RobertDober / earmark_parser

The Markdown to AST part of Earmark.
Apache License 2.0
68 stars 26 forks source link

When footnote is referenced twice the backlink points to multiple targets #75

Open RobertDober opened 2 years ago

RobertDober commented 2 years ago
hello[^1] world[^1]

[^1]: A common greeting

produces the following

 [
   {"p", [],
    [
      "hello",
      {"a",
       [
         {"href", "#fn:1"},
         {"id", "fnref:1"},
         {"class", "footnote"},
         {"title", "see footnote"}
       ], ["1"], %{}},
      " world",
      {"a",
       [
         {"href", "#fn:1"},
         {"id", "fnref:1"},
         {"class", "footnote"},
         {"title", "see footnote"}
       ], ["1"], %{}}
    ], %{}},
   {"div", [{"class", "footnotes"}],
    [
      {"hr", [], [], %{}},
      {"ol", [],
       [
         {"li", [{"id", "fn:1"}],
          [
            {"a",
             [
               {"class", "reversefootnote"},
               {"href", "#fnref:1"},
               {"title", "return to article"}
             ], ["↩"], %{}},
            {"p", [], ["A common greeting"], %{}}
          ], %{}}
       ], %{}}
    ], %{}}
 ]
RobertDober commented 2 years ago

Fix

we need to number all the fnref:x uniquely and add them as target to the link's definition (then we can add backlinks for all of them)

Implementation Detail

Context.referenced_footnote_ids will change from a MapSet to a Map(footnote_id, list(fnrefs))