Add support for anonymous footnote definitions

This commit is contained in:
Niklas Fasching 2019-07-07 10:00:55 +02:00
parent 6dc04b4b02
commit a7563ce461
4 changed files with 23 additions and 5 deletions

View file

@ -49,7 +49,7 @@ var videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`)
var subScriptSuperScriptRegexp = regexp.MustCompile(`^([_^]){([^{}]+?)}`)
var timestampRegexp = regexp.MustCompile(`^<(\d{4}-\d{2}-\d{2})( [A-Za-z]+)?( \d{2}:\d{2})?( \+\d+[dwmy])?>`)
var footnoteRegexp = regexp.MustCompile(`^\[fn:([\w-]+?)(:(.*?))?\]`)
var footnoteRegexp = regexp.MustCompile(`^\[fn:([\w-]*?)(:(.*?))?\]`)
var statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`)
var timestampFormat = "2006-01-02 Mon 15:04"
@ -168,6 +168,9 @@ func (d *Document) parseOpeningBracket(input string, start int) (int, Node) {
func (d *Document) parseFootnoteReference(input string, start int) (int, Node) {
if m := footnoteRegexp.FindStringSubmatch(input[start:]); m != nil {
name, definition := m[1], m[3]
if name == "" && definition == "" {
return 0, nil
}
link := FootnoteLink{name, nil}
if definition != "" {
link.Definition = &FootnoteDefinition{name, []Node{Paragraph{d.parseInline(definition)}}, true}

View file

@ -27,8 +27,13 @@ inline footnotes are also supported via <sup class="footnote-reference"><a id="f
</li>
<li>
<p>
anonymous inline footnotes are also supported via <sup class="footnote-reference"><a id="footnote-reference-3" href="#footnote-3">3</a></sup>.
</p>
</li>
<li>
<p>
Footnote definitions are not printed where they appear.
Rather, they are gathered and exported at the end of the document in the footnote section. <sup class="footnote-reference"><a id="footnote-reference-3" href="#footnote-3">3</a></sup>
Rather, they are gathered and exported at the end of the document in the footnote section. <sup class="footnote-reference"><a id="footnote-reference-4" href="#footnote-4">4</a></sup>
</p>
</li>
</ul>
@ -36,10 +41,10 @@ Rather, they are gathered and exported at the end of the document in the footnot
Footnotes
</h1>
<p>
Please note that the footnotes section is not automatically excluded from the export like in emacs. <sup class="footnote-reference"><a id="footnote-reference-4" href="#footnote-4">4</a></sup>
Please note that the footnotes section is not automatically excluded from the export like in emacs. <sup class="footnote-reference"><a id="footnote-reference-5" href="#footnote-5">5</a></sup>
</p>
<p>
this is not part of <sup class="footnote-reference"><a id="footnote-reference-4" href="#footnote-4">4</a></sup> anymore as there are 2 blank lines in between!
this is not part of <sup class="footnote-reference"><a id="footnote-reference-5" href="#footnote-5">5</a></sup> anymore as there are 2 blank lines in between!
</p>
<div class="footnotes">
<hr class="footnotes-separatator">
@ -118,13 +123,21 @@ the inline footnote definition
<sup id="footnote-3"><a href="#footnote-reference-3">3</a></sup>
<div class="footnote-body">
<p>
the anonymous inline footnote definition
</p>
</div>
</div>
<div class="footnote-definition">
<sup id="footnote-4"><a href="#footnote-reference-4">4</a></sup>
<div class="footnote-body">
<p>
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.
</p>
</div>
</div>
<div class="footnote-definition">
<sup id="footnote-4"><a href="#footnote-reference-4">4</a></sup>
<sup id="footnote-5"><a href="#footnote-reference-5">5</a></sup>
<div class="footnote-body">
<p>
There&#39;s multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently

View file

@ -2,6 +2,7 @@
- normal footnote reference [fn:1] [fn:6]
- further references to the same footnote should not [fn:1] render duplicates in the footnote list
- inline footnotes are also supported via [fn:2:the inline footnote definition].
- anonymous inline footnotes are also supported via [fn::the anonymous inline footnote definition].
- Footnote definitions are not printed where they appear.
Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4]

View file

@ -2,6 +2,7 @@
- normal footnote reference [fn:1] [fn:6]
- further references to the same footnote should not [fn:1] render duplicates in the footnote list
- inline footnotes are also supported via [fn:2:the inline footnote definition].
- anonymous inline footnotes are also supported via [fn::the anonymous inline footnote definition].
- Footnote definitions are not printed where they appear.
Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4]