[uf-discuss] Formating Code
Jacob Ham
hakejam at gmail.com
Tue Nov 1 11:27:29 PST 2005
> > Just to throw in my comments. When I include "code", I usually do it like
> > this:
> >
> > <pre>
> > <code>
> >
> > class HellWorld {
> > public static void main(String args[]) {
> > System.out.println("Hello World");
> > }
> > }
> >
> > </code>
> > </pre>
> >
> >
> > That way you get the semantics that this is "code" -- from the <code>
> > element. And <pre> element tells the browser that the white space is
> > significant.
>
> Wow! I came to the same conclusion Charles.
>
> I've labeled such uses of multiple XHTML Elements in combination to form a
> new meaning an "XHTML Compound".
>
> Originally:
> http://tantek.com/presentations/2005/03/elementsofxhtml/
> Most recently:
> http://tantek.com/presentations/2005/09/elements-of-xhtml/
>
> I've been referring to the <pre><code> construct as a blockcode, as that was
> the obvious name that we (W3C HTML WG at the time) came up with for an
> element for the block version of a code element years ago.
>
> Shortly after that I realized two key things:
>
> 1. It was really dumb to have two of the same element just to represent some
> odd inline vs. block content nesting concept which was useless to web
> authors, who could use CSS to affect the presentation anyway. The whole
> inline vs. block content model thing has been nothing but trouble.
>
> 2. There was no need to wait for XHTML2 and a new <blockcode> tag when
> <pre><code> captured the necessary semantic (in the same number of
> characters).
Is there really a need to use both 'pre' and 'code' elements? I admit
that I have done the the same thing. There is the CSSv1 element
'white-space' that helps relieve this problem
[http://www.w3.org/TR/CSS1#white-space]. There isn't really a need
for using <pre> at all. Also, after a little investigating, I have
found out there is actually an (X)HTML element for displaying program
output, script results, etc called samp
[http://www.w3.org/TR/html4/struct/text.html#edef-SAMP].
Thanks Tantek for point me in the right direction, and apologies for
the html encoded email. As I see it there really only need to be 2
elements for displaying programming languages in (X)HTML, <code> for
actual computer code, and <samp> for the output. Most of the other
information can be made up of other microformats (vCard, rel-license).
There might be a need for its own 'version'.
My other question is how ambiguous could a class for the element
'code' be? Example, there can be code for Python (<code
class="Python">) and a different class for interactive Python (like
found in the examples in Diveintopython.org).
Cheers,
Jake
More information about the microformats-discuss
mailing list