Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I've taken the liberty of making an example:

<html> <head> <title>test</title> <style> code { white-space: pre; } .functionName { color: red; } .reservedWord { color: green; } .stringValue { color: blue; } .comment { color: grey; } </style> <script> function HighlightSyntax(object) { var codeContent = object.innerHTML; //stringValue codeContent = codeContent.replace(/(\"|\')(.*?)\1/g, "$1<span clas +s=\"stringValue\">$2</span>$1"); //functionName codeContent = codeContent.replace(/(sub\s+)([a-zA-Z]\w+)/g, "$1<sp +an class=\"functionName\">$2</span>"); //reserverdWord codeContent = codeContent.replace(/(\s+)(close|else|if|for|foreach +|my|open|print|printf|return|sprintf|sub|unless|use|while)(\s+)/g, "$ +1<span class=\"reservedWord\">$2</span>$3"); //comment codeContent = codeContent.replace(/(\#.*?\r|\n)/g, "<span class=\" +comment\">$1</span>"); object.innerHTML = codeContent; } </script> </head> <body> <code onClick="HighlightSyntax(this);"> #!/usr/bin/perl -w sub JavascriptEncodeText($) { my $string = shift; unless (defined ($string)) { $string = ''; } $string =~ s/([\x{80}-\x{ffff}])/sprintf('&#x%04X;', ord($1))/ge; return "$string"; } #apples print "test\n"; <\/code> </body> </html>
To try it, remove the backslash in the last <\/code> thing. This could easily be expandedn (i'll work some more on it and post it too.)

In reply to Re: Re: Re: Feature Request: Adding Colors to Source Code by Jaap
in thread Feature Request: Adding Colors to Source Code by Vautrin

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2020-06-02 12:27 GMT
    Find Nodes?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?

      Results (17 votes). Check out past polls.