-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Inconsistent parsing of indented bullet lists/unordered lists #107
Comments
Reading about the goals of this markdown package in the readme, I guess we would look at https://github.github.com/gfm/#lists for a specification. Since that is GitHub Flavored Markown, a faster way seems to add that string literally here to see how it renders in the comment: elm-markdown 7.0.0
The rendering in the GitHub issue above looks like there is no difference between using minus and plus character for this list. |
I went searching for a change in the program code that would fix this inconsistency.
|
I found the test modules call them 'unordered lists' (not 'bullet lists'), so maybe the issue title is not ideal yet. 🤔 |
If the indent before the list items is to be discarded, following might be a appropriate implementation for an automated test: , test "basic indented list with '+'" <|
\() ->
String.trimLeft """
+ Item 1
+ Item 2
+ Item 3
"""
|> Markdown.Parser.parse
|> Expect.equal
(Ok
[ UnorderedList Tight
[ ListItem NoTask [ Paragraph [ Text "Item 1" ] ]
, ListItem NoTask [ Paragraph [ Text "Item 2" ] ]
, ListItem NoTask [ Paragraph [ Text "Item 3" ] ]
]
]
) This test yields following output with
|
I don't have a lot of experience with parsing, but rummaging through the parsing code, I stumbled on this function that looks like a good candidate for experimenting with a change: elm-markdown/src/Markdown/UnorderedList.elm Lines 38 to 48 in 1c0ca65
I tried this variant: unorderedListMarkerParser : Parser UnorderedListMarker
unorderedListMarkerParser =
oneOf
[ succeed Minus
|. Extra.upTo 3 Whitespace.space
|. Advanced.symbol (Advanced.Token "-" (Parser.ExpectingSymbol "-"))
, succeed Plus
|. Extra.upTo 3 Whitespace.space
|. Advanced.symbol (Advanced.Token "+" (Parser.ExpectingSymbol "+"))
, succeed Asterisk
|. Extra.upTo 3 Whitespace.space
|. Advanced.symbol (Advanced.Token "*" (Parser.ExpectingSymbol "*"))
] Guess that would have been too easy. I see no change in the test result. My next guess is something else consumes that part with a higher priority. |
Taking a break helped. I found an error in the test code. This one looks better: , test "basic list with '+' indented by 3" <|
\() ->
"""
+ Item 1
+ Item 2
+ Item 3
"""
|> Markdown.Parser.parse
|> Expect.equal
(Ok
[ UnorderedList Tight
[ ListItem NoTask [ Paragraph [ Text "Item 1" ] ]
, ListItem NoTask [ Paragraph [ Text "Item 2" ] ]
, ListItem NoTask [ Paragraph [ Text "Item 3" ] ]
]
]
) |
With more experimenting, I learned that I need to add backtracking here. This variant lets the test pass: unorderedListMarkerParser : Parser UnorderedListMarker
unorderedListMarkerParser =
oneOf
[ backtrackable
(succeed Minus
|. Extra.upTo 3 Whitespace.space
|. Advanced.symbol (Advanced.Token "-" (Parser.ExpectingSymbol "-"))
)
, succeed Plus
|. Extra.upTo 3 Whitespace.space
|. Advanced.symbol (Advanced.Token "+" (Parser.ExpectingSymbol "+"))
, succeed Asterisk
|. Extra.upTo 3 Whitespace.space
|. Advanced.symbol (Advanced.Token "*" (Parser.ExpectingSymbol "*"))
] |
I was surprised by how version
7.0.0
maps this markdown string:Here is a screenshot of parsed and rendered, based on one of the example ellies:
https://ellie-app.com/fnbWFCZhzyTa1
There are three spaces in front of each list item. Is it desirable/intended to have this distinction between minus/plus character?
The text was updated successfully, but these errors were encountered: