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:
Niklas Fasching 2019-07-07 09:52:23 +02:00
parent 50395f999a
commit 6dc04b4b02
8 changed files with 69 additions and 100 deletions

View file

@ -35,7 +35,6 @@ type Document struct {
Path string // Path of the file containing the parse input - used to resolve relative paths during parsing (e.g. INCLUDE).
tokens []token
Nodes []Node
Footnotes Footnotes
Outline Outline // Outline is a Table Of Contents for the document and contains all sections (headline + content).
BufferSettings map[string]string // Settings contains all settings that were parsed from keywords.
Error error
@ -113,11 +112,7 @@ func (d *Document) Write(w Writer) (out string, err error) {
func (c *Configuration) Parse(input io.Reader, path string) (d *Document) {
outlineSection := &Section{}
d = &Document{
Configuration: c,
Footnotes: Footnotes{
Title: "Footnotes",
Definitions: map[string]*FootnoteDefinition{},
},
Configuration: c,
Outline: Outline{outlineSection, outlineSection, 0},
BufferSettings: map[string]string{},
Path: path,
@ -243,16 +238,6 @@ func (d *Document) parseMany(i int, stop stopFn) (int, []Node) {
return i - start, nodes
}
func (d *Document) addFootnote(name string, definition *FootnoteDefinition) {
if definition != nil {
if _, exists := d.Footnotes.Definitions[name]; exists {
d.Log.Printf("Footnote [fn:%s] redefined! %#v", name, definition)
}
d.Footnotes.Definitions[name] = definition
}
d.Footnotes.addOrder = append(d.Footnotes.addOrder, name)
}
func (d *Document) addHeadline(headline *Headline) int {
current := &Section{Headline: headline}
d.Outline.last.add(current)