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

Nesting in ordered list #19

Closed
tlienart opened this issue Mar 13, 2021 · 4 comments
Closed

Nesting in ordered list #19

tlienart opened this issue Mar 13, 2021 · 4 comments

Comments

@tlienart
Copy link
Contributor

tlienart commented Mar 13, 2021

Is this meant to be?


julia> a = """
       1. abc
       2. def
         1. ghi
       """
"1. abc\n2. def\n  1. ghi\n"

julia> p(a)
  1. abc
  
  2. def
  
  3. ghi


julia> a = """
       * abc
       * def
         * ghi
       """
"* abc\n* def\n  * ghi\n"

julia> p(a)
  ● abc
  
  ● def
    
     ○ ghi

or must sub-levels be indicated differently for ordered lists?

@MichaelHatherly
Copy link
Owner

Nested lists are tricky syntax, they need the child element markers to be indented in line with the start of the list item's content, i.e

julia> a = """
       1. abc
       2. def
          1. ghi
       """
"1. abc\n2. def\n   1. ghi\n"

julia> p(a)
  1. abc

  2. def

      1. ghi

which is the equivalent to the second, unordered list above.

This is how markdown, commonmark at least, is meant to handle nested lists: see the below babelmark tests:

and the spec for list syntax: https://spec.commonmark.org/0.29/#lists.

https://www.johnmacfarlane.net/beyond-markdown.html is a nice read about the list syntax shortcomings (among other things).

@tlienart
Copy link
Contributor Author

tlienart commented Mar 13, 2021

Ok thanks! So it's a question of number of spaces? (4 in your example instead of 2?) The thing that confuses me is that there's the same number in both cases yet in the second one it picks up the "child" element.

(I see that the common mark editor does exactly the same thing so feel free to close this issue and I can just refer people to it and tell them to use 4 spaces for indentation)

@MichaelHatherly
Copy link
Owner

Ok thanks! So it's a question of number of spaces? (4 in your example instead of 2?) The thing that confuses me is that there's the same number in both cases yet in the second one it picks up the "child" element.

It's not really to do with any particular set number of spaces, it's relative to the lines above. See for example:

julia> cm"""
          100000. one
           1. two
       """ |> CommonMark.ast_dump
Document
  List
    Item
      Paragraph
        Text
          "one"
        SoftBreak
          ""
        Text
          "1"
        Text
          "."
        Text
          " two"

julia> cm"""
          100000. one
                  1. two
       """ |> CommonMark.ast_dump
Document
  List
    Item
      Paragraph
        Text
          "one"
      List
        Item
          Paragraph
            Text
              "two"

Where the first list marker 100000. is much wider than 4 spaces, so any child lists need to start from much further to the right. Once you start putting in weird amounts of indentation the parser consistency drops somewhat: https://babelmark.github.io/?text=+++100000.+one%0A++++1.+two

@tlienart
Copy link
Contributor Author

Ok this makes sense, thanks!

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