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

Possible Duplicate:
Code block is not properly formatted when placed immediately after a list item

In this post about nesting code-blocks in lists, it is explained that if you want to nest a code-block in a list, you need to indent your code 8 spaces. This will allow you to include the code block as part of a list item. Is there any way to place code blocks after lists without having them use the same indentation level as the list that came before it?

The only solution I've found is to place a single character somewhere between the list item and the code block so it "switches off" the list formatting mode. Something like this:

  1. list item 1  
  2. list item 2

.

    string myVariable = "hello world"

Which will output like this:

  1. list item 1
  2. list item 2

.

string myVariable = "hello world"

Without the period I'd have to indent my code 8 spaces, which would put the code block at the same level as the list item. This isn't a major problem, but I was just wondering if there was a better way to get Markdown to do what I want it to.

Is there any way to force the "list item" formatting mode to switch off. It seems like the "list mode" will stay enabled until a line is reached that starts with a character other than a space.

share|improve this question

marked as duplicate by balpha Feb 1 '12 at 20:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 26 down vote accepted

A hacky way to get it displayed correctly is to replace the dot in your example with a Html-tag that won't be rendered to anything visible:

- list
- items

<b></b>

    code

This is then rendered like this:

  • list
  • items

code
share|improve this answer
9  
That's a good idea. I would use HTML comments <!-- -->, but that works great! I just wish there was a more intuitive option available... –  Dan Herbert Jan 1 '10 at 21:00

code block after a list:

  • this
  • is a
  • list
this is a code block

markup:

- this
- is a
- list

<!-- well hey there sailor -->

    this is a code block
share|improve this answer
1  
the usual caveat .. you must manually escape any < or > in the code block. Using a HTML comment as a "paragraph break" is probably easier. –  Jeff Atwood Jan 2 '10 at 3:01
    
This is a fine work around for those that know about it, but this is still a bug, any chance on getting it fixed? –  Sam Feb 25 '11 at 2:10
2  
@sam not a bug, this is part of the Markdown spec. Go look it up if you don't believe me. –  Jeff Atwood Feb 25 '11 at 2:27
    
@Sam: See balpha's explanation here. –  Hendrik Vogt Jul 24 '11 at 9:27
    
Shouldn't there be commas after "well" and "there"? –  Cary Swoveland Nov 27 at 19:33

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