zzyengineer / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

CDATA doesn't get treated as javascript #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When using a CDATA section in a script tag, none of the javascript is
prettified.

The javascript in a CDATA section should be prettified.

Original issue reported on code.google.com by dhtmlkit...@gmail.com on 22 May 2007 at 3:54

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by mikesamuel@gmail.com on 15 Aug 2007 at 6:22

GoogleCodeExporter commented 9 years ago

Original comment by mikesamuel@gmail.com on 15 Aug 2007 at 8:43

GoogleCodeExporter commented 9 years ago
Thanks for the testcase.

The lexer treats the chunk as markup if the first non-whitespace character is 
'<'. 
Since "<![CDATA[" starts with '<' it's getting confused.

I will change the splitSourceNodes pass to force non markup lexing.

Original comment by mikesamuel@gmail.com on 30 Aug 2007 at 9:29

GoogleCodeExporter commented 9 years ago
Actually, I'll just do it in the chunkifier.

Original comment by mikesamuel@gmail.com on 30 Aug 2007 at 9:32

GoogleCodeExporter commented 9 years ago
I tested, and
  <pre class="prettyprint">
  <script><![CDATA[
    mySourceDoe();
  ]]></script>
works properly.

In the testPrettify.html example though:

    <pre class="prettyprint"><![CDATA[
    /**
     * @method isPrettyGood
     * This is a test.
     * @param foo {String} is it a "bar" string?
     * function returns a new this. document is open for each class.
     */
    isPrettyGood = function isPrettyGood(/* string*/foo ) {
        var x = new String( "poop" );
        // first char is "p".
        var p = x.charAt( 0 );
        var p = new Poop( p );
        var t = new this( s );
    };
    ]]>

    <!-- foo html comment function -->
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    </pre>

What do you expect to happen?
It looks like the content is markup, and should be parsed as such.  The CDATA 
section
is a text node, not something that a browser would treat as javascript, so what
indicator is there that it should be treated as javascript?

Original comment by mikesamuel@gmail.com on 30 Aug 2007 at 9:46

GoogleCodeExporter commented 9 years ago
Closed for lack of activity.

Original comment by mikesamuel@gmail.com on 23 Oct 2007 at 1:20