Hi Monks, ^^

I've been making a code That works like the <code> #.. </code> on this site with a few visual additions like a Perl editer reads.

CSS code
.codepost { background-color: #ffffff; width: 500px; height: auto; white-space: nowrap; overflow: scroll; padding-left: 2px; padding-bottom: 5px; }
My HTML Escape code
sub html_escape { my $text = shift; return '' unless $text; #$text =~ s{\;}{#59;}gso; $text =~ s{&}{&amp;}gso; #$text =~ s{#59;}{&#59;}gso; $text =~ s{"}{&quot;}gso; $text =~ s{ }{ \&nbsp;}gso; $text =~ s{\*}{&#42;}gso; $text =~ s{<}{&lt;}gso; $text =~ s{>}{&gt;}gso; $text =~ s{'}{&#39;}gso; $text =~ s{\)}{&#41;}gso; $text =~ s{\(}{&#40;}gso; $text =~ s{\\}{&#92;}gso; # need this! $text =~ s{\t}{ \&nbsp; \&nbsp; \&nbsp;}gso; $text =~ s{\|}{\&#124;}gso; # going to keep this $text =~ s{\n}{<br>}gso; $text =~ s{\cM}{}gso; return $text; }
The main code
$message =~ s~<br>~=br=~isg; while ($message =~ s{\[code\]([\S\s].+?[\S\s])\[/code\]} { my $tmp = $1; $tmp =~ s!<!&#60;!g; $tmp =~ s!>!&#62;!g; # &#39; $tmp =~ s!:!&#58;!g; $tmp =~ s!\[!&#91;!g; $tmp =~ s!\\!&#92;!g; $tmp =~ s!\]!&#93;!g; $tmp =~ s!\)!&#41;!g; $tmp =~ s!\(!&#40;!g; $tmp =~ s!\|!&#124;!g; $tmp =~ s!([^\&])(\#.*?(=br=))!$1<font color=" +blue"><i>$2</i></font>!g; $tmp =~ s!(&#39;.*?(&#39;|=br=))!<font color=r +ed>$1</font>!g; $tmp =~ s!(&quot;.*?(&quot;|=br=))!<font color +=red>$1</font>!g; $tmp =~ s!(return)!<b>$1</b>!g; $tmp =~ s!(require)!<b>$1</b>!g; $tmp =~ s!(while)!<b>$1</b>!g; $tmp =~ s!(foreach)!<b>$1</b>!g; $tmp =~ s!(for)!<b>$1</b>!g; $tmp =~ s!(my)!<b>$1</b>!g; $tmp =~ s!(sub)!<b>$1</b>!g; $tmp =~ s!([^\w])(if)([^\w]*)!$1<b>$2</b>$3!g; $tmp =~ s!(unless)!<b>$1</b>!g; $tmp =~ s!(elsif)!<b>$1</b>!g; $tmp =~ s!(else)!<b>$1</b>!g; $tmp =~ s!(use)!<b>$1</b>!g; $tmp =~ s!(package)!<b>$1</b>!g; $tmp =~ s!&lt;!&#60;!g; $tmp =~ s!&gt;!&#62;!g; $tmp =~ s!&quot;!&#34;!g; $tmp =~ s!"!&#34;!g; #" $tmp =~ s!\s{1};!&#59;!g; #$tmp =~ s!&gt;br&gt;!\n!g; $tmp = "<br><div class=\"codepost\"><font colo +r=\"blue\"><i># $msg{code}</i></font> <br>" . $tmp . '<br><font color="blue"><i># Code En +d</i></font></div>'; }exisog) {} $message =~ s~=br=~<br>~isg;

with the above code it should display a code like this
sub html_escape
{
       my $text = shift;

       return '' unless $text;
       #$text =~ s{\;}{#59;}gso;
       $text =~ s{&}{&amp;}gso;
       #$text =~ s{#59;}{&#59;}gso;
       $text =~ s{"}{&quot;}gso;
       $text =~ s{  }{ \&nbsp;}gso;
       $text =~ s{\*}{&#42;}gso;
       $text =~ s{<}{&lt;}gso;
       $text =~ s{>}{&gt;}gso;
       $text =~ s{'}{&#39;}gso; # bug 1 (want it to be red for the hole line)
       $text =~ s{\)}{&#41;}gso;
       $text =~ s{\(}{&#40;}gso;
       $text =~ s{\\}{&#92;}gso; # need this!
       $text =~ s{\t}{ \&nbsp; \&nbsp; \&nbsp;}gso;
       $text =~ s{\|}{\&#124;}gso; # going to keep this
       $text =~ s{\n}{<br>}gso;
       $text =~ s{\cM}{}gso;

       return $text;
}

And for the other bug.

package filters;
# ---------------------
#  Untaint # bug2 should be blue
# ---------------------
sub untaint {
my $value   = shift || '';
my $pattern = shift || '\w\-\.\/';
return '' unless $value;
$value =~ m!^([$pattern]+)$!i
? return $1
: return;
}

For the first bug i guess i can deal with it becase i didnt want to do a fancy code to fix it
For the 2nt bug, well its not working the way i wanted it to.

Help!!!

In reply to Regex - it works, but not the way i want it to =( by SFLEX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.