github / cmark-gfm

GitHub's fork of cmark, a CommonMark parsing and rendering library and program in C
Other
909 stars 175 forks source link

XML: add NODE_FOOTNOTE type strings and footnote emitters #362

Open zkamvar opened 8 months ago

zkamvar commented 8 months ago

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 commented 7 months ago

Pinging this again to see if there are any maintainers who can review this.

zkamvar commented 6 months ago

Bumping this again to see if I can get a review.

yoonghm commented 2 months ago

@zkamvar, how did you execute cmark-gfm to generate the html in your comment above?

I guess you use cmark-fsm <input_file> --extension footnotes