46

Writing a question including a C code in a <pre><code> block, I found out that in my #include lines the header names are not displayed when using the standard <name.h> convention. Instead, I had to use quotes "name.h" to make it appear. Apparently, the renderer treats these as tags, and I could not find a way to escape them. So, what is the method for doing it?

4
  • You don't have to wrap them in <pre><code> blocks yourself. Just use standard markdown formatting. Doing this should have your includes appear just fine.
    – Bart
    Oct 12, 2012 at 0:44
  • Bart - if by "standard" you mean four spaces, please see my reply to @blahdiblah.
    – ysap
    Oct 12, 2012 at 0:50
  • 2
    Yep, 4 space indentation. Ctrl-k. Simple as that.
    – Bart
    Oct 12, 2012 at 0:55
  • 1
    Since then: CommonMark and code fences Apr 11 at 14:56

1 Answer 1

65

The standard way of including code is by indenting it all with four spaces:

like so

(literal text: "    like so")

Or, for inline blocks, surrounding it with backticks like so (literal text: "`like so`").

As you've seen, using <pre><code> has unexpected limitations and also doesn't support nifty stuff like automatic code coloring.

That said, if you really want < and > you can get them with &lt; and &gt;

<foo>
4
  • 1
    Sure, this is easy for short code pieces, but when you have a long block, it is tiring to add and/or remove all these spaces while still maintaining the original indentation/tabulation.
    – ysap
    Oct 12, 2012 at 0:48
  • 6
    @ysap, select the code and hit Ctrl + K or use the code indent button on the formatting toolbar, looks like {}. I suggest hitting the question mark button on the right side of the formatting toolbar for additional editing help.
    – Charles
    Oct 12, 2012 at 0:50
  • @Charles - thanks. This is definitely the best way to do this. However, my past experience is that I went into troubles using this operation - probably my fault, but once I learned about that <pre><code> feature, I decided that this must be the best way, as the code does not need any change to be displayed as code... apparently, the #include directive proved that even this has its own limitations.
    – ysap
    Oct 12, 2012 at 0:55
  • 1
    The &lt; / &gt; solution is also useful if you are in a blockquote rather than a code block.
    – dumbledad
    Sep 21, 2016 at 8:52

You must log in to answer this question.

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