Fix footnotes starting with empty line
This commit is contained in:
parent
3c2e9ed204
commit
d5665fb21c
5 changed files with 26 additions and 11 deletions
|
@ -17,7 +17,7 @@ type FootnoteDefinition struct {
|
||||||
Inline bool
|
Inline bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var footnoteDefinitionRegexp = regexp.MustCompile(`^\[fn:([\w-]+)\]\s+(.+)`)
|
var footnoteDefinitionRegexp = regexp.MustCompile(`^\[fn:([\w-]+)\](\s+(.+)|$)`)
|
||||||
|
|
||||||
func lexFootnoteDefinition(line string) (token, bool) {
|
func lexFootnoteDefinition(line string) (token, bool) {
|
||||||
if m := footnoteDefinitionRegexp.FindStringSubmatch(line); m != nil {
|
if m := footnoteDefinitionRegexp.FindStringSubmatch(line); m != nil {
|
||||||
|
@ -27,10 +27,11 @@ func lexFootnoteDefinition(line string) (token, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) parseFootnoteDefinition(i int, parentStop stopFn) (int, Node) {
|
func (d *Document) parseFootnoteDefinition(i int, parentStop stopFn) (int, Node) {
|
||||||
name := d.tokens[i].content
|
start, name := i, d.tokens[i].content
|
||||||
d.tokens[i] = tokenize(d.tokens[i].matches[2])
|
d.tokens[i] = tokenize(d.tokens[i].matches[2])
|
||||||
stop := func(d *Document, i int) bool {
|
stop := func(d *Document, i int) bool {
|
||||||
return parentStop(d, i) || isSecondBlankLine(d, i) ||
|
return parentStop(d, i) ||
|
||||||
|
(isSecondBlankLine(d, i) && i > start+1) ||
|
||||||
d.tokens[i].kind == "headline" || d.tokens[i].kind == "footnoteDefinition"
|
d.tokens[i].kind == "headline" || d.tokens[i].kind == "footnoteDefinition"
|
||||||
}
|
}
|
||||||
consumed, nodes := d.parseMany(i, stop)
|
consumed, nodes := d.parseMany(i, stop)
|
||||||
|
|
|
@ -118,8 +118,8 @@ func (d *Document) parseFootnoteReference(input string, start int) (int, Node) {
|
||||||
if definition != "" {
|
if definition != "" {
|
||||||
paragraph := Paragraph{[]Node{Line{d.parseInline(definition)}}}
|
paragraph := Paragraph{[]Node{Line{d.parseInline(definition)}}}
|
||||||
link.Definition = &FootnoteDefinition{name, []Node{paragraph}, true}
|
link.Definition = &FootnoteDefinition{name, []Node{paragraph}, true}
|
||||||
|
d.Footnotes.add(name, link.Definition)
|
||||||
}
|
}
|
||||||
d.Footnotes.add(name, link.Definition)
|
|
||||||
return len(m[0]), link
|
return len(m[0]), link
|
||||||
}
|
}
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|
12
org/org.go
12
org/org.go
|
@ -148,8 +148,18 @@ func (w *OrgWriter) writeFootnotes(d *Document) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isEmptyLineParagraph(n Node) bool {
|
||||||
|
if p, _ := n.(Paragraph); len(p.Children) == 1 {
|
||||||
|
return len(p.Children[0].(Line).Children) == 0
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (w *OrgWriter) writeFootnoteDefinition(f FootnoteDefinition) {
|
func (w *OrgWriter) writeFootnoteDefinition(f FootnoteDefinition) {
|
||||||
w.WriteString(fmt.Sprintf("[fn:%s] ", f.Name))
|
w.WriteString(fmt.Sprintf("[fn:%s]", f.Name))
|
||||||
|
if !(len(f.Children) >= 1 && isEmptyLineParagraph(f.Children[0])) {
|
||||||
|
w.WriteString(" ")
|
||||||
|
}
|
||||||
w.writeNodes(f.Children...)
|
w.writeNodes(f.Children...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
org/testdata/example.html
vendored
7
org/testdata/example.html
vendored
|
@ -199,7 +199,7 @@ or <code>that</code> foo.
|
||||||
</p>
|
</p>
|
||||||
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/68">#68</a>: Quote block with inline markup</h3>
|
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/68">#68</a>: Quote block with inline markup</h3>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<a href="www.example.com"><em>this</em> <strong>is</strong> <span style="text-decoration: underline;">markup</span>!</a>
|
<a href="https://www.example.com"><em>this</em> <strong>is</strong> <span style="text-decoration: underline;">markup</span>!</a>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/77">#77</a>: Recognize <code class="verbatim">code</code>--- as code plus dash</h3>
|
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/77">#77</a>: Recognize <code class="verbatim">code</code>--- as code plus dash</h3>
|
||||||
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/75">#75</a>: Not parsing nested lists correctly</h3>
|
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/75">#75</a>: Not parsing nested lists correctly</h3>
|
||||||
|
@ -243,7 +243,7 @@ Bar paragraph
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
normal footnote reference <sup class="footnote-reference"><a href="#footnote-1">1</a></sup>
|
normal footnote reference <sup class="footnote-reference"><a href="#footnote-1">1</a></sup> <sup class="footnote-reference"><a href="#footnote-6">6</a></sup>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -327,7 +327,8 @@ another unused footnote
|
||||||
<div class="footnote-definition">
|
<div class="footnote-definition">
|
||||||
<sup id="footnote-6">6</sup>
|
<sup id="footnote-6">6</sup>
|
||||||
<p>
|
<p>
|
||||||
another unused footnote
|
Footnotes break after two consecutive empty lines - just like paragraphs - see <a href="https://orgmode.org/worg/dev/org-syntax.html.">https://orgmode.org/worg/dev/org-syntax.html.</a>
|
||||||
|
This shouldn't happen when the definition line and the line after that are empty.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="footnote-definition">
|
<div class="footnote-definition">
|
||||||
|
|
9
org/testdata/example.org
vendored
9
org/testdata/example.org
vendored
|
@ -89,7 +89,7 @@ either ~this~
|
||||||
or ~that~ foo.
|
or ~that~ foo.
|
||||||
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/68][#68]]: Quote block with inline markup
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/68][#68]]: Quote block with inline markup
|
||||||
#+BEGIN_QUOTE
|
#+BEGIN_QUOTE
|
||||||
[[www.example.com][/this/ *is* _markup_!]]
|
[[https://www.example.com][/this/ *is* _markup_!]]
|
||||||
#+END_QUOTE
|
#+END_QUOTE
|
||||||
|
|
||||||
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/77][#77]]: Recognize =code=--- as code plus dash
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/77][#77]]: Recognize =code=--- as code plus dash
|
||||||
|
@ -111,7 +111,7 @@ Foo paragraph.
|
||||||
**** Bar
|
**** Bar
|
||||||
Bar paragraph
|
Bar paragraph
|
||||||
** Footnotes
|
** Footnotes
|
||||||
- normal footnote reference [fn:1]
|
- 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].
|
||||||
|
|
||||||
|
@ -134,4 +134,7 @@ Bar paragraph
|
||||||
|
|
||||||
[fn:5] another unused footnote
|
[fn:5] another unused footnote
|
||||||
|
|
||||||
[fn:6] another unused footnote
|
[fn:6]
|
||||||
|
|
||||||
|
Footnotes break after two consecutive empty lines - just like paragraphs - see https://orgmode.org/worg/dev/org-syntax.html.
|
||||||
|
This shouldn't happen when the definition line and the line after that are empty.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue