2

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

As part of this answer on SO I entered a code block. The code however was not being displayed in the markup, it was just plain text with no line breaks. I tried multiple times copying and pasting it in, entering tabs/spaces for the indents and highlighting it and clicking the 'Code Sample' button.

Here is an example of the failure case...

  1. Here is a list item. The code direclty after is not formatted correctly.

    import java.text.SimpleDateFormat import java.text.DateFormat

    Date timeDate1 = new Date().parse("dd-MM-yyyy HH:mm:ss Z","18-05-2012 09:29:41 +0800") Date timeDate2 = new Date().parse("dd-MM-yyyy HH:mm:ss Z","18-05-2012 09:29:21 +0900")

After further testing it seems that if you enter source code directly after a list then the code will not be formatted correctly.

How do correctly display code blocks after a bullet list?

0
2

Enter a dash - character on it's own line after the bullet list.

  1. The code below works (with the dash character the code block displays correctly formatted). E.g.:

-

import java.text.SimpleDateFormat
import java.text.DateFormat

Date timeDate1 = new Date().parse("dd-MM-yyyy HH:mm:ss Z","18-05-2012 09:29:41 +0800")
Date timeDate2 = new Date().parse("dd-MM-yyyy HH:mm:ss Z","18-05-2012 09:29:21 +0900")

This however seems like a work around. I would think it should be possible to display code after a list without needing to add an extra unnecessary character.

2
  • 2
    It is, just indent 8 spaces, rather than 4. – Cody Gray May 24 '12 at 12:59
  • 2
    @TheEstablishment But that makes the code block part of the last list item. A <!-- comment --> between list and code block works without displaying a stray extra character (but is more work than typing a single dash). – Daniel Fischer May 24 '12 at 13:50

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