On Tue, 22 Aug 2006, Havard Eidnes wrote:
> while fixing up a document which used <font> to change colour inside a
> <pre>, the validator gave this error message:
>
> document type does not allow element "FONT" here.
I'm afraid there's not much that can be done to improve the error message,
since it is generated in a situation where the validator does not really
"know" what the context is. That is, it has no simple access to
information that would tell _why_ (say) element "FONT" is disallowed here;
it only works with a definition (content model) that says what may appear.
That's how I've understood the explanations given previously on this list.
I don't know the internals of the validator, but having written some
parsers, I understand that you easily end up with a situation like this.
The validator would probably need a major rewrite in order to have access
to the context information.
> I have since been told by our resident HTML expert that the context was
> probably <pre>,
Technically, the context is normally the enclosing element, i.e. the
element inside which the offending element appears with no intervening
markup. Thus the context is most probably <pre>. (It is possible, but not
common, to have several nesting levels in markup inside <pre>.)
Things would be easier if the validator named the context, i.e. the
enclosing element (e.g., document type does not allow element "FONT"
as a sub-element of "PRE"), instead of using the vague word "context". But
for reasons mentioned above, this probably won't happen. Besides, in HTML
(as opposite to XHTML), there are some tricky issues with "exclusion
exceptions" that would complicate things.
> and that it is much preferable to use CSS than to use
> <font> to change colour.
Well, that's a completely different issue, though worth noting of course,
and actually more important than the validation issue.
The _reason_ for disallowing "FONT" inside "PRE" was that "FONT" _may_
change the font size (via the SIZE attribue), thereby working against the
very idea of "PRE". There was however no way to say, in a DTD, that "FONT"
is OK as long as it does not contain the "SIZE" attribute.
--
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/