erc2html
Par Juba le samedi 7 janvier 2006, 23:50 - Emacs, Gnus - Lien permanent
Je viens de pondre un tout petit script en Ruby qui me permet de transformer un log de discussion IRC enregistré sous ERC (Emacs Relay Chat) en fichier HTML pour publication. Le script supprime les sauts de ligne superflus, supprime les messages serveur et colorise deux trois bricoles. C'est loin d'être parfait, mais si ça peut être utile à quelqu'un...
require "cgi"
str = IO.read("/home/julien/lautre_20060107.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!(/
\s+/n, " ")
str.gsub!(/[\d\d:\d\d]/) { |s| "
"+s+"
"}
str.gsub!(/\s+$/n, "")
str.gsub!(/^\*\*\* .*$/n, "")
5.times {str.gsub!(/
\s*
/n, "
")}
str = CGI::escapeHTML(str)
str.gsub!(/^<.*?>/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!(/
/, "<br />
")
str = head + str
str = str + foot
puts str