GitLab Flavored Markdown removes footnotes metadata when rendering footnotes
The GitLab Markdown API outputs HTML that is different from gitlab-cmark and commonmarker’s C renderer. If I define a footnote symbol, for example footnote-42
, cmark-github and commonmarker retain footnote-42
when rendering footnotes in the reference it, but GFM loses it.
Why is this happening
We use Commonmarker’s HTML renderer in GFM which renders footnotes differently from the C renderer.
Why is this important
This problem is important for the Editor group because preserving the footnotes’ metadata allows us generate Markdown that retains the users’ preference.
How to reproduce the bug?
I will demonstrate this bug by rendering the following Markdown snippet in the three rendering engines:
[^1]
[^footnote-42]
[^1]: This is the text inside a footnote.
[^footnote-42]: This is another footnote.
GFM output
<p data-sourcepos="1:1-1:46" dir="auto"><sup class="footnote-ref"><a href="#fn1-2177" id="fnref1-2177">1</a></sup></p>
<p data-sourcepos="3:1-3:66" dir="auto"><sup class="footnote-ref"><a href="#fn2-2177" id="fnref2-2177">2</a></sup></p>
<section class="footnotes">
<ol>
<li id="fn1-2177">
<p data-sourcepos="5:7-5:41">
This is the text inside a footnote.
<a href="#fnref1-2177" class="footnote-backref">
<gl-emoji title="leftwards arrow with hook" data-name="leftwards_arrow_with_hook" data-unicode-version="1.1">↩</gl-emoji>
</a>
</p>
</li>
<li id="fn2-2177">
<p data-sourcepos="7:17-7:41">
This is another footnote.
<a href="#fnref2-2177" class="footnote-backref">
<gl-emoji title="leftwards arrow with hook" data-name="leftwards_arrow_with_hook" data-unicode-version="1.1">↩</gl-emoji>
</a>
</p>
</li>
</ol>
</section>
Commonmarker
bundle exec commonmarker --parse-option=FOOTNOTES --render-option=SOURCEPOS footnotes.md
<p data-sourcepos="1:1-1:46"><sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup></p>
<p data-sourcepos="3:1-3:66"><sup class="footnote-ref"><a href="#fn-footnote-42" id="fnref-footnote-42" data-footnote-ref>2</a></sup></p>
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-1">
<p data-sourcepos="5:7-5:41">This is the text inside a footnote. <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
</li>
<li id="fn-footnote-42">
<p data-sourcepos="7:17-7:41">This is another footnote. <a href="#fnref-footnote-42" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
</li>
</ol>
</section>
CMark GFM
cmark-gfm --sourcepos -e footnotes footnotes.md
<p data-sourcepos="1:1-1:46"><sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup></p>
<p data-sourcepos="3:1-3:66"><sup class="footnote-ref"><a href="#fn-footnote-42" id="fnref-footnote-42" data-footnote-ref>2</a></sup></p>
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-1">
<p data-sourcepos="5:7-5:41">This is the text inside a footnote. <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
</li>
<li id="fn-footnote-42">
<p data-sourcepos="7:17-7:41">This is another footnote. <a href="#fnref-footnote-42" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
</li>
</ol>
</section>