1

When a paragraph starts with a decimal digit followed by a dot, the value of that number is silently renumbered to whatever markup believes it should be without any warnings. I would expect that the rendered text contains at least some red remark if the rendered number differs from the user provided number.

It happened to me in the following situation: The first numbered item also contained a <pre>; therefore, the enumeration was considered to be finished. The second numbered item which started with 2. is now rendered as 1.

I have always found the implicit enumeration in Latex and HTML very error prone too. Ideally the implicit numbering is checked against the user provided numbers.

What would be best in this situation is to alert to such problems by rendering the problematic item with some error message.


Example

  1. This is the first item.
with a pre
  1. This is the second item, but it is rendered as 1

  2. This is the third item, but it is rendered as 2


To answer the question by @dmckee (I cannot comment here on meta for some unknown reason...): I need to use <pre> such that I can use <s> and <b> within program text. This I need for program slices, in particular

6
  • 1
    Could you provide an example, so we don't have to sit here and try to decode exactly what scenario you're talking about?
    – animuson StaffMod
    Commented Dec 1, 2012 at 22:50
  • 3
    This is well-documented markdown behavior. See here.
    – hammar
    Commented Dec 1, 2012 at 22:56
  • First of all: why are you mixing html literals in with markdown like that? There is no need to use <hr> when markdown supplies \n---\n to do the same nor <pre> when you have backticks or > for block quotes. Commented Dec 1, 2012 at 23:03
  • @dmckee: I need <pre> because I annotate programs (actually, executable program slices, see failure-slice) with <s> and <b>.
    – false
    Commented Dec 3, 2012 at 19:19
  • 1
    This was fixed with the transition to CommonMark and the added support of a different starting number. Commented Sep 15, 2023 at 8:13
  • @SonictheAnonymousHedgehog Thank you! Please make this an answer such that I can accept it and, finally close this question!
    – false
    Commented Sep 15, 2023 at 9:14

1 Answer 1

4

The interaction between numbering and code blocks isn't all that straightforward, but StackOverflow sticks to the Markdown design, which says

It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces.

The 1. syntax is Markdown's shorthand for an html ordered list, and will be replaced with <li> tags so you lose control of the numbering because the html doesn't specify numbers anyway.

Workaround: always check the preview underneath your answer/question to make sure it looks as you'd like.

To include inline code inside a numbered item, indent it as least as much as the item, otherwise you end the list:

 1. Item one
    <pre> some code </pre>
    `some more code`

 2. Item two

        But here's a block of code
        indented by 8 spaces

     1. Nested list item one

            as hammar points out
            in his comment nested comments can have nested code

     2. Nested list item two

            as long as the code starts 4 spaces in from the text.

 3. Item three

gives:

  1. Item one

     some code 

    some more code

  2. Item two

    But here's a block of code
    indented by 8 spaces
    
    1. Nested list item one

      as hammar points out
      in his comment nested comments can have nested code
      
    2. Nested list item two

      as long as the code starts 4 spaces in from the text.
      
  3. Item three

4
  • 1
    Backticks are for inline code. To get a full code block within a list item without using <pre>, you just need 8 spaces of indentation total (or 12, 16, etc. for code within nested lists).
    – hammar
    Commented Dec 1, 2012 at 23:07
  • Good point. Edited in. Thanks.
    – AndrewC
    Commented Dec 1, 2012 at 23:11
  • 1
    html allows you to explicitly specify the value of a <li> tag. Commented Dec 2, 2012 at 10:32
  • @CodesInChaos but AFAIK, markdown doesn't, and just gives you a bald <li> tag.
    – AndrewC
    Commented Dec 2, 2012 at 10:42

You must log in to answer this question.

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