Fix footnote ordering and some other bugs
This commit is contained in:
parent
b1f9bfc9e9
commit
d5bf4317b2
7 changed files with 105 additions and 28 deletions
|
@ -7,8 +7,8 @@ import (
|
|||
type Footnotes struct {
|
||||
ExcludeHeading bool
|
||||
Title string
|
||||
Definitions map[string]FootnoteDefinition
|
||||
Order []string
|
||||
Definitions map[string]*FootnoteDefinition
|
||||
addOrder []string
|
||||
}
|
||||
|
||||
type FootnoteDefinition struct {
|
||||
|
@ -34,6 +34,29 @@ func (d *Document) parseFootnoteDefinition(i int, parentStop stopFn) (int, Node)
|
|||
d.tokens[i].kind == "headline" || d.tokens[i].kind == "footnoteDefinition"
|
||||
}
|
||||
consumed, nodes := d.parseMany(i, stop)
|
||||
d.Footnotes.Definitions[name] = FootnoteDefinition{name, nodes, false}
|
||||
d.Footnotes.add(name, &FootnoteDefinition{name, nodes, false})
|
||||
return consumed, nil
|
||||
}
|
||||
|
||||
func (fs *Footnotes) add(name string, definition *FootnoteDefinition) {
|
||||
if definition != nil {
|
||||
fs.Definitions[name] = definition
|
||||
}
|
||||
fs.addOrder = append(fs.addOrder, name)
|
||||
}
|
||||
|
||||
func (fs *Footnotes) Ordered() []FootnoteDefinition {
|
||||
m := map[string]bool{}
|
||||
definitions, inlineDefinitions := []FootnoteDefinition{}, []FootnoteDefinition{}
|
||||
for _, name := range fs.addOrder {
|
||||
if isDuplicate := m[name]; !isDuplicate {
|
||||
m[name] = true
|
||||
if definition := *fs.Definitions[name]; definition.Inline {
|
||||
inlineDefinitions = append(inlineDefinitions, definition)
|
||||
} else {
|
||||
definitions = append(definitions, definition)
|
||||
}
|
||||
}
|
||||
}
|
||||
return append(definitions, inlineDefinitions...)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue