Warning : This website is not updated anymore. Its content surely is outdated.

erc2html

erc2html est un petit script Ruby qui transforme le contenu d'un log session d'ERC (Emacs Relay Chat) en HTML.

C'est du vite fait pas forcément bien fait. Vous êtes donc prévenus.

require "cgi"

str = IO.read("erc_chat_file.log.txt")

titre = "Titre de la page"
charset = "UTF-8"

head = <<EOL
<html>
<head>
<title>#{titre}</title>
<meta http-equiv="Content-Type" content="text/html; charset=#{charset}" />
<style type="text/css">
 * {font-family: monospace;}
 .nick {font-weight: bold; color: #A00;}
 .ref {font-style: italic; color: #090;}
 .timestamp {color: #AAA;}
 .me {color: #00B;}
</style>
</head>
<body>
<h1>#{titre}</h1>
<p>
EOL

foot = <<EOL
</p>
</body>
</html>
EOL

str.gsub!(/^ERC>.*$/n, "")
str.gsub!(/\n\s+/n, " ")
str.gsub!(/\[\d\d:\d\d\]/) { |s| "\n"+s+"\n"}
str.gsub!(/\s+$/n, "")
str.gsub!(/^\*\*\* .*$/n, "")
5.times {str.gsub!(/\n\s*\n/n, "\n")}

str = CGI::escapeHTML(str)
str.gsub!(/^&lt;.*?&gt;/n) {|s| '<span class="nick">'+s+'</span>'}
str.gsub!(/(<\/span>) (\w+\s?:)/n) {|s| $1+' <span class="ref">'+$2+'</span>'}
str.gsub!(/\[\d\d:\d\d\]/) { |s| '<span class="timestamp">'+s+'</span>'}
str.gsub!(/^\* .*$/n) {|s| '<span class="me">'+s+'</span>'}
str.gsub!(/\n/, "<br />\n")

str = head + str
str = str + foot

puts str