Invalid location of <script> tag within a HTML <pre> tag

I am going through the example given in JavaScript The Complete Reference 3rd Edition.

The O/P can be seen here, given by the author.

            <body> 
            <h1>Standard Whitespace Handling</h1> 

            <script>
            // STRINGS AND (X)HTML
            document.write("Welcome to JavaScript strings.\n");
            document.write("This example illustrates nested quotes 'like this.'\n");        
            document.write("Note how newlines (\\n's) and ");
            document.write("escape sequences are used.\n");
            document.write("You might wonder, \"Will this nested quoting work?\"");
            document.write(" It will.\n");
            document.write("Here's an example of some formatted data:\n\n");
            document.write("\tCode\tValue\n");
            document.write("\t\\n\tnewline\n");
            document.write("\t\\\\\tbackslash\n");
            document.write("\t\\\"\tdouble quote\n\n");
            </script>   

            <h1>Preserved Whitespace</h1> 
            <pre>
            <script>           // in Eclipse IDE, at this line invalid location of tag(script)                                             
            // STRINGS AND (X)HTML
            document.write("Welcome to JavaScript strings.\n");
            document.write("This example illustrates nested quotes 'like this.'\n");        
            document.write("Note how newlines (\\n's) and ");
            document.write("escape sequences are used.\n");
            document.write("You might wonder, \"Will this nested quoting work?\"");
            document.write(" It will.\n");
            document.write("Here's an example of some formatted data:\n\n");
            document.write("\tCode\tValue\n");
            document.write("\t\\n\tnewline\n");
            document.write("\t\\\\\tbackslash\n");
            document.write("\t\\\"\tdouble quote\n\n");
            </script>   
            </pre>
            </body>

(X)HTML automatically “collapses” multiple whitespace characters down to one whitespace. So, for example, including multiple consecutive tabs in your HTML shows up as only one space character. In this example, the pre tag is used to tell the browser that the text is preformatted and that it should not collapse the white space inside of it. Similarly, we could use the CSS white-space property to modify standard white space handling. Using pre allows the tabs in the example to be displayed correctly in the output.

So, how to get rid of this warning and do i really need to have a concern for this? I think i am missing something as i have the intuition of the authors not being wrong?

Upvotes: 0

Views: 4948

Answers (1)

jonasnas
jonasnas

Reputation: 3580

There is nothing wrong in having script inside pre tag. It is just Eclipse IDE validation issue. If you use this html in the browser everything works fine and no warnings are displayed.

Also, if you wanted to show script tag as 'text content' inside pre tag, then have a look at this question: script in pre

Upvotes: 4

Related Questions