FootnoteBackLink.Ref

Part of #92
This commit is contained in:
Tommi Virtanen 2020-01-15 18:46:27 -07:00
parent fbd164be52
commit 70ad9d5b30
2 changed files with 7 additions and 4 deletions

View file

@ -41,6 +41,7 @@ func NewFootnoteLink(index int, ref []byte) *FootnoteLink {
type FootnoteBackLink struct {
gast.BaseInline
Index int
Ref []byte
}
// Dump implements Node.Dump.
@ -59,9 +60,10 @@ func (n *FootnoteBackLink) Kind() gast.NodeKind {
}
// NewFootnoteBackLink returns a new FootnoteBackLink node.
func NewFootnoteBackLink(index int) *FootnoteBackLink {
func NewFootnoteBackLink(index int, ref []byte) *FootnoteBackLink {
return &FootnoteBackLink{
Index: index,
Ref: ref,
}
}

View file

@ -194,11 +194,12 @@ func (a *footnoteASTTransformer) Transform(node *gast.Document, reader text.Read
if fc := container.LastChild(); fc != nil && gast.IsParagraph(fc) {
container = fc
}
index := footnote.(*ast.Footnote).Index
if index < 0 {
n := footnote.(*ast.Footnote)
if n.Index < 0 {
list.RemoveChild(list, footnote)
} else {
container.AppendChild(container, ast.NewFootnoteBackLink(index))
backlink := ast.NewFootnoteBackLink(n.Index, n.Ref)
container.AppendChild(container, backlink)
}
footnote = next
}