[whatwg] <code> attributes

Ian Hickson ian at hixie.ch
Thu Jun 4 21:51:09 PDT 2009


On Wed, 29 Apr 2009, ddailey wrote:
>
> 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.)


> 2. having to escape "<" as < in the middle of <code> seems like work for
> the author that could just as easily be handled by the browser. In the old
> days, <xmp> worked pretty well... why no replacement for its functionality??

If you can use XML, use <![CDATA[ ... ]]> to escape the element's 
contents.

In text/html, I think for HTML5 we've introduced enough changes to the 
parser for one version; I'd rather not add more until the current set have 
been well-implemented.


> 3. trying to style a <code> so that it would have an indented margin, a
> border, a default font-style (monospaced), preserve within -line indentation,
> and work consistently across browsers seemed to defy my humble abilities with
> CSS. (see
> http://srufaculty.sru.edu/david.dailey/cs427/StateOfArt-Dailey.html#test_file
> as an example of the very clumsy solution I ultimately opted for -- IE still
> doesn't preserve within-line indentation in this solution-- it used a styled
> table with a styled td and was particularly gross!.)

If this is due to bugs, I encourage you to report them to your browser 
vendors. If it is due to limitations of CSS, I encourage you to bring this 
to the attention of the CSS working group.


> 4. if we could just write
>    <code language="xml">
>    <html>
>        <body>
>            <svg><rect/></svg>
>        </body>
>    </html>
> </code>,
> it'd be nice to have the page render the HTML just as is.

I'm not really sure what you mean here.


> 5. Some of the good folks on either whatwg-irc or htmlwg-irc let me know that
> <code><p>happy</p><p>sad</p></code> was bad form, and that I should use
> <pre><code> instead. It never would have dawned on me that the first was bad
> form, nor that the second would be good form. (maybe it should have dawned on
> me, but I speak html sorta like I speak english, more through habit than
> training, and not very formally at that). Second the introduction of <p>
> within <code> was actually generated by a robot that converted a bunch of MS
> Word to <html> so someone other than me must have thought it was a good idea
> to do it that way.

The main reason not to allow this is that there are some very unintuitive 
results when parsing text/html where phrasing elements (like <code>) 
contain non-phrasing content (like <p> -- especially <p>, in fact).

I'm not sure what we can do about this.


On Thu, 30 Apr 2009, Smylers wrote:
> > 2. having to escape "<" as < in the middle of <code> seems like 
> > work for the author that could just as easily be handled by the 
> > browser.
> 
> It could.  But doing so would prevent being able to use other elements 
> inside <code>, such as:
> 
>   <p>Type <code>ls <var>dir</var></code> to see what's in the directory
>   <var>dir</var>.</p>

That's a good point; HTML5 itself does this a lot in the spec text.

Cheers,
-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list