Code: Select all
proc mirc2html str {
set re {([\002\017\026\037]|[\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})}
array set colors { 0 white 1 black 2 navy 3 green
4 red 5 maroon 6 purple 7 olive
8 yellow 9 lime 10 teal 11 aqua
12 blue 13 fuchsia 14 gray 15 silver}
set numtags 0
while {[regexp -indices $re $str -> idxs]} {
set b [lindex $idxs 0]
set e [lindex $idxs 1]
set sub [string range $str $b $e]
switch [string index $sub 0] {
"\002" {
set tag "<span style=\"font-weight:bold\">"
incr numtags
}
"\017" {
set tag [string repeat "</span>" $numtags]
set numtags 0
}
"\026" {
set tag [string repeat "</span>" $numtags]
append tag "<span style=\"color:white;background-color:black\">"
set numtags 1
}
"\037" {
set tag "<span style=\"text-decoration:underline\">"
incr numtags
}
"\003" {
set fg [lindex [split [string range $sub 1 e] ,] 0]
set bg [lindex [split [string range $sub 1 e] ,] 1]
if {$fg != "" || $bg != ""} {
if {$fg > 15 || $bg > 15} {
set tag "<span>"
} elseif {$fg != "" && $bg != ""} {
set tag "<span style=\"color:$colors($fg);background-color:$colors($bg)\">"
} elseif {$fg != "" && $bg == ""} {
set tag "<span style=\"color:$colors($fg)\">"
} else {
set tag "<span style=\"background-color:$colors($bg)\">"
}
incr numtags
} {
set tag [string repeat "</span>" $numtags]
set numtags 0
}
}
}
set str [string replace $str $b $e $tag]
}
append str [string repeat "</span>" $numtags]
return $str
}
Code: Select all
proc mirc2html str {
set re {([\002\017\026\037]|[\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})}
array set colors { 0 white 1 black 2 navy 3 green
4 red 5 maroon 6 purple 7 olive
8 yellow 9 lime 10 teal 11 aqua
12 blue 13 fuchsia 14 gray 15 silver}
set numtags 0; set bold 0
while {[regexp -indices $re $str -> idxs]} {
set b [lindex $idxs 0]
set e [lindex $idxs 1]
set sub [string range $str $b $e]
switch [string index $sub 0] {
"\002" {
if !$bold {
set tag "<span style=\"font-weight:bold\">"
set bold 1
} {
set tag "<span style=\"font-weight:normal\">"
set bold 0
}
incr numtags
}
"\017" {
set tag [string repeat "</span>" $numtags]
set numtags 0
}
"\026" {
set tag [string repeat "</span>" $numtags]
append tag "<span style=\"color:white;background-color:black\">"
set numtags 1
}
"\037" {
set tag "<span style=\"text-decoration:underline\">"
incr numtags
}
"\003" {
set fg [lindex [split [string range $sub 1 e] ,] 0]
set bg [lindex [split [string range $sub 1 e] ,] 1]
if {$fg != "" || $bg != ""} {
if {$fg > 15 || $bg > 15} {
set tag "<span>"
} elseif {$fg != "" && $bg != ""} {
set tag "<span style=\"color:$colors($fg);background-color:$colors($bg)\">"
} elseif {$fg != "" && $bg == ""} {
set tag "<span style=\"color:$colors($fg)\">"
} else {
set tag "<span style=\"background-color:$colors($bg)\">"
}
incr numtags
} {
set tag [string repeat "</span>" $numtags]
set numtags 0
}
}
}
set str [string replace $str $b $e $tag]
}
append str [string repeat "</span>" $numtags]
return $str
}