Add support for anonymous footnote definitions
This commit is contained in:
parent
6dc04b4b02
commit
a7563ce461
4 changed files with 23 additions and 5 deletions
|
@ -49,7 +49,7 @@ var videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`)
|
||||||
|
|
||||||
var subScriptSuperScriptRegexp = regexp.MustCompile(`^([_^]){([^{}]+?)}`)
|
var subScriptSuperScriptRegexp = regexp.MustCompile(`^([_^]){([^{}]+?)}`)
|
||||||
var timestampRegexp = regexp.MustCompile(`^<(\d{4}-\d{2}-\d{2})( [A-Za-z]+)?( \d{2}:\d{2})?( \+\d+[dwmy])?>`)
|
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 statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`)
|
||||||
|
|
||||||
var timestampFormat = "2006-01-02 Mon 15:04"
|
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) {
|
func (d *Document) parseFootnoteReference(input string, start int) (int, Node) {
|
||||||
if m := footnoteRegexp.FindStringSubmatch(input[start:]); m != nil {
|
if m := footnoteRegexp.FindStringSubmatch(input[start:]); m != nil {
|
||||||
name, definition := m[1], m[3]
|
name, definition := m[1], m[3]
|
||||||
|
if name == "" && definition == "" {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
link := FootnoteLink{name, nil}
|
link := FootnoteLink{name, nil}
|
||||||
if definition != "" {
|
if definition != "" {
|
||||||
link.Definition = &FootnoteDefinition{name, []Node{Paragraph{d.parseInline(definition)}}, true}
|
link.Definition = &FootnoteDefinition{name, []Node{Paragraph{d.parseInline(definition)}}, true}
|
||||||
|
|
21
org/testdata/footnotes.html
vendored
21
org/testdata/footnotes.html
vendored
|
@ -27,8 +27,13 @@ inline footnotes are also supported via <sup class="footnote-reference"><a id="f
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<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.
|
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>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -36,10 +41,10 @@ Rather, they are gathered and exported at the end of the document in the footnot
|
||||||
Footnotes
|
Footnotes
|
||||||
</h1>
|
</h1>
|
||||||
<p>
|
<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>
|
||||||
<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>
|
</p>
|
||||||
<div class="footnotes">
|
<div class="footnotes">
|
||||||
<hr class="footnotes-separatator">
|
<hr class="footnotes-separatator">
|
||||||
|
@ -118,13 +123,21 @@ the inline footnote definition
|
||||||
<sup id="footnote-3"><a href="#footnote-reference-3">3</a></sup>
|
<sup id="footnote-3"><a href="#footnote-reference-3">3</a></sup>
|
||||||
<div class="footnote-body">
|
<div class="footnote-body">
|
||||||
<p>
|
<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.
|
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.
|
Rather, it will be somewhere down below in the footnotes section.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="footnote-definition">
|
<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">
|
<div class="footnote-body">
|
||||||
<p>
|
<p>
|
||||||
There's multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently
|
There's multiple reasons for that. Among others, doing so requires i18n (to recognize the section) and silently
|
||||||
|
|
1
org/testdata/footnotes.org
vendored
1
org/testdata/footnotes.org
vendored
|
@ -2,6 +2,7 @@
|
||||||
- normal footnote reference [fn:1] [fn:6]
|
- normal footnote reference [fn:1] [fn:6]
|
||||||
- further references to the same footnote should not [fn:1] render duplicates in the footnote list
|
- 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].
|
- 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.
|
- 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]
|
Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4]
|
||||||
|
|
||||||
|
|
1
org/testdata/footnotes.pretty_org
vendored
1
org/testdata/footnotes.pretty_org
vendored
|
@ -2,6 +2,7 @@
|
||||||
- normal footnote reference [fn:1] [fn:6]
|
- normal footnote reference [fn:1] [fn:6]
|
||||||
- further references to the same footnote should not [fn:1] render duplicates in the footnote list
|
- 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].
|
- 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.
|
- 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]
|
Rather, they are gathered and exported at the end of the document in the footnote section. [fn:4]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue