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

Consider the following code block:


#include 

It's only showing #include, but what I've typed in the code block is #include <yajl/yajl_parse.h>. So, the < is not being escaped properly.

Here's another code block:

for ( i=1; i 

That should be for ( i=1; i < strlen(argv[a]); i++) .

According to the formatting help:

Like code blocks, code spans will be displayed in a monospaced font. Markdown and HTML will not work within them. Note that, unlike code blocks, code spans require you to manually escape any HTML within!

So it seems like the intent is to automatically escape all HTML -- or am I not understanding how code blocks should work?

share|improve this question
4  
Rather than using <pre> and <code> shouldn't you just be indenting by 4 spaces? –  shanethehat Aug 13 '11 at 14:58
    
The reason this came up is because I was pasting a code example into an answer. The code is maybe 75 lines long. So, no, I don't think I should be indenting each line. –  Answerbot Aug 13 '11 at 15:04
6  
@Harkonian There's a {} button in the editor that will indent selected text for you. –  Anna Lear Aug 13 '11 at 15:05
    
The formatting help you're quoting doesn't actually say that you should use <pre><code> yourself. It says that to create a similar effect, you should indent with 4 spaces. –  Cody Gray Aug 14 '11 at 9:13

2 Answers 2

up vote 7 down vote accepted

"Code blocks" in this context means code blocks generated by Markdown when you indent content four or more spaces. In your case, using the following would have worked as you expected:

    #include <yajl/yajl_parse.h>

in the post editor produces

#include <yajl/yajl_parse.h>

in the generated content.

If you use raw HTML in your post, anything within that raw HTML must be escaped manually, because the Markdown parser cannot make assumptions about what you did and did not want escaped in that case.

As jonsca hinted at, to make applying the Markdown formatting easy you can select all of the relevant code text and then press the code format button (code formatting button icon, shortcut Ctrl+K) to indent it all at once.

share|improve this answer
    
Ah, actually I think you might be correct. Rereading the section on code blocks, "Indent four spaces to create an escaped <pre><code> block" which seems to indicate that <pre><code> is not escaped. Which is unfortunate, because it makes pasting code of any length more of a hassle. –  Answerbot Aug 13 '11 at 15:10
6  
@Harkonian how is it a hassle? Paste it, select the code region, hit ctrl+k –  Marc Gravell Aug 13 '11 at 15:47

Instead of using the <code></code> as you did, which I believe translates to the inline code spans (I usually just use backtics), just indent your code by 4 spaces.

Alternatively, select the pertinent code and click the {} button in the toolbar above the editor. This will give you a block.

share|improve this answer
1  
Backticks also give you escaping, while <code></code> doesn't. So backticks are superior there too. –  sth Aug 13 '11 at 15:01
    
As I indicated above -- the reason this came up is because I was pasting a code example into an answer. The code is maybe 75 lines long. So, no, I don't think I should be indenting each line. And according to the formatting help that I quoted in my question, using <pre><code> should automatically escape any code. –  Answerbot Aug 13 '11 at 15:06
    
@Harkonian You don't have to indent each line. Highlight the entire sample and press the {}. Honestly, I don't know the underlying mechanism, but it works. –  jonsca Aug 13 '11 at 15:08

You must log in to answer this question.

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