Allow blocks to contain paragraphs and other top level elements
This commit is contained in:
parent
ed8764940f
commit
8f06883ec5
4 changed files with 36 additions and 14 deletions
25
org/block.go
25
org/block.go
|
@ -28,17 +28,26 @@ func (d *Document) parseBlock(i int, parentStop stopFn) (int, Node) {
|
|||
t, start, nodes := d.tokens[i], i, []Node{}
|
||||
name, parameters := t.content, strings.Fields(t.matches[3])
|
||||
trim := trimIndentUpTo(d.tokens[i].lvl)
|
||||
for i++; !(d.tokens[i].kind == "endBlock" && d.tokens[i].content == name); i++ {
|
||||
stop := func(d *Document, i int) bool {
|
||||
return parentStop(d, i) || (d.tokens[i].kind == "endBlock" && d.tokens[i].content == name)
|
||||
}
|
||||
if name == "SRC" || name == "EXAMPLE" {
|
||||
for i++; !stop(d, i); i++ {
|
||||
nodes = append(nodes, Line{[]Node{Text{trim(d.tokens[i].matches[0])}}})
|
||||
}
|
||||
} else {
|
||||
for i++; !stop(d, i); {
|
||||
consumed, node := d.parseParagraph(i, stop)
|
||||
if consumed == 0 {
|
||||
break
|
||||
}
|
||||
i += consumed
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
}
|
||||
if parentStop(d, i) {
|
||||
return 0, nil
|
||||
}
|
||||
text := trim(d.tokens[i].matches[0])
|
||||
if name == "SRC" || name == "EXAMPLE" {
|
||||
nodes = append(nodes, Line{[]Node{Text{text}}})
|
||||
} else {
|
||||
nodes = append(nodes, Line{d.parseInline(text)})
|
||||
}
|
||||
}
|
||||
return i + 1 - start, Block{name, parameters, nodes}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,13 +122,13 @@ func (w *HTMLWriter) writeBlock(b Block) {
|
|||
w.writeNodes(b.Children...)
|
||||
w.WriteString("</blockquote>\n")
|
||||
case "CENTER":
|
||||
w.WriteString(`<p class="center-block" style="text-align: center; margin-left: auto; margin-right: auto;">` + "\n")
|
||||
w.WriteString(`<div class="center-block" style="text-align: center; margin-left: auto; margin-right: auto;">` + "\n")
|
||||
w.writeNodes(b.Children...)
|
||||
w.WriteString("</p>\n")
|
||||
w.WriteString("</div>\n")
|
||||
default:
|
||||
w.WriteString(fmt.Sprintf(`<p class="%s-block">`, strings.ToLower(b.Name)) + "\n")
|
||||
w.WriteString(fmt.Sprintf(`<div class="%s-block">`, strings.ToLower(b.Name)) + "\n")
|
||||
w.writeNodes(b.Children...)
|
||||
w.WriteString("</p>\n")
|
||||
w.WriteString("</div>\n")
|
||||
|
||||
}
|
||||
}
|
||||
|
|
15
org/testdata/example.html
vendored
15
org/testdata/example.html
vendored
|
@ -183,19 +183,28 @@ an example block
|
|||
with multiple lines
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
Mongodb is very webscale
|
||||
</p>
|
||||
<p>
|
||||
and quote blocks can contain multiple paragraphs
|
||||
</p>
|
||||
</blockquote>
|
||||
<h2>issues from goorgeous (free test cases, yay!)</h2>
|
||||
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/29">#29:</a> Support verse block</h3>
|
||||
<p class="verse-block">
|
||||
<div class="verse-block">
|
||||
<p>
|
||||
This
|
||||
<strong>is</strong>
|
||||
verse
|
||||
</p>
|
||||
<p class="custom-block">
|
||||
</div>
|
||||
<div class="custom-block">
|
||||
<p>
|
||||
or even a <strong>totally</strong> <em>custom</em> kind of block
|
||||
crazy ain't it?
|
||||
</p>
|
||||
</div>
|
||||
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/47">#47:</a> Consecutive <code>code</code> wrapped text gets joined</h3>
|
||||
<p>
|
||||
either <code>this</code> or <code>that</code> foo.
|
||||
|
@ -204,7 +213,9 @@ or <code>that</code> foo.
|
|||
</p>
|
||||
<h3><a href="https://github.com/chaseadamsio/goorgeous/issues/68">#68</a>: Quote block with inline markup</h3>
|
||||
<blockquote>
|
||||
<p>
|
||||
<a href="https://www.example.com"><em>this</em> <strong>is</strong> <span style="text-decoration: underline;">markup</span>!</a>
|
||||
</p>
|
||||
</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/75">#75</a>: Not parsing nested lists correctly</h3>
|
||||
|
|
2
org/testdata/example.org
vendored
2
org/testdata/example.org
vendored
|
@ -77,6 +77,8 @@ with multiple lines
|
|||
|
||||
#+BEGIN_QUOTE
|
||||
Mongodb is very webscale
|
||||
|
||||
and quote blocks can contain multiple paragraphs
|
||||
#+END_QUOTE
|
||||
|
||||
** issues from goorgeous (free test cases, yay!)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue