24

I've tried at various times to have code-blocks with different syntax highlighting.
That is important if a question/answer contains source code in different languages, or you want to suppress distracting highlighting of example input/output.

Here a quote of what I tried:

C source:<!-- language: lang-c -->

    int main(void)
    {
        return 0;
    }

Now directly without quotes:

C source:

int main(void)
{
    return 0;
}

AFAICT, I followed the guide in the help center exactly, but it does not work. (language-all is not an option)

3
  • 10
    You have to put a blank line before and after the html comment.
    – gunr2171
    Commented Jun 2, 2014 at 20:56
  • 2
    @gunr2171: Thanks, that got it done. Commented Jun 2, 2014 at 20:58
  • 1
    You can always press the edit button on somebody else's question / answer if you see them using something you like. Then you can see exactly how they did it.
    – Dave
    Commented Jun 3, 2014 at 18:29

1 Answer 1

51

The comment has to be put on a separate line, with blank lines before and after (e.g. its own Markdown paragraph):

C source:

<!-- language: lang-c -->

    int main(void)
    {
        return 0;
    }

The extra lines are not part of the rendered output:

C source:

int main(void)
{
    return 0;
}
3
  • Stress the blank lines before and after the comment, and I'll accept it whenever I can. Commented Jun 2, 2014 at 21:02
  • There you go :-) I've worked with Markdown so much now I 'separate line' and 'separate paragraph' are almost synonymous now. Commented Jun 2, 2014 at 21:04
  • 21
    Should probably be worked into the markdown help page, too... Commented Jun 2, 2014 at 21:06

You must log in to answer this question.

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