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

Fix HTML fenced code siblings management #10

Merged
merged 3 commits into from
Aug 1, 2024

Conversation

xavierlacot
Copy link
Member

Because the commonmark HTML parsing algorithm is what it is, some cases can produce a strange AST.

For example,

<p>Intro</p>
<pre><code>Multiline

code
</code></pre>

will be parsed as:

<document xmlns="http://commonmark.org/xml/1.0">
  <html_block>&lt;p&gt;Intro&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Multiline</html_block>
  <paragraph>
    <text>code</text>
    <softbreak />
    <html_inline>&lt;/code&gt;</html_inline>
    <html_inline>&lt;/pre&gt;</html_inline>
  </paragraph>
</document>

while (note the extra line between the first two HTML nodes)

<p>Intro</p>

<pre><code>Multiline

code
</code></pre>

will be parsed as:

<document xmlns="http://commonmark.org/xml/1.0">
  <html_block>&lt;p&gt;Intro&lt;/p&gt;</html_block>
  <html_block>&lt;pre&gt;&lt;code&gt;Multiline

code
&lt;/code&gt;&lt;/pre&gt;</html_block>
</document>

This is perfectly in line with the specs of Commonmark, but was leading to situations where the HtmlBlockFixer could not correctly transform the input HTML into markdown and was generating errors. This PR fixes such a behavior.

@xavierlacot xavierlacot added the bug Something isn't working label Aug 1, 2024
@xavierlacot xavierlacot merged commit 4fa0006 into main Aug 1, 2024
4 checks passed
@xavierlacot xavierlacot deleted the fix/html-siblings-fenced-code branch August 1, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant