FootnoteLink.Ref

Part of #92
This commit is contained in:
Tommi Virtanen 2020-01-15 18:45:18 -07:00
parent faaafa55b6
commit fbd164be52
2 changed files with 6 additions and 2 deletions

View file

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

View file

@ -149,6 +149,7 @@ func (s *footnoteParser) Parse(parent gast.Node, block text.Reader, pc parser.Co
return nil return nil
} }
index := 0 index := 0
var ref []byte
for def := list.FirstChild(); def != nil; def = def.NextSibling() { for def := list.FirstChild(); def != nil; def = def.NextSibling() {
d := def.(*ast.Footnote) d := def.(*ast.Footnote)
if bytes.Equal(d.Ref, value) { if bytes.Equal(d.Ref, value) {
@ -157,6 +158,7 @@ func (s *footnoteParser) Parse(parent gast.Node, block text.Reader, pc parser.Co
d.Index = list.Count d.Index = list.Count
} }
index = d.Index index = d.Index
ref = d.Ref
break break
} }
} }
@ -164,7 +166,7 @@ func (s *footnoteParser) Parse(parent gast.Node, block text.Reader, pc parser.Co
return nil return nil
} }
return ast.NewFootnoteLink(index) return ast.NewFootnoteLink(index, ref)
} }
type footnoteASTTransformer struct { type footnoteASTTransformer struct {