Add lossless inline-definition-footnote rendering for the OrgWriter

This commit is contained in:
Niklas Fasching 2018-12-02 17:24:10 +01:00
parent fc982125c9
commit a570fc736f
6 changed files with 49 additions and 29 deletions

View file

@ -15,7 +15,10 @@ type Emphasis struct {
Content []Node
}
type FootnoteLink struct{ Name string }
type FootnoteLink struct {
Name string
Definition *FootnoteDefinition
}
type RegularLink struct {
Protocol string
@ -104,7 +107,7 @@ func (d *Document) parseRegularLinkOrFootnoteReference(input string, start int)
func (d *Document) parseFootnoteReference(input string, start int) (int, Node) {
if m := footnoteRegexp.FindStringSubmatch(input[start:]); m != nil {
name, definition := m[1], m[3]
seen := false
seen, link := false, FootnoteLink{name, nil}
for _, otherName := range d.Footnotes.Order {
if name == otherName {
seen = true
@ -114,9 +117,10 @@ func (d *Document) parseFootnoteReference(input string, start int) (int, Node) {
d.Footnotes.Order = append(d.Footnotes.Order, name)
}
if definition != "" {
d.Footnotes.Definitions[name] = FootnoteDefinition{name, d.parseInline(definition)}
link.Definition = &FootnoteDefinition{name, d.parseInline(definition), true}
d.Footnotes.Definitions[name] = *link.Definition
}
return len(m[0]), FootnoteLink{name}
return len(m[0]), link
}
return 0, nil
}