diff --git a/org/document.go b/org/document.go index 8fdfc1c..6fa8530 100644 --- a/org/document.go +++ b/org/document.go @@ -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) diff --git a/org/footnote.go b/org/footnote.go index 628452c..660e244 100644 --- a/org/footnote.go +++ b/org/footnote.go @@ -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) } diff --git a/org/html_writer.go b/org/html_writer.go index 4e38274..33f3acc 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -19,6 +19,12 @@ type HTMLWriter struct { HighlightCodeBlock func(source, lang string) string htmlEscape bool log *log.Logger + footnotes footnotes +} + +type footnotes struct { + mapping map[string]int + list []*FootnoteDefinition } var emphasisTags = map[string][]string{ @@ -55,6 +61,9 @@ func NewHTMLWriter() *HTMLWriter { HighlightCodeBlock: func(source, lang string) string { return fmt.Sprintf("%s\n
\n%s\n\n", `
-normal footnote reference 1 6 +normal footnote reference 0 1
-further references to the same footnote should not 1 render duplicates in the footnote list +further references to the same footnote should not 0 render duplicates in the footnote list
-Please note that the footnotes section is not automatically excluded from the export like in emacs. 7 +Please note that the footnotes section is not automatically excluded from the export like in emacs. 4
-this is not part of 7 anymore as there are 2 blank lines in between! +this is not part of 4 anymore as there are 2 blank lines in between!
-so this definition will not be at the end of this section in the exported document. -Rather, it will be somewhere down below in the footnotes section. -
-
-another unused footnote (this definition overwrites the previous definition of fn:5
)
-
Footnotes break after two consecutive empty lines - just like paragraphs - see https://orgmode.org/worg/dev/org-syntax.html. @@ -132,15 +107,6 @@ This shouldn't happen when the definition line and the line after that are e
-There's multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently -hides content before and after the footnotes. -
-@@ -148,5 +114,23 @@ the inline footnote definition
+so this definition will not be at the end of this section in the exported document. +Rather, it will be somewhere down below in the footnotes section. +
++There's multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently +hides content before and after the footnotes. +
+-footnotes can contain markup - and other elements and stuff 2 +footnotes can contain markup - and other elements and stuff 0 1
that also goes for inline footnote definitions
diff --git a/org/testdata/misc.org b/org/testdata/misc.org
index 9615290..864618d 100644
--- a/org/testdata/misc.org
+++ b/org/testdata/misc.org
@@ -108,7 +108,7 @@ also, consecutive dashes inside
: --, ---
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/87][#87]]: Markup in footnotes is rendered literally
-footnotes can contain *markup* - and other elements and stuff [fn:2:that also goes for *inline* footnote /definitions/]
+footnotes can contain *markup* - and other elements and stuff [fn:1] [fn:2:that also goes for *inline* footnote /definitions/]
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/92][#92]]: src blocks only render in caps
The behaviour of Org mode =