Accueil





Convertir des codes de style mIRC en HTML



Pratique pour mettre des citations ou des logs IRC sur une page HTML en préservant les couleurs et autres styles.

Les codes de style malformés / mal équilibrés / imbriqués sont supportés.

Vous aurez besoin de la procédure html_entities_encode.


Procédure
proc mIRC2HTML {data} { regsub -all {\022} [html_entities_encode $data] "" data set taglist [regexp -all -inline {\002|\003(?:[0-9]{0,2}(?:,[0-9]{0,2})?)?|\037|\026|\017} $data] # Etat des tags "au repos"; les -1 signifient que la couleur est celle par # défaut. set textbold 0 ; set textuline 0 ; set textitalic 0 ; set textfgcol "-1" ; set textbgcol "-1" ; set first_one 1 set outtag "" foreach tag $taglist { if { !$first_one } { append outtag "|</span>" } switch -- $tag { "\002" { if { !$textbold } { set textbold 1 } { set textbold 0 } } "\037" { if { !$textuline } { set textuline 1 } { set textuline 0 } } "\026" { if { !$textitalic } { set textitalic 1 } { set textitalic 0 } } "\017" { set textbold 0 ; set textuline 0 ; set textitalic 0 ; set textfgcol "-1" ; set textbgcol "-1" } default { # \003xx lassign [split [regsub {\003([0-9]{0,2}(,[0-9]{0,2})?)?} $tag {\1}] ","] textfgcol temp_textbgcol # \003 if { $textfgcol eq "" } { set textfgcol -1 ; set textbgcol -1 # \003xx,yy } elseif { $temp_textbgcol ne "" } { set textbgcol $temp_textbgcol } } } set first_one 0 set temp_outtag "" foreach tagname {textbold textuline textitalic textfgcol textbgcol} { if { [set $tagname] > 0 } { append temp_outtag " $tagname" } if { (($tagname eq "textfgcol") || ($tagname eq "textbgcol")) && ([set $tagname] > -1) } then { append temp_outtag [set $tagname] } } if { [set temp_outtag [::tcl::string::range [set temp_outtag] 1 end]] ne "" } { append outtag "<span class=\"[set temp_outtag]\">" } } # Injection des balises HTML dans le texte. set counter 0 foreach tag $taglist { regsub $tag $data [lindex [split $outtag "|"] $counter] data incr counter } if { ($textbold) || ($textuline) || ($textitalic) || ($textfgcol > -1) || ($textbgcol > -1) } { append data "</span>" } return $data }


Vous devrez inclure ceci dans la feuille de style (.css) qui accompagnera votre page web
.textbold { font-weight:bold; } .textuline { text-decoration:underline; } .textitalic { font-style:italic; } .textfgcol00, .textfgcol0 { color:#FFFFFF; } .textbgcol00, .textbgcol0 { background-color:#FFFFFF; } .textfgcol01, .textfgcol1 { color:#000000; } .textbgcol01, .textbgcol1 { background-color:#000000; } .textfgcol02, .textfgcol2 { color:#000090; } .textbgcol02, .textbgcol2 { background-color:#000090; } .textfgcol03, .textfgcol3 { color:#00B000; } .textbgcol03, .textbgcol3 { background-color:#00B000; } .textfgcol04, .textfgcol4 { color:#FF0000; } .textbgcol04, .textbgcol4 { background-color:#FF0000; } .textfgcol05, .textfgcol5 { color:#800000; } .textbgcol05, .textbgcol5 { background-color:#800000; } .textfgcol06, .textfgcol6 { color:#800080; } .textbgcol06, .textbgcol6 { background-color:#800080; } .textfgcol07, .textfgcol7 { color:#FF8000; } .textbgcol07, .textbgcol7 { background-color:#FF8000; } .textfgcol08, .textfgcol8 { color:#FFFF00; } .textbgcol08, .textbgcol8 { background-color:#FFFF00; } .textfgcol09, .textfgcol9 { color:#00FF00; } .textbgcol09, .textbgcol9 { background-color:#00FF00; } .textfgcol10 { color:#008080; } .textbgcol10 { background-color:#008080; } .textfgcol11 { color:#00FFFF; } .textbgcol11 { background-color:#00FFFF; } .textfgcol12 { color:#0060FF; } .textbgcol12 { background-color:#0060FF; } .textfgcol13 { color:#FF00FF; } .textbgcol13 { background-color:#FF00FF; } .textfgcol14 { color:#696969; } .textbgcol14 { background-color:#696969; } .textfgcol15 { color:#A3A3A3; } .textbgcol15 { background-color:#A3A3A3; }


Exemple
mIRC2HTML "ceci est un test hop" Tcl: ceci <span class="textfgcol4">est </span><span class="textfgcol12"></span><span class="textbold textfgcol12 textbgcol08">un </span><span class="textbold">test</span> </span><span class="textuline">hop</span></span>
©2005-2016 Menz Agitat