Topic: Code blocks in <pre><code>

Hello!

PunBB currently marks up code snippets as a <pre> wrapped in a <div> with a special class. However there is a common convention of marking up code snippets as <pre><code>. It is used by Markdown and is proposed for standartization in HTML5. More than this it just makes sense semantically and is very clean (e.g. doesn't require any special classes).

I think PunBB could easily adopt this technique by adding <code>...</code> inside <pre> also keeping the wrapper div. This would be backward compatible and will make it forward compatible with whatever tools using this convention would appear in the future.

Why I really care about this thing is that I'm the author of such a tool. It's a javascript library for highlighting code snippets in forums and blogs -- highlight.js. It uses <pre><code> for detecting code snippets and this is why I  propose it for PunBB that I also use on my site.

Thank you for your attention!

Re: Code blocks in <pre><code>

This is also how I post code on my design site and on my blog. Its easier for me to remember to just put <code> around my code. smile

3

Re: Code blocks in <pre><code>

The next version of PunBB already uses <pre><code> and has done for quite some time. It still requires special classes though as getting cross browser scrolling boxes etc without a wrapping div is extremely difficult given the way some browsers mangle the code tag if set to dispaly:block.

The only problem of course is what if its not code i.e. sombody could use the bbcode code tags to post ascii art in which case the <code> tag is semantically wrong. Strictly speaking there should also be a bbcode pre tag.

4 (edited by guardian34 2007-01-20 15:44)

Re: Code blocks in <pre><code>

Paul wrote:

The only problem of course is what if its not code i.e. sombody could use the bbcode code tags to post ascii art in which case the <code> tag is semantically wrong. Strictly speaking there should also be a bbcode pre tag.

Strictly speaking, there should also be a <kbd> tag for providing, say, shell commands.

Edit: Maybe it's ascii art for a command line tool. tongue

Re: Code blocks in <pre><code>

The next version of PunBB already uses <pre><code> and has done for quite some time.

Great!

given the way some browsers mangle the code tag if set to dispaly:block.

Oh yes :-). I've just given up on IE in this regard on my blog...

sombody could use the bbcode code tags to post ascii art in which case the <code> tag is semantically wrong

Well... I believe this is a common problem with semantics: you can't expect all people using the web to understand it and to use it properly. So it will always be abuse of semantic elements. This is why some technologists consider semantics not only the matter of standard but also the matter of actual usage practice. And there if people get semantics right like 80% of the time -- it's worth supporting it. And this is the case for <code> I believe.