Javascript and Tidy

First of all, I usually use Tidy through the Firefox "HTML 
Validation" extension. I have the latest version of the extension, 
but whether that is the latest version of Tidy, I don't know. I use 
Tidy to report errors, but not to fix them.

I make use of a lot of simple Javascript to generate HTML code. In 
most cases, this does not cause any problems (Tidy, of course, cannot 
check the generated HTML code, but that is fine). However, there are 
a number of situations where Tidy reports errors that I do not understand.

A typical one would be the following fragment (I am replacing angle 
brackets with square brackets in the HTML code, to avoid any possible 
unintended interpretations. Also, this is hand-typed on the fly - 
please ignore any minor typos.)

[ul]
[script type="text/javascript"]showUntil(date, html-code);[/script]
....
[/ul]

This "showUntil" function checks the date parameter against the 
current date, and adds the HTML code parameter to the document iff appropriate.

Tidy objects to a missing "li" tag. Of course, that is in the 
generated code that Tidy cannot "see."

I understand that Tidy cannot interpret the Javascript and verify 
that it generates the required "li" tag. However, the implication of 
the message is that only an "li" tag is permitted in this position - 
I would think that a "script" tag should be valid, even if Tidy 
cannot interpret the results of executing the script.

Similar things occur, for example, in tables, if I have a Javascript 
function to generate an entire row of a table, including the "tr" and 
"/tr" tags.

I can avoid the errors by generating more of the code in Javascript - 
for example, adding a function to generate the "ul" and "/ul" tags in 
the example above. But this seems silly.

My question is, is a "script" tag really invalid here, or is Tidy 
just making the worst-case assumption, that the script may not 
generate valid HTML code? I would think that scripting was designed 
for exactly these kinds of applications, and I can't imaging why it 
would be disallowed. All of the browsers I have tested "do the right 
thing" (i.e. what I expect :-), but I would like to know if what I am 
doing is really an error.




Peter Curran 

Received on Friday, 26 May 2006 04:32:48 UTC