Refactor footnote handling
- Remove unused footnote section title option - Move away from maintaining a list of footnotes in the document (only needed for html export, potential maintainance overhead when modifying the document) and rather only build it on export when required. - HTML export: Rename all footnotes to numbers (so we can support anonymous footnote references by assigning them a number) and export footnotes in order of reference, not definition. The implementation of this makes it natural to also stop exporting unused footnote definitions so we do that as well.
This commit is contained in:
parent
50395f999a
commit
6dc04b4b02
8 changed files with 69 additions and 100 deletions
|
@ -4,12 +4,6 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
type Footnotes struct {
|
||||
Title string
|
||||
Definitions map[string]*FootnoteDefinition
|
||||
addOrder []string
|
||||
}
|
||||
|
||||
type FootnoteDefinition struct {
|
||||
Name string
|
||||
Children []Node
|
||||
|
@ -35,24 +29,7 @@ func (d *Document) parseFootnoteDefinition(i int, parentStop stopFn) (int, Node)
|
|||
}
|
||||
consumed, nodes := d.parseMany(i, stop)
|
||||
definition := FootnoteDefinition{name, nodes, false}
|
||||
d.addFootnote(name, &definition)
|
||||
return consumed, definition
|
||||
}
|
||||
|
||||
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...)
|
||||
}
|
||||
|
||||
func (n FootnoteDefinition) String() string { return orgWriter.nodesAsString(n) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue