-
Notifications
You must be signed in to change notification settings - Fork 62
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
fix: Another attempt fixing nested fenced divs keeping structure #52
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may not need to use the full markdown grammar while looking for the end of a div, but it seems to me that we need to consider at least code fences.
This issue should also close #53 and #54. @Omikhleia, can you please add #52 (comment), #53, #54 to the unit tests, so that we can at least see the extent to which the code is failing at the moment?
I am sorry about that. I should have heeded your concerns. I am way behind on my schedule for the monthly release of witiko/markdown due to the bugged fenced div implementation, but rushing ahead and introducing new bugs to |
d8ff8b1
to
b16842e
Compare
@Omikhleia I added edge cases from #54, #53, and #52 (comment) to the unit tests. CI shows that although this pull request already fixes #54, it currently fails to address the edge cases from #53 and #52 (comment). Will you find the time to tackle this by the end of the month, or should I? |
@Witiko
The first is a "regular" case that works, the second currently breaks.
I won't have the bandwidth to guarantee I can work on it next week (and probably a bit more). Feel free to go ahead. I'll try to follow the PR though, for comments. (And if at some point you want to squash commits, no problem either. A |
Good thinking. I will add the regular case.
Thanks, I did not know that. I will also do that for commits based on your comments. |
See jgm#52 (comment) Co-authored-by: Omikhleia <[email protected]>
I have postponed the 2.19.0 release of witiko/markdown to December 23, so this is less urgent for me. Besides fenced divs, I will also need #43 closed before the release. If you'd like, we can split the effort and I will focus on #43. If you'd like to have a direct channel to discuss the implementation, please feel free to join the witiko/markdown discord server or matrix space. |
3aca81c
to
b23327e
Compare
….fenced_div_end`
6406bdc
to
6a07ddc
Compare
a89be91
to
67b8a56
Compare
67b8a56
to
d247439
Compare
@Omikhleia I am done and would appreciate your review.
This ended up being trickier than I expected. Assume the following input: :::
This is not a div
::: If we add an exception for <p>::: This is not a div</p>
<p>:::</p> Therefore, I ended up keeping the nesting level as a named capture inside the grammar and we only match the exception for lunamark/lunamark/reader/markdown.lua Lines 1715 to 1718 in d247439
lunamark/lunamark/reader/markdown.lua Lines 1322 to 1343 in d247439
lunamark/lunamark/reader/markdown.lua Lines 1124 to 1136 in d247439
This follows a similar trick done by Pandoc. However, I welcome any ideas for simplification. |
One last quibble I have with the current implementation is that a div must end with a blank line, otherwise it will not be placed in a paragraph. Let's take the following example: ::: {.myclass}
Some div
::: Currently, Lunamark will produce the following output: <div class="myclass">Some div</div> Your original solution from this PR called
Regardless of whether this is a feature or a bug, it seems out-of-scope for this PR. |
@Witiko What an amazing work you have done here! I'm sorry I couldn't contribute - Not only did I expect the week to be very busy, but moreover I am sick with my brain at 10% capacity... Just took the time to test you branch on a bunch of small tests I had (mostly redundant with the ones you added, but written a bit differently, so who knows...) = They all went right... There's one case where I didn't get the same result as Pandoc and was a bit astonished at first:
Pandoc gives
Lunamark with your fixes (some line breaks added for easier comparison)
Small discrepancy for a "broken" case - and I am even thinking our output might be more correct maybe. I'll look at code as soon as I can and have the necessary focus^^ |
Definitely looks like a bug. I will test this with up-to-date Pandoc and report it if present.
I am sorry to hear that! Please, take all the time you need. |
@Witiko Trying to check combinations of options --
It does work if the note is on a single line ( |
Doh, it was in front of my eyes: Not sure this is the proper way to handle the situation - Tests pass and I could process a 10-page document using all above extensions enabled, but it might not be general. |
Seems reasonable. We should check that there do not exist other copies of |
Co-Authored-By: Omikhleia <[email protected]>
@Omikhleia I did not find any other problems, but I extracted the state-managing pattern to |
LGTM ! I just successfully tested two cases I had seen where end-of-lines were breaking. The inline notes, as noted above:
but also the indirect links, like the following:
So besides Only remaining item would be |
Erm. Perhaps spoke too soon...
Gives
For some reason the second div is empty. EDIT the first blank line is the issue, not the last. |
Adapted from jgm#52. Co-Authored-By: Omikhleia <[email protected]>
Adapted from jgm#52. Co-Authored-By: Omikhleia <[email protected]>
Adapted from jgm#52. Co-Authored-By: Omikhleia <[email protected]>
Co-authored-by: Omikhleia <[email protected]>
Co-Authored-By: Omikhleia <[email protected]>
The current implementation seems quite robust. Hopefully, we have not overlooked anything major. |
PR #51 (for issue #44) got merged a bit to quickly to my taste. Here is a PR rebased on it, but reverting to the previous writer API and trying to keep the hierarchical structure. It passes the tests for #51. I wish I had more time to check for edge cases, but at least you have it here for scrutiny.