[uf-discuss] Formating Code

Tantek Ç elik tantek at cs.stanford.edu
Wed Nov 2 08:55:33 PST 2005


On 11/2/05 8:26 AM, "Jacob Ham" <hakejam at gmail.com> wrote:

>> But its not part of the presentation, its part of the structure/meaning.
>> 
> 
> How could we tell the difference between languages that are white
> spaced sensitive, and ones that are not?  Some languages would need
> <pre> and some would not.  How human readable is:
> 
> <pre>
>   <code>
>   blah
>   </code>
> </pre>
> 
> compaired to:
> 
> <code class="Python">
> </code>
> 
> If we created a microformat, Python informed Microformat engines would
> be aware of how to deal with the Python or MyNewLang formating
> (semanticly). The 'pre' element is for "pre-formatted text" [1].

And code is text, therefore it makes sense.

> I am
> not saying that we shouldn't use the semantics that are available to
> us in HTML, but that we are using the 'pre' element in the wrong way
> (for programming languages).
> 
> Maybe I am thinking to hard, or looking at this the wrong way.

Consider that both <pre> and class="python" provide additional semantics to
<code>.

Typical source code *is* white-space sensitive, and thus when providing a
block of source code it makes sense to use the <pre><code> XHTML compound.

Now, in *addition*, there is nothing wrong with extending that with a
semantic class name on the <code> to indicate the language.  For example,
many CSS specifications already do this with <code class="css"> and <code
class="html">.

But that's just proper use of semantic class names.  It's ok to stop with
that.  It's not even clear that it is necessary if you're thinking from the
perspective of a search engine which is going to go out there and index all
blocks of code -- it could just index instances of the <pre><code> compound,
and perhaps use other heuristics to determine the language of the code.

However, the real question is:

Is there really a need for a microformat for code?

I'm not convinced of that yet.

If you think there is, then I invite you to follow the steps indicated in
the process:

 http://microformats.org/wiki/process

which will help scientifically answer that question based on microformat
principles.

Thanks,

Tantek



More information about the microformats-discuss mailing list