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

Fixed lists in blockquotes #179

Merged
merged 1 commit into from
Mar 29, 2022
Merged

Conversation

jecneps
Copy link
Contributor

@jecneps jecneps commented Mar 29, 2022

I found this problem when I tried to parse a list inside of a blockquote:
"> * a\n> * b" gets parsed to "<blockquote><p><ul><li>a<ul><li>b</li></ul></li></ul></p></blockquote>" (the second bullet is incorrectly nested an extra level).

The problem was not with lists inside blockquotes exactly. The previous implementation relied on the first indent in lists never having white-space between it and the blockquote character. The markdown editor I used (typora) always includes a whitespace between the ">" and the "*" characters (which is not unusual behavior for markdown editors). The problem persists without the blockquote character:
" * a\n * b" gets parsed to "<ul><li>a<ul><li>b</li></ul></li></ul>"

I believe this is undesired behavior because several other markdown parsers I've found (including the on I'm writing this PR in) all parse "* a\n* b" (0-spaces), " * a\n * b" (1-space), and " * a\n * b" (2-spaces) into "<ul><li>a</li><li>b</li></ul>". Plus it just makes sense.

This bug is a result of trimming the first lines of lists. The first line, because it's trimmed of its white-space, is read has having an indent of zero and the second line an indent of 1, so the parser sees this as a further indentation when really we want both lines to be at the same level of nesting. The code is already written such that nothing actually conditions on the first indentation level of a list being denoted as 0, so by simply not trimming the first line in a list we can have the desired behavior.

The test case I changed was failing because the parser registered starting at 1 space, then unindenting to 0 spaces, but the transformer state had nothing in :lists and there was a null pointer error. This seems like an error with the test case that was only revealed upon fixing the indenting bug.

…hould be valid markdown) and fixed one test case that was actually an error in light of this change
@yogthos yogthos merged commit fdeb5a6 into yogthos:master Mar 29, 2022
@yogthos
Copy link
Owner

yogthos commented Mar 29, 2022

Thanks, that's a good catch. Just pushed out 1.11.0 with the fix.

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

Successfully merging this pull request may close these issues.

None yet

2 participants