5

I entered the question and answer text from a book. Both, obviously, had the same number which happened to be 2: Javascript practice test question: anonymous functions.

Even though I correctly put 2 for both, SO is rendering the answer section as "3".

Is there a more correct way I should have entered this to prevent that behavior?

Edit: Dang, as soon as I wrote this I clicked back on the link and now I see it says 2. Guess I have to check the edits now to see if maybe I initially made a mistake and someone else corrected it...

Edit 2: Okay, someone "fixed" it for me. That's why it renders correctly now.

1
  • 3
    If you want two things (lists, code blocks, block quotes) to be separated in Markdown, simply put an HTML comment (an empty one, like <!-- -->) between them. See this revision. Alternatively, use actual HTML, e.g. <ol> <li></li></ol>, <blockquote></blockquote>, etc. Commented May 28, 2020 at 7:15

1 Answer 1

6

It's not a bug. This is by design. Markdown lets you skip having to maintain the sequential order of a numbered list. You can just number everything as "1.", and then let the engine figure out the actual order when it renders it. (Open the source of this answer to see an example!)

There is one additional quirk: Stack Overflow Markdown lets you start the list with any number you want.

That's why your list began with "2." (because that's what you started numbering with), and then why the next item was numbered "3." (because that's the next cardinal number after 2).

There are two possible workarounds to avoid this and get exactly the numbers you want in the list, both of which have been demonstrated by edits to your question:

  1. Escaping the number, like so: 2\.

    This lets you use any arbitrary sequence of numbers that you like, but with the drawback of it no longer being an actual list. (In other words, it doesn't get rendered as an <ol> in the resulting HTML.)

  2. Inserting an HTML comment after the list item, which breaks up the list into multiple, separate and distinct lists.

    This is a bit less obvious and less discoverable, but it works nicely, especially paired with the fact that you are allowed to start a list's numbering with any number you want.

Interestingly, this very topic is covered as part of the discussion in the original introduction of Markdown, by John Gruber.

You must log in to answer this question.

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