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?
-
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.– BartOct 12, 2012 at 0:44
-
Bart - if by "standard" you mean four spaces, please see my reply to @blahdiblah.– ysapOct 12, 2012 at 0:50
-
2Yep, 4 space indentation. Ctrl-k. Simple as that.– BartOct 12, 2012 at 0:55
-
1Since then: CommonMark and code fences– This_is_NOT_a_forumApr 11 at 14:56
1 Answer
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 <
and >
<foo>
-
1Sure, 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.– ysapOct 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.– CharlesOct 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.– ysapOct 12, 2012 at 0:55 -
1The
<
/>
solution is also useful if you are in a blockquote rather than a code block. Sep 21, 2016 at 8:52