gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.37k stars 172 forks source link

Fix fenced codeblocks inside lists #231

Closed martincapello closed 2 years ago

martincapello commented 2 years ago

Fixes https://github.com/gomarkdown/markdown/issues/124

There are a couple of tests that start failing when this PR is applied, but I think that actually the expected value must be updated. These are the tests that fails:

TestFootnotes Input:

        Input:
        testing long[^b] notes.

        [^b]: Paragraph 1

                Paragraph 2
            some code
            ```

            Paragraph 3

    No longer in the footnote

Expected: 
```html
        <p>testing long<sup class="footnote-ref" id="fnref:b"><a href="#fn:b">1</a></sup> notes.</p>

        <p>No longer in the footnote</p>

        <div class="footnotes">

        <hr />

        <ol>
        <li id="fn:b"><p>Paragraph 1</p>

        <p>Paragraph 2</p>

        <p><code>
        some code
        </code></p>

        <p>Paragraph 3</p></li>
        </ol>

        </div>

Got:

        <p>testing long<sup class="footnote-ref" id="fnref:b"><a href="#fn:b">1</a></sup> notes.</p>

        <p>No longer in the footnote</p>

        <div class="footnotes">

        <hr />

        <ol>
        <li id="fn:b"><p>Paragraph 1</p>

        <p>Paragraph 2</p>

        <p>
        <pre><code>
        some code
        </code></pre>
        </p>

        <p>Paragraph 3</p></li>
        </ol>

        </div>

TestFootnotesWithParameters Input:

        testing long[^b] notes.

        [^b]: Paragraph 1

                Paragraph 2
            some code
            ```

            Paragraph 3

    No longer in the footnote

Expected:
```html
        <p>testing long<sup class="footnote-ref" id="fnref:testPrefixb"><a href="#fn:testPrefixb">1</a></sup> notes.</p>

        <p>No longer in the footnote</p>

        <div class="footnotes">

        <hr />

        <ol>
        <li id="fn:testPrefixb"><p>Paragraph 1</p>

        <p>Paragraph 2</p>

        <p><code>
        some code
        </code></p>

        <p>Paragraph 3</p> <a class="footnote-return" href="#fnref:testPrefixb">ret</a></li>
        </ol>

        </div>

Got:

        <p>testing long<sup class="footnote-ref" id="fnref:testPrefixb"><a href="#fn:testPrefixb">1</a></sup> notes.</p>

        <p>No longer in the footnote</p>

        <div class="footnotes">

        <hr />

        <ol>
        <li id="fn:testPrefixb"><p>Paragraph 1</p>

        <p>Paragraph 2</p>

        <p>
        <pre><code>
        some code
        </code></pre>
        </p>

        <p>Paragraph 3</p> <a class="footnote-return" href="#fnref:testPrefixb">ret</a></li>
        </ol>

        </div>

If you think the expected value must be fixed, just let me know and I can push a commit with the fix.

kjk commented 2 years ago

The change in test seems reasonable (changing from inline code to code block).

Could you update expected values for those tests as part of this PR?

martincapello commented 2 years ago

Sure, will do it right now

kjk commented 2 years ago

Thanks!