[whatwg] <code> attributes

ddailey ddailey at zoominternet.net
Fri Jun 5 11:36:36 PDT 2009


Hi Ian,

>> 1. Having to type <pre><code><tagname></code></pre> seemed a little 
>> bit
>> silly to me:
>> is there a use case for *not* wanting <pre> when doing <code>? Could that 
>> not
>> be handled as an attribute of the <code> if so?
>
> <code> is used a lot to refer to method names and the like, where the
> contents aren't preformatted. (For example, HTML5 uses <code> over 14,000
> times but <pre> only about 500 times currently.)

Oh, okay, I see. But for the very common case in which there is a block of 
code how about something like
<code type="pre">
<html>
       <p>happy</p>
</html>
</code>

instead of
<pre><code>
<html>
       <p>happy</p>
</html>
</code></pre>
? (assuming the '<' s have all been escaped one way or another)

Thanks for your example:

<p>Type <code>ls <var>dir</var></code> to see what's in the directory
<var>dir</var>.</p>

it explains the basic reasoning, but still befuddles me a bit, I guess. It 
seems like the number of folks needing to preserve HTML functions inside 
code as in this example,  might be smaller than the number of folks doing 
XML or HTML, so why not make the smaller group do the extra work, instead of 
the others?

That is, the parser has to, it seems, have an exception that says either
    a) don't render the < literally but as <
 or
    b) when inside <code> don't render the <var></var> (phrasing content?) 
tags literally but as their HTML equivalents

No big deal, as I can see your point.  I tried reading up on the distinction 
between phrasing and non-phrasing content in
http://dev.w3.org/html5/spec/Overview.html but that document (dated June 5, 
2009) seems to be crashing both FF and IE for me this afternoon..

On the other hand,
a simple

<code lang="xml/html">

could be used to introduce the <pre> and all the < s

I do miss <xmp> whenever I have to do this sort of stuff.

cheers
David 




More information about the whatwg mailing list