W3C home > Mailing lists > Public > www-validator@w3.org > July 2008

Re: <pre><img src="test.gif" alt="test" /></pre>

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Wed, 9 Jul 2008 20:34:55 +0300
Message-ID: <018501c8e1ea$1bd5ea60$0400000a@DOCENDO>
To: <www-validator@w3.org>

Frank Ellermann wrote:
> Fredrik Medin wrote:
>
>> You get an error when you do it like this:
>> <pre><img src="test.gif" alt="test" /></pre>
>
>> And still it shows perfectly in both IE and FF.
>
> Yeah, that is just as it is, the syntax does not
> allow images within <pre>. Even where that could
> work, depending on the browser and the image.

It could only for some odd values of "work", since a <pre> element is 
supposed to contain preformatted text data to be rendered "as is". Since 
an image has no defined relationship with preformatted text, the results 
would be unpredicable, working against the very idea of preformatted 
text.

> Things you can do:
> (1) Ignore the error if you are sure that you are
>     not interested to find another solution.

Well, I'd say "a solution" rather than "another solution", and then the 
question arises why one would use a validator and ignore its error 
messages.

> (2) Cheat, put the image into a <span> within the
>     <pre>.  That's actually a variant of (1), and
>     it only works because *this* validator at the
>     moment isn't smart enough to detect that trick.

It's not really the validator's fault but depends on the data format. 
Contrary to popular babbling and widespread propaganda, XHTML is in many 
ways _more_ permissive than classic HTML. Here the reason is that XML 
DTDs lack exclusion exceptions, so their definition of <pre> content is 
more primitive and more permissive. Using good old HTML, the error (of 
having <img> inside <span> inside <pre>) would be detected in validator.

> Lots of options,

The best option is to learn HTML well enough in order to find better, 
more structured and more logical markup. In this case, it means using 
<p> for a paragraph, <h2> for a 2nd level heading, and an image can then 
be wrapped inside a <div> if you want to be Strict. The problem then 
vanishes in a puff of logic, and to limit text width, CSS can be used if 
desired (e.g., p { max-width: 25em; }).

Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/ 
Received on Wednesday, 9 July 2008 17:34:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:30 GMT