cmark-gfm icon indicating copy to clipboard operation
cmark-gfm copied to clipboard

XML: add NODE_FOOTNOTE type strings and footnote emitters

Open zkamvar opened this issue 3 months ago • 1 comments

I believe this will begin to address the issues in https://github.com/github/cmark-gfm/issues/341 and https://github.com/github/cmark-gfm/issues/316.

(Update 2023-04-17: I added id and destination attributes to these nodes based on what I saw in the html writer)

I have run make test and everything passes for me. I have additionally tested this on a minimal document:

---
title: "footnote"
---

let's insert a footnote[^1] and a duplicate[^1] another one[^foot]

[^1]: first footnote with a number

[^foot]: second footnote with a label
    
    and

    a linebreak.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
  <thematic_break />
  <heading level="2">
    <text xml:space="preserve">title: &quot;footnote&quot;</text>
  </heading>
  <paragraph>
    <text xml:space="preserve">let's insert a footnote</text>
    <fnref id="fnref-1" destination="fn-1" />
    <text xml:space="preserve"> and a duplicate</text>
    <fnref id="fnref-1-2" destination="fn-1" />
    <text xml:space="preserve"> another one</text>
    <fnref id="fnref-foot" destination="fn-foot" />
  </paragraph>
  <fn id="fn-1">
    <paragraph>
      <text xml:space="preserve">first footnote with a number</text>
    </paragraph>
  </fn>
  <fn id="fn-foot">
    <paragraph>
      <text xml:space="preserve">second footnote with a label</text>
    </paragraph>
    <paragraph>
      <text xml:space="preserve">and</text>
    </paragraph>
    <paragraph>
      <text xml:space="preserve">a linebreak.</text>
    </paragraph>
  </fn>
</document>

I was not sure of what type labels to give the nodes, so I named them fnref and fn for the reference and the definition, respectively. If there is a more relevant precedent, then let's go for that.

zkamvar avatar Apr 05 '24 17:04 zkamvar