What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I noticed the other day that two nearly identical answers to a question were slightly different.

The first one (the accepted answer) uses four spaces. The second answer (highest non-accepted answer, at time of this writing) uses <code> tags. I'm pretty sure this is why it doesn't highlight.

It seems to me that the two should use the same engine for rendering, but it doesn't appear to be that way.

share|improve this question
    
Related: How do I format my code blocks? –  Arjan Feb 11 '13 at 22:42

2 Answers 2

up vote 3 down vote accepted

No, they don't use the same engine. For one, the markdown syntax adds a <pre class="..."> tag around the <code> tags with language highlighting metadata.

Markdown happens to support inline HTML for 'manual' formatting, but once you move to such manual formatting, you also loose the possibility to attach richer metadata such as the language highlighter to use.

If you must use <code> add a <pre> tag around it (no class or style information, that'll cause it to be filtered out) and optionally add a highlight hint:

<!-- language: lang-xml -->

<pre><code>&lt;some>
    &lt;bogus>&lt;xml />&lt;/bogus>
&lt;/some>
</code></pre>

becomes:

<some>
    <bogus><xml /></bogus>
</some>

but you have to do all the escaping by hand. :-)

share|improve this answer
    
So <code> isn't part of Markdown, it's actually part of html? –  corsiKa Feb 11 '13 at 22:27
    
@corsiKa: exactly. It's a HTML 5 element. –  Martijn Pieters Feb 11 '13 at 22:28
    
Well then, I'd say it's hardly a bug... thanks! –  corsiKa Feb 11 '13 at 22:29
    
@corsiKa: nope, this is status-bydesign. –  Martijn Pieters Feb 11 '13 at 22:30
    
<pre><code> works just fine. –  Arjan Feb 11 '13 at 22:33
    
@Arjan: Ah, it's the class and style attributes that cause it to be filtered out. –  Martijn Pieters Feb 11 '13 at 22:35
    
Not sure what you mean by that. Plain <pre><code> is also enhanced by the SE JavaScript, which then makes Prettify highlight it. Still then, Markdown 4-spaces is so much easier, if only as one does not have to encode any < and > characters. –  Arjan Feb 11 '13 at 22:38
    
...and the highlight hint is not needed if the question is tagged with some language ;-) –  Arjan Feb 11 '13 at 22:43
    
@Arjan: I mean that if you add in <pre class="..."> the pre tag is removed again. I was updating my answer with the same info already. :) –  Martijn Pieters Feb 11 '13 at 22:43
    
@Arjan: Ah, added a 'optionally' in there. –  Martijn Pieters Feb 11 '13 at 22:44
    
Hmm that sure does seem like a lot of work. I guess it was just by a user who didn't know about Markdown. Thanks for the thorough analysis! –  corsiKa Feb 12 '13 at 15:37

The highlighting doesn't work because it's specified in the surround <pre> tag, not the <code> tag:

<pre class="lang-xml prettyprint" style="">
    <code>

Using <pre><code> works just fine too:

Look ma, <em style="xyz">highlighting</em>!

Using <code> alone is bad practice. If you must use HTML instead of Markdown, you should use <pre><code>, which is what indentation by four spaces generates.

share|improve this answer
    
prettyprinted is added by Prettify. –  Arjan Feb 11 '13 at 22:28
    
I just ninja-edited the answer to add <pre> tags. It prettifies. –  Dennis Feb 11 '13 at 22:29
    
(I meant the "prettyprinted" CSS class; but I edited it out.) –  Arjan Feb 11 '13 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .