9

If I type this code using the new fence-style code blocks, it displays fine:

#include <stdio.h>

int main(int argc, char** argv)
{
    int i = 6;
    while(i --> 0) printf(i);
    return 0;
}

But when I add a newline after int i = 6; (or any indented section), it displays things weirdly:

#include <stdio.h>

int main(int argc, char** argv)
{
    int i = 6;

    while(i --> 0) printf(i);
    return 0;
}

It works as expected with 4-space indented code blocks:

#include <stdio.h>

int main(int argc, char** argv)
{
    int i = 6;

    while(i --> 0) printf(i);
    return 0;
}

Looking at the HTML structure, it appears that it is creating a code block (from the four spaces indent) within the ``` code block.

  • 2
    This is fixed on meta, and being deployed to the rest of the network right now (should be done in ~5 minutes). I'll write up an answer with an explanation tomorrow, but it's getting late here :) Thanks for the report! – balpha Jan 8 at 21:07
2

What happened here was caused by the fact that there are now two different ways of making a code block. As you noticed, the rendered HTML had a code block inside a codeblock – this occured because I didn't make sure that the two different code block kinds could never overlap, and so that's exactly what happend.

After handling code fences, the intermediary content looked like this:

<pre><code>
#include &lt;stdio.h&gt;

int main(int argc, char** argv)
{
    int i = 6;

    while(i --&gt; 0) printf(i);
    return 0;
}
</code></pre>

Now the "indented code block" logic looked at this result, and it saw an indented code block in the while / return lines, and thus this happened:

<pre><code>
#include &lt;stdio.h&gt;

int main(int argc, char** argv)
{
    int i = 6;
<pre><code>
while(i --&amp;gt; 0) printf(i);
return 0;
</code></pre>
}
</code></pre>

Once we switch to an actual CommonMark parser, this kind of thing can't happen anymore. But right now we're still using the classic "regex replacement" approach to Markdown rendering, and that needs some extra care.

You must log in to answer this question.

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