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 are not handled properly #6

Open
z0u opened this issue Jul 21, 2016 · 6 comments
Open

Nested lists are not handled properly #6

z0u opened this issue Jul 21, 2016 · 6 comments

Comments

@z0u
Copy link

z0u commented Jul 21, 2016

Using domador and megamark, a transform from Markdown -> HTML -> Markdown -> HTML fails to preserve nested lists.

Transform to HTML (correct):

megamark(
    "1. Item 1\n" +
    "2. Item 2\n" +
    "    1. Item 2.1\n" +
    "    2. Item 2.2\n" +
    "3. Item 3\n"
)
  1. Item 1
  2. Item 2
    1. Item 2.1
    2. Item 2.2
  3. Item 3

Transform back to Markdown:

domador(megamark(
    "1. Item 1\n" +
    "2. Item 2\n" +
    "    1. Item 2.1\n" +
    "    2. Item 2.2\n" +
    "3. Item 3\n"
))
1. Item 1
2. Item 2
  1. Item 2.1
  2. Item 2.2
3. Item 3

Transform back to HTML (error):

megamark(domador(megamark(
    "1. Item 1\n" +
    "2. Item 2\n" +
    "    1. Item 2.1\n" +
    "    2. Item 2.2\n" +
    "3. Item 3\n"
)))
  1. Item 1
  2. Item 2
  3. Item 2.1
  4. Item 2.2
  5. Item 3

I'm not sure if this is a bug in domador or megamark, but I think either:

  • megamark should use two spaces to identify nested lists, like GFM, or
  • domador should use four spaces to nest lists, like SO.
@z0u
Copy link
Author

z0u commented Jul 21, 2016

Another use case is a paragraph in a nested list:

Transform to HTML (correct):

megamark(
    "1. Foo 1\n" +
    "1. Foo 2\n" +
    "    1. Bar 1\n" +
    "\n" +
    "       Bar 1 (continued)\n" +
    "    1. Bar 2\n" +
    "1. Foo 3\n"
)
  1. Foo 1
  2. Foo 2
    1. Bar 1

      Bar 1 (continued)

    2. Bar 2

  3. Foo 3

Transform to Markdown and HTML again (error):

megamark(domador(megamark(
    "1. Foo 1\n" +
    "1. Foo 2\n" +
    "    1. Bar 1\n" +
    "\n" +
    "       Bar 1 (continued)\n" +
    "    1. Bar 2\n" +
    "1. Foo 3\n"
)))
  1. Foo 1
  2. Foo 2

Bar 1

Bar 1 (continued)

  1. Bar 2
  2. Foo 3

@bevacqua
Copy link
Owner

Could you PR a fix for this?

@z0u
Copy link
Author

z0u commented Jul 22, 2016

Sadly probably not; I don't think I'll have time in this project.

@bevacqua
Copy link
Owner

bevacqua commented Aug 1, 2016

@jywarren Maybe you could look into this one? 🎉

@jywarren
Copy link
Collaborator

jywarren commented Aug 1, 2016

I think it'll be pretty similar to #8, but I need to spend time on the issues in bevacqua/banksy#5, which are high priority for my own project.

For this, it could be similar to the nesting-in-tables code in #8, using an inUl or inList property.

@philayres
Copy link

philayres commented Jun 28, 2022

I needed to handle this myself to cater for 3 spaces for ordered lists. I put together a quick fix, to allow a configurable number of spaces for ordered and unordered lists.

This allows megamark to nest ordered lists, where the number of padding spaces must align with the first non-space character in the parent. This change doesn't handle actual detection of the number of spaces required, but does make it work with short lists - allowing me to specify 3 spaces as an option is good enough.

I'll submit the PR, in case it is useful to anybody else.

#11

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

4 participants