mIRC Home    About    Download    Register    News    Help

Print Thread
#26023 26/05/03 02:51 AM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
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>

#26024 26/05/03 02:56 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Yes, get this addon here and read the readme file before using.

#26025 26/05/03 05:12 AM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
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)

#26026 26/05/03 09:18 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
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.

#26027 26/05/03 09:19 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
If you get a chance, that would be great!

#26028 26/05/03 11:15 PM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Ok, I think this one will do the job:
Code:
alias tohtml {
  ;
  ; $tohtml(text)
  ;
  var %t = $1-, %i = 1, %s = $len($1-), %w, %p, $&amp;
    %bold, %rev, %under, %col, %bg, $&amp;
    %inv = $+(&lt;span style=color:,$_tohex($color(b)), $&amp;
    ;background-color:,$_tohex($color(te)),&gt;)
  while %i &lt;= %s {
    var %w = $mid(%t,%i,1)
    if %w ==  {
      if !%bold { var %p = %p $+ &lt;b&gt;, %bold = 1 }
      else { var %p = %p $+ &lt;/b&gt;, %bold = 0 }
    }
    elseif %w ==  {
      if !%under { var %p = %p $+ &lt;u&gt;, %under = 1 }
      else { var %p = %p $+ &lt;/u&gt;, %under = 0 }
    }
    elseif %w ==  {
      if !%rev { var %p = %p $+ %inv, %rev = 1 }
      else { var %p = %p $+ &lt;/span&gt;, %rev = 0 }
    }
    elseif %w ==  {
      if %col { var %p = %p $+ &lt;/span&gt;, %col = 0 }
      if $regex($mid(%t,%i),^(\d\d?(?:\x2C\d\d?)?)) {
        tokenize 44 $regml(1)
        if $2 { var %bg = $2 }
        var %p = $+(%p,&lt;span style=color:,$_tohex($1), $&amp;
          $iif(%bg,;background-color: $+ $_tohex(%bg)), $&amp;
          &gt;), %col = 1, %i = %i + $len($1-)
      }
    }
    elseif %w ==  {
      var %p = %p $+ $iif(%bold,&lt;/b&gt;) $+ $iif(%under,&lt;/u&gt;) $+ $&amp;
        $iif(%rev,&lt;/span&gt;) $+ $iif(%col,&lt;/span&gt;), $&amp;
        %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.

#26029 27/05/03 12:36 AM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
It is giving
* String too long: $+ (line 30, script.mrc)
Can i only do some much text at once?

#26030 27/05/03 01:41 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
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.
Code:
alias tohtmlfile {
  ; /tohtml2 &lt;text&gt;
  var %t = $1-, %i = 1, %s = $len($1-), %w, $&amp;
    %bold, %rev, %under, %col, %bg, $&amp;
    %inv = $+(&lt;span style=color:,$_tohex($color(b)), $&amp;
    ;background-color:,$_tohex($color(te)),&gt;)
  write -c temp.html
  while %i &lt;= %s {
    var %w = $mid(%t,%i,1)
    if %w ==  {
      if !%bold { bset -t &amp;p $calc($bvar(&amp;p,0) +1) &lt;b&gt; | %bold = 1 }
      else { bset -t &amp;p $calc($bvar(&amp;p,0) +1) %p $+ &lt;/b&gt; | %bold = 0 }
    }
    elseif %w ==  {
      if !%under { bset -t &amp;p $calc($bvar(&amp;p,0) +1) &lt;u&gt; | %under = 1 }
      else { bset -t &amp;p $calc($bvar(&amp;p,0) +1) &lt;/u&gt; | %under = 0 }
    }
    elseif %w ==  {
      if !%rev { bset -t &amp;p $calc($bvar(&amp;p,0) +1) %inv | %rev = 1 }
      else { bset -t &amp;p $calc($bvar(&amp;p,0) +1) &lt;/span&gt; | %rev = 0 }
    }
    elseif %w ==  {
      if %col { bset -t &amp;p $calc($bvar(&amp;p,0) +1) &lt;/span&gt;, %col = 0 }
      if $regex($mid(%t,%i),^(\d\d?(?:\x2C\d\d?)?)) {
        tokenize 44 $regml(1)
        if $2 { var %bg = $2 }
        bset -t &amp;p $calc($bvar(&amp;p,0) +1) $+(&lt;span style=color:,$_tohex($1), $&amp;
          $iif(%bg,;background-color: $+ $_tohex(%bg)), $&amp;
          &gt;)
        var %col = 1, %i = %i + $len($1-)
      }
    }
    elseif %w ==  {
      bset -t &amp;p $calc($bvar(&amp;p,0) +1) $iif(%bold,&lt;/b&gt;) $+ $iif(%under,&lt;/u&gt;) $+ $&amp;
        $iif(%rev,&lt;/span&gt;) $+ $iif(%col,&lt;/span&gt;)
      var %bold = 0, %under = 0, %rev = 0, %col = 0
    }
    else bset -t &amp;p $calc($bvar(&amp;p,0) +1) %w
    inc %i
  }
  bwrite temp.html 0 &amp;p
  run temp.html
}

Use: /tohtmlfile <text>

(remember to keep the $_tohex alias though). I hope it helped.

#26031 27/05/03 11:34 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
Joined: Dec 2002
Posts: 83
Thanks online for all your help so far!

I'm getting along, but this line is giving me errors:
Code:
      bset -t &amp;p $calc($bvar(&amp;p,0) +1) %w 


Any ideas?

#26032 27/05/03 11:38 PM
Joined: Dec 2002
Posts: 83
A
Babel fish
OP Offline
Babel fish
A
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)

#26033 28/05/03 03:24 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
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 -
Code:
else bset &amp;p $calc($bvar(&amp;p,0) +1) $asc(%w)


Link Copied to Clipboard