bent10 / marked-extensions

Marked extensions workspace
https://www.npmjs.com/search?q=keywords:stilearning-marked-extensions
MIT License
33 stars 6 forks source link

Footnote numbering increments every time the same string is parsed, instead of resetting #28

Closed zakkor closed 11 months ago

zakkor commented 11 months ago

Description

Parsing markdown with footnotes output is non-idempotent, see reproduction for example.

To Reproduce (⚠️ read below)

Expected Behavior

    const str = `Here's a simple footnote,[^1] thanks.

[^1]: This is the first footnote.`;
    let rendered = marked.parse(str);
    console.log(`rendered:`, rendered);
    // Output:
<p>Here&#39;s a simple footnote,<sup><a id=\"footnote-ref-1\" href=\"#footnote-1\" data-footnote-ref aria-describedby=\"footnote-label\">[1]</a></sup> thanks.</p>
<section class=\"footnotes\" data-footnotes>
<h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2>
<ol>
<li id=\"footnote-1\">
<p>This is the first footnote. <a href=\"#footnote-ref-1\" data-footnote-backref aria-label=\"Back to reference 1\">↩</a></p>
</li>
</ol>
</section>

    rendered = marked.parse(str);
    console.log(`rendered:`, rendered);
    // Output:
    <p>Here&#39;s a simple footnote,<sup><a id=\"footnote-ref-1\" href=\"#footnote-1\" data-footnote-ref aria-describedby=\"footnote-label\">[2]</a></sup> thanks.</p>
<section class=\"footnotes\" data-footnotes>
<h2 id=\"footnote-label\" class=\"sr-only\">Footnotes</h2>
<ol>
<li id=\"footnote-1\">
<p>This is the first footnote. <a href=\"#footnote-ref-1\" data-footnote-backref aria-label=\"Back to reference 1\">↩</a></p>
</li>
</ol>
</section>

The second time the same string is parsed, the superscript is now [2], instead of [1], even though the other reference IDs correctly have it as [1].

Actual Behavior

Superscript is [2]

Additional Information

bent10 commented 11 months ago

The issue has been resolved in v1.2.1. Thanks for reporting it!