gjtorikian / commonmarker

Ruby wrapper for the comrak (CommonMark parser) Rust crate
MIT License
416 stars 80 forks source link

Code block incorrectly parsed in commonmarker 1.0.0.pre #202

Closed andreas12345 closed 1 year ago

andreas12345 commented 1 year ago

Hi,

I noticed that code blocks are sometimes not parsed correctly in commonmarker (1.0.0.pre arm64-darwin):

irb(main):011:0> s = "\n```\n\nx\n\n```\n"
=> "\n```\n\nx\n\n```\n"
irb(main):012:0> print(s)

x

=> nil                                                        
irb(main):013:0> Commonmarker.to_html(s)
=> "<p>x</p>\n<pre><code></code></pre>\n"

The "x" is not inside the generated code & pre tags.

Here is what Comrak CLI 0.15.0 returns for the same piece of Markdown code:

<pre style="background-color:#2b303b;"><code>
<span style="color:#c0c5ce;">                                                              
</span><span style="color:#c0c5ce;">x                                                             
</span><span style="color:#c0c5ce;">                                                              
</span>
</code></pre>

Thanks, Andreas

kivikakk commented 1 year ago

Thanks for the report. It looks like the default front-matter delimiter is "", rather than unspecified, meaning the first line is getting eaten as frontmatter. The comrak execution that produces similar output is:

$ printf "\n```\n\nx\n\n```\n" | comrak --front-matter-delimiter ''
<p>x</p>
<pre style="background-color:#2b303b;"><code>

</code></pre>
gjtorikian commented 1 year ago

Thanks for reporting this! I was able to also tighten up the string parsing in general. 1.0.0.pre.2 will be released soon.