goldmark icon indicating copy to clipboard operation
goldmark copied to clipboard

Footnote in a footnote appears before other footnotes

Open kuruczgy opened this issue 1 year ago • 6 comments

goldmark has https://github.com/yuin/goldmark/discussions in github. You should post only issues here. Feature requests and questions should be posted at discussions.

  • [ ] goldmark is fully compliant with the CommonMark. Before submitting issue, you must read CommonMark spec and confirm your output is different from CommonMark online demo.
    • [X] Extensions(Autolink without < >, Table, etc) are not part of CommonMark spec. You should confirm your output is different from other official renderers correspond with an extension.
  • [ ] goldmark is not dedicated for Hugo. If you are Hugo user and your issue was raised by your experience in Hugo, you should consider create issue at Hugo repository at first .

Please answer the following before submitting your issue:

  1. What version of goldmark are you using? : goldmark: v1.5.4, https://github.com/kpym/gm: v0.11.4
  2. What version of Go are you using? : go version go1.21.0 linux/amd64
  3. What operating system and processor architecture are you using? : linux/amd64
  4. What did you do? : gm test.md Where test.md contains:
before[^before]

[^before]: before

parent[^parent]

[^parent]: parent[^child]

[^child]: child

after[^after]

[^after]: after

  1. What did you expect to see? : Using https://michelf.ca/projects/php-markdown/dingus/, the order of the footnotes is:
1. before
2. parent
3. after
4. child
  1. What did you see instead? : The order the footnotes appear in index.html is the following:
1. before
2. child
3. parent
4. after
  1. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: Yes, see above.

kuruczgy avatar Aug 23 '23 00:08 kuruczgy

Workaround for anyone finding this issue:

diff --git a/extension/footnote.go b/extension/footnote.go
index d1b67aa..b856d92 100644
--- a/extension/footnote.go
+++ b/extension/footnote.go
@@ -91,8 +91,8 @@ func (b *footnoteBlockParser) Close(node gast.Node, reader text.Reader, pc parse
 	} else {
 		list = ast.NewFootnoteList()
 		pc.Set(footnoteListKey, list)
-		node.Parent().InsertBefore(node.Parent(), node, list)
 	}
+	node.Parent().InsertBefore(node.Parent(), node, list)
 	node.Parent().RemoveChild(node.Parent(), node)
 	list.AppendChild(list, node)
 }

This solution seems kind of janky to me though, so I didn't want to submit it as a PR without prior discussion.

Also, the ideal order IMO would be before parent child after (which is what GitHub seems to do), but achieving that probably requires some additional logic.

kuruczgy avatar Aug 23 '23 00:08 kuruczgy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 22 '23 09:09 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Oct 06 '23 09:10 github-actions[bot]

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Nov 09 '23 09:11 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Nov 23 '23 09:11 github-actions[bot]

Ping

mwat56 avatar Mar 15 '24 18:03 mwat56