|
Joined: Dec 2002
Posts: 83
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 83 |
Does anyone know of a script to convert colour codes to html format from a line of text?
mIRC: /convert page.html (white text) Hello, welcome! HTML: <font color="#FFFFFF">Hello, welcome!</font>
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
Yes, get this addon here and read the readme file before using.
|
|
|
|
Joined: Dec 2002
Posts: 83
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 83 |
It uses CSS and does multi-lined html... i need it in a single line (it's going to be used in java script)
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
You're right. However, I couldn't find another script that accomplishes irc to html conversion. I'll try to make one myself later.
|
|
|
|
Joined: Dec 2002
Posts: 83
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 83 |
If you get a chance, that would be great!
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
Ok, I think this one will do the job: alias tohtml {
;
; $tohtml(text)
;
var %t = $1-, %i = 1, %s = $len($1-), %w, %p, $&
%bold, %rev, %under, %col, %bg, $&
%inv = $+(<span style=color:,$_tohex($color(b)), $&
;background-color:,$_tohex($color(te)),>)
while %i <= %s {
var %w = $mid(%t,%i,1)
if %w == {
if !%bold { var %p = %p $+ <b>, %bold = 1 }
else { var %p = %p $+ </b>, %bold = 0 }
}
elseif %w == {
if !%under { var %p = %p $+ <u>, %under = 1 }
else { var %p = %p $+ </u>, %under = 0 }
}
elseif %w == {
if !%rev { var %p = %p $+ %inv, %rev = 1 }
else { var %p = %p $+ </span>, %rev = 0 }
}
elseif %w == {
if %col { var %p = %p $+ </span>, %col = 0 }
if $regex($mid(%t,%i),^(\d\d?(?:\x2C\d\d?)?)) {
tokenize 44 $regml(1)
if $2 { var %bg = $2 }
var %p = $+(%p,<span style=color:,$_tohex($1), $&
$iif(%bg,;background-color: $+ $_tohex(%bg)), $&
>), %col = 1, %i = %i + $len($1-)
}
}
elseif %w == {
var %p = %p $+ $iif(%bold,</b>) $+ $iif(%under,</u>) $+ $&
$iif(%rev,</span>) $+ $iif(%col,</span>), $&
%bold = 0, %under = 0, %rev = 0, %col = 0
}
else var %p = $+(%p,%w,$iif(%w = $chr(32),$lf))
inc %i
}
return $remove(%p,$lf)
}
alias -l _tohex {
;
; $_tohex(1-16)
;
tokenize 44 $rgb($color($1))
return $+($chr(35),$base($1,10,16,2),$base($2,10,16,2),$base($3,10,16,2))
} //echo -a $tohtml(bold and underline) It should parse the codes exactly as mirc does. If you find a bug, please tell me, and we'll try to fix it.
|
|
|
|
Joined: Dec 2002
Posts: 83
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 83 |
It is giving * String too long: $+ (line 30, script.mrc) Can i only do some much text at once?
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
Yes, that's a problem. The html output can easily exceed the allowed string length (~950 chars), considering each control code generaters a far greater html tag. Anyhow, here's a modified version (/tohtmlfile), which uses a binary variable (limited to 8192 chars) to store the output, then writes it directly into a temporary html file. This version will allow your input to be much longer. alias tohtmlfile {
; /tohtml2 <text>
var %t = $1-, %i = 1, %s = $len($1-), %w, $&
%bold, %rev, %under, %col, %bg, $&
%inv = $+(<span style=color:,$_tohex($color(b)), $&
;background-color:,$_tohex($color(te)),>)
write -c temp.html
while %i <= %s {
var %w = $mid(%t,%i,1)
if %w == {
if !%bold { bset -t &p $calc($bvar(&p,0) +1) <b> | %bold = 1 }
else { bset -t &p $calc($bvar(&p,0) +1) %p $+ </b> | %bold = 0 }
}
elseif %w == {
if !%under { bset -t &p $calc($bvar(&p,0) +1) <u> | %under = 1 }
else { bset -t &p $calc($bvar(&p,0) +1) </u> | %under = 0 }
}
elseif %w == {
if !%rev { bset -t &p $calc($bvar(&p,0) +1) %inv | %rev = 1 }
else { bset -t &p $calc($bvar(&p,0) +1) </span> | %rev = 0 }
}
elseif %w == {
if %col { bset -t &p $calc($bvar(&p,0) +1) </span>, %col = 0 }
if $regex($mid(%t,%i),^(\d\d?(?:\x2C\d\d?)?)) {
tokenize 44 $regml(1)
if $2 { var %bg = $2 }
bset -t &p $calc($bvar(&p,0) +1) $+(<span style=color:,$_tohex($1), $&
$iif(%bg,;background-color: $+ $_tohex(%bg)), $&
>)
var %col = 1, %i = %i + $len($1-)
}
}
elseif %w == {
bset -t &p $calc($bvar(&p,0) +1) $iif(%bold,</b>) $+ $iif(%under,</u>) $+ $&
$iif(%rev,</span>) $+ $iif(%col,</span>)
var %bold = 0, %under = 0, %rev = 0, %col = 0
}
else bset -t &p $calc($bvar(&p,0) +1) %w
inc %i
}
bwrite temp.html 0 &p
run temp.html
} Use: /tohtmlfile <text> (remember to keep the $_tohex alias though). I hope it helped.
|
|
|
|
Joined: Dec 2002
Posts: 83
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 83 |
Thanks online for all your help so far! I'm getting along, but this line is giving me errors:
bset -t &p $calc($bvar(&p,0) +1) %w
Any ideas?
|
|
|
|
Joined: Dec 2002
Posts: 83
Babel fish
|
OP
Babel fish
Joined: Dec 2002
Posts: 83 |
If I add any character to the end of that line, it goes through with it, but produces the HTML file wrong. (obviously.. that character messes it all up)
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
oops, sorry for the late reply. The forum didn't show me there are new messages in this thread. Yes that command gives an error when %w contains a space. I think it could be solved by replacing that line with - else bset &p $calc($bvar(&p,0) +1) $asc(%w)
|
|
|
|
|