Fix paragraphs: Empty lines separate paragraphs
Somehow i thought it was 2 empty lines rather than 1 - makes more sense this way... :D
This commit is contained in:
parent
c759df1efe
commit
ed8764940f
5 changed files with 41 additions and 25 deletions
|
@ -148,13 +148,6 @@ 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) {
|
||||
w.WriteString(fmt.Sprintf("[fn:%s]", f.Name))
|
||||
if !(len(f.Children) >= 1 && isEmptyLineParagraph(f.Children[0])) {
|
||||
|
|
|
@ -25,27 +25,13 @@ func lexHorizontalRule(line string) (token, bool) {
|
|||
return nilToken, false
|
||||
}
|
||||
|
||||
func isSecondBlankLine(d *Document, i int) bool {
|
||||
if i-1 <= 0 {
|
||||
return false
|
||||
}
|
||||
t1, t2 := d.tokens[i-1], d.tokens[i]
|
||||
if t1.kind == "text" && t2.kind == "text" && t1.content == "" && t2.content == "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *Document) parseParagraph(i int, parentStop stopFn) (int, Node) {
|
||||
lines, start := []Node{Line{d.parseInline(d.tokens[i].content)}}, i
|
||||
i++
|
||||
stop := func(d *Document, i int) bool { return parentStop(d, i) || d.tokens[i].kind != "text" }
|
||||
for ; !stop(d, i) && !isSecondBlankLine(d, i); i++ {
|
||||
if isSecondBlankLine(d, i) {
|
||||
lines = lines[:len(lines)-1]
|
||||
i++
|
||||
break
|
||||
}
|
||||
stop := func(d *Document, i int) bool {
|
||||
return parentStop(d, i) || d.tokens[i].kind != "text" || d.tokens[i].content == ""
|
||||
}
|
||||
for ; !stop(d, i); i++ {
|
||||
lines = append(lines, Line{d.parseInline(d.tokens[i].content)})
|
||||
}
|
||||
consumed := i - start
|
||||
|
|
10
org/testdata/example.html
vendored
10
org/testdata/example.html
vendored
|
@ -5,6 +5,16 @@ works we can be kind of sure that the parsing worked.
|
|||
At least I hope so - I would like to get around writing tests for the individual parsing
|
||||
functions...
|
||||
</p>
|
||||
<h2>Paragraphs</h2>
|
||||
<p>
|
||||
Empty lines separate paragraphs.
|
||||
</p>
|
||||
<p>
|
||||
Right?
|
||||
</p>
|
||||
<p>
|
||||
They do!
|
||||
</p>
|
||||
<h2>Headlines with TODO status, priority & tags</h2>
|
||||
<h3>Headline with todo status & priority</h3>
|
||||
<h3>Headline with TODO status</h3>
|
||||
|
|
8
org/testdata/example.org
vendored
8
org/testdata/example.org
vendored
|
@ -9,6 +9,14 @@ works we can be kind of sure that the parsing worked.
|
|||
At least I hope so - I would like to get around writing tests for the individual parsing
|
||||
functions...
|
||||
|
||||
** Paragraphs
|
||||
|
||||
Empty lines separate paragraphs.
|
||||
|
||||
Right?
|
||||
|
||||
They do!
|
||||
|
||||
** Headlines with TODO status, priority & tags
|
||||
*** TODO [#B] Headline with todo status & priority
|
||||
*** DONE Headline with TODO status
|
||||
|
|
19
org/util.go
Normal file
19
org/util.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package org
|
||||
|
||||
func isSecondBlankLine(d *Document, i int) bool {
|
||||
if i-1 <= 0 {
|
||||
return false
|
||||
}
|
||||
t1, t2 := d.tokens[i-1], d.tokens[i]
|
||||
if t1.kind == "text" && t2.kind == "text" && t1.content == "" && t2.content == "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isEmptyLineParagraph(n Node) bool {
|
||||
if p, _ := n.(Paragraph); len(p.Children) == 1 {
|
||||
return len(p.Children[0].(Line).Children) == 0
|
||||
}
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue