goldmark
goldmark copied to clipboard
Footnote in a footnote appears before other footnotes
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.
- [X] Extensions(Autolink without
- [ ] 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:
- What version of goldmark are you using? : goldmark:
v1.5.4
, https://github.com/kpym/gm:v0.11.4
- What version of Go are you using? :
go version go1.21.0 linux/amd64
- What operating system and processor architecture are you using? :
linux/amd64
- What did you do? :
gm test.md
Wheretest.md
contains:
before[^before]
[^before]: before
parent[^parent]
[^parent]: parent[^child]
[^child]: child
after[^after]
[^after]: after
- 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
- What did you see instead? :
The order the footnotes appear in
index.html
is the following:
1. before
2. child
3. parent
4. after
- Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: Yes, see above.
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.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Ping