Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested lists don't work in markdown #137

Closed
jgm opened this issue Jun 10, 2011 · 6 comments
Closed

Nested lists don't work in markdown #137

jgm opened this issue Jun 10, 2011 · 6 comments
Assignees

Comments

@jgm
Copy link
Owner

jgm commented Jun 10, 2011

What steps will reproduce the problem?

  1. Create a document with a nested list in markdown:
    {{{
  • a
    • should be nested
  • but it's not
    }}}
  • Convert it to any format, I checked html and mediawiki

What is the expected output? What do you see instead?

The output is not a nested list. The nested element appears at the same
level as the other elements.

What version of the product are you using? On what operating system?

1.4 on windows.

Google Code Info:
Issue #: 229
Author: paul.chi...@gmail.com
Created On: 2010-04-01T15:19:28.000Z
Closed On: 2010-04-01T22:46:16.000Z

@ghost ghost assigned jgm Jun 10, 2011
@jgm jgm closed this as completed Jun 10, 2011
@jgm
Copy link
Owner Author

jgm commented Jun 10, 2011

Nested lists need to be indented four spaces or a tab. This is implied by the markdown
syntax documentation, but not all implementations of markdown respect it.

Google Code Info:
Author: fiddloso...@gmail.com
Created On: 2010-04-01T22:46:16.000Z

@jgm
Copy link
Owner Author

jgm commented Jun 10, 2011

It is implied by the markdown syntax documentation? Where? John Gruber's
implementation works for any number of leading spaces, you can verify at:
http://daringfireball.net/projects/markdown/dingus

But good to know it works somehow. :)

Google Code Info:
Author: paul.chi...@gmail.com
Created On: 2010-04-02T03:40:34.000Z

@jgm
Copy link
Owner Author

jgm commented Jun 10, 2011

What's explicit in the markdown syntax description is that continuation paragraphs
in a list item need to be indented four spaces (or eight if they're code blocks). It's
reasonable to infer that all block-level elements in a list item need to be indented
four spaces (at least in their first line - markdown allows you to be lazy about
subsequent indents). Since a list is a block-level item, it's reasonable to assume the
same rule applies there. And that is what many markup implementations, including
pandoc, do.

It's true that Markdown.pl allows less than four-space indentation, but its treatment
of nested lists is notoriously inconsistent, and it can't be used as any kind of a
model. Try this, for example:
% Markdown.pl

  • one
    • two
      • three
        • one
          • two
          • three

Here's you'd expect three levels of nesting, but you only get two. There are other
examples on pandoc's googlecode wiki of crazy nested list behavior by Markdown.pl.

You might ask: why not just consistently make any additional indentation start a
sublist? That would be easy to implement, and in fact that is how restructured text
does it. I think that one motivation for the different decision in markdown was to
allow list markers to be right-aligned. Consider:

  1. nine
    1. ten
    2. eleven

Here the numbers don't line up in the same column on the left, but we want them to
be considered a single-level list.

Anyway, this has been discussed at times on markdown-discuss, and no clear
standard has emerged. Some people prefer a four-space rule; others a three-space
rule; still others an any-additional-indent rule:
http://thread.gmane.org/gmane.text.markdown.general/1981/focus=1998

Google Code Info:
Author: fiddloso...@gmail.com
Created On: 2010-04-02T06:38:51.000Z

@jgm
Copy link
Owner Author

jgm commented Jun 10, 2011

Thank you for the thorough response. It does not surprise me that even Gruber's
implementation is totally inconsistent. That is what happens when you implement
something like markdown using a mess of interacting regex replacements, I suppose. :)
Sorry for the bad bug report - honestly, I just thought nested lists didn't work at
all. Your decision on how to handle things seems totally valid to me.

Awesome project, btw.

Google Code Info:
Author: paul.chi...@gmail.com
Created On: 2010-04-02T11:54:33.000Z

@mhbrown
Copy link

mhbrown commented Apr 27, 2016

I was just struggling with nested lists a bit and upon Googling, came across this resolved issue and the comment I liked above from @jgm was the answer for me.

I think https://guides.github.com/features/mastering-markdown/ should be updated to say indentation should be 4 spaces or a tab.

Also, the examples for nested lists use 2 spaces in the Lists example, but the Lists section on the page shows 3 spaces. These should both probably use 4 spaces to further clarify.

Thanks!
-Martin

@jgm
Copy link
Owner Author

jgm commented Apr 27, 2016

@mhbrown - yes, absolutely. The advice in the "mastering markdown" page you link to is very bad. The only safe advice that will work reliably across all Markdown implementations is to use a 4-space indent. A 2-space indent

See http://johnmacfarlane.net/babelmark2/?normalize=1&text=+-+a%0A+++-+b%0A+++++-+c%0A+++++++-+d%0A for an illustration.

The situation is even worse for ordered lists: http://johnmacfarlane.net/babelmark2/?normalize=1&text=+1.+a%0A+++2.+b%0A+++++3.+c%0A+++++++4.+d%0A. Only one implementation (not the one GitHub uses) consistently honors a 2-space indent.

Please give feedback to GitHub to change their misleading guide.

jgm added a commit that referenced this issue Feb 27, 2017
LaTeX template: add babel-otherlangs and babel-newcommands
jgm added a commit that referenced this issue Aug 19, 2017
Closes #3511.

Previously pandoc used the four-space rule: continuation paragraphs,
sublists, and other block level content had to be indented 4
spaces.  Now the indentation required is determined by the
first line of the list item:  to be included in the list item,
blocks must be indented to the level of the first non-space
content after the list marker. Exception: if are 5 or more spaces
after the list marker, then the content is interpreted as an
indented code block, and continuation paragraphs must be indented
two spaces beyond the end of the list marker.  See the CommonMark
spec for more details and examples.

Documents that adhere to the four-space rule should, in most cases,
be parsed the same way by the new rules.  Here are some examples
of texts that will be parsed differently:

    - a
      - b

will be parsed as a list item with a sublist; under the four-space
rule, it would be a list with two items.

    - a

          code

Here we have an indented code block under the list item, even though it
is only indented six spaces from the margin, because it is four spaces
past the point where a continuation paragraph could begin.  With the
four-space rule, this would be a regular paragraph rather than a code
block.

    - a

            code

Here the code block will start with two spaces, whereas under
the four-space rule, it would start with `code`.  With the four-space
rule, indented code under a list item always must be indented eight
spaces from the margin, while the new rules require only that it
be indented four spaces from the beginning of the first non-space
text after the list marker (here, `a`).

This change was motivated by a slew of bug reports from people
who expected lists to work differently (#3125, #2367, #2575, #2210,
 #1990, #1137, #744, #172, #137, #128) and by the growing prevalance
of CommonMark (now used by GitHub, for example).

Users who want to use the old rules can select the `four_space_rule`
extension.

* Added `four_space_rule` extension.
* Added `Ext_four_space_rule` to `Extensions`.
* `Parsing` now exports `gobbleAtMostSpaces`, and the type
  of `gobbleSpaces` has been changed so that a `ReaderOptions`
  parameter is not needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants