miyuchina / mistletoe

A fast, extensible and spec-compliant Markdown parser in pure Python.
MIT License
811 stars 113 forks source link

Fix for #108, CommonMark 0.30 spec compliance, part 2 #165

Closed anderskaplan closed 1 year ago

anderskaplan commented 1 year ago

A set of small fixes which improve the CommonMark spec compliance. See the commit messages for details.

pbodnar commented 1 year ago

Great, thank you for another contribution. :)

So it looks like, because spec examples 312 and 313 are already fixed in master now, there will be just 1 failing example left after the fixes provided in here, namely:

$ py -m test.specification
example:  146
markdown: '~~~ aa ``` ~~~\nfoo\n~~~\n'
html:     '<pre><code class="language-aa">foo\n</code></pre>\n'
output:   '<p><del>~ aa ``` </del>~\nfoo</p>\n<pre><code></code></pre>\n'

... the last challenge. ;)

anderskaplan commented 1 year ago

Yes, at first I thought it was caused by the strikethrough token, but that can't be. Because the code fences should already be parsed on block level before the strikethrough can kick in on span level.

pbodnar commented 1 year ago

Yes, at first I thought it was caused by the strikethrough token, but that can't be. Because the code fences should already be parsed on block level before the strikethrough can kick in on span level.

Yeah, it looks like mistletoe cannot handle the following correctly (stated above the failing Example 146):

Info strings for tilde code blocks can contain backticks and tildes...

So I believe this condition is the culprit of mistletoe's failure:

        if leader[0] in lang or leader[0] in line[match_obj.end():]:
            return False

I.e. https://github.com/miyuchina/mistletoe/blob/v0.9.0/mistletoe/block_token.py#L430.

anderskaplan commented 1 year ago

hey @pbodnar thanks for the review! I'll try and find some time to update the tests during next week.

anderskaplan commented 1 year ago

all done! the last failing test case will be in a PR of its own.

anderskaplan commented 1 year ago

Updated the commit messages and squashed the unit test updates according to review comments. Should be good to go now!

pbodnar commented 1 year ago
2. I would just ... and add ` (#108)` to the end of the summary line.

(note: after looking in the commits history, I have added parentheses around the number)

@anderskaplan, maybe you have overlooked this part (which groups the commits together)? Apart from that, the commits seem perfect now. :)

pbodnar commented 1 year ago

Thank you!