Support html export blocks
This commit is contained in:
parent
04db858934
commit
53b61abfd0
4 changed files with 18 additions and 7 deletions
|
@ -24,7 +24,7 @@ func lexBlock(line string) (token, bool) {
|
||||||
return nilToken, false
|
return nilToken, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isRawTextBlock(name string) bool { return name == "SRC" || name == "EXAMPLE" }
|
func isRawTextBlock(name string) bool { return name == "SRC" || name == "EXAMPLE" || name == "EXPORT" }
|
||||||
|
|
||||||
func (d *Document) parseBlock(i int, parentStop stopFn) (int, Node) {
|
func (d *Document) parseBlock(i int, parentStop stopFn) (int, Node) {
|
||||||
t, start, lines := d.tokens[i], i, []string{}
|
t, start, lines := d.tokens[i], i, []string{}
|
||||||
|
|
14
org/html.go
14
org/html.go
|
@ -107,22 +107,24 @@ func (w *HTMLWriter) writeNodes(ns ...Node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *HTMLWriter) writeBlock(b Block) {
|
func (w *HTMLWriter) writeBlock(b Block) {
|
||||||
switch b.Name {
|
switch name := b.Name; {
|
||||||
case "SRC":
|
case name == "SRC":
|
||||||
source, lang := b.Children[0].(Text).Content, "text"
|
source, lang := b.Children[0].(Text).Content, "text"
|
||||||
if len(b.Parameters) >= 1 {
|
if len(b.Parameters) >= 1 {
|
||||||
lang = b.Parameters[0]
|
lang = strings.ToLower(b.Parameters[0])
|
||||||
}
|
}
|
||||||
w.WriteString(w.HighlightCodeBlock(source, lang) + "\n")
|
w.WriteString(w.HighlightCodeBlock(source, lang) + "\n")
|
||||||
case "EXAMPLE":
|
case name == "EXAMPLE":
|
||||||
w.WriteString(`<pre class="example">` + "\n")
|
w.WriteString(`<pre class="example">` + "\n")
|
||||||
w.writeNodes(b.Children...)
|
w.writeNodes(b.Children...)
|
||||||
w.WriteString("\n</pre>\n")
|
w.WriteString("\n</pre>\n")
|
||||||
case "QUOTE":
|
case name == "EXPORT" && len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html":
|
||||||
|
w.WriteString(b.Children[0].(Text).Content + "\n")
|
||||||
|
case name == "QUOTE":
|
||||||
w.WriteString("<blockquote>\n")
|
w.WriteString("<blockquote>\n")
|
||||||
w.writeNodes(b.Children...)
|
w.writeNodes(b.Children...)
|
||||||
w.WriteString("</blockquote>\n")
|
w.WriteString("</blockquote>\n")
|
||||||
case "CENTER":
|
case name == "CENTER":
|
||||||
w.WriteString(`<div 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.writeNodes(b.Children...)
|
||||||
w.WriteString("</div>\n")
|
w.WriteString("</div>\n")
|
||||||
|
|
3
org/testdata/blocks.html
vendored
3
org/testdata/blocks.html
vendored
|
@ -19,3 +19,6 @@ Mongodb is very webscale
|
||||||
and quote blocks can contain multiple paragraphs
|
and quote blocks can contain multiple paragraphs
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
<script>
|
||||||
|
console.log("Hello World!")
|
||||||
|
</script>
|
||||||
|
|
6
org/testdata/blocks.org
vendored
6
org/testdata/blocks.org
vendored
|
@ -19,3 +19,9 @@ Mongodb is very webscale
|
||||||
|
|
||||||
and quote blocks can contain multiple paragraphs
|
and quote blocks can contain multiple paragraphs
|
||||||
#+END_QUOTE
|
#+END_QUOTE
|
||||||
|
|
||||||
|
#+BEGIN_EXPORT html
|
||||||
|
<script>
|
||||||
|
console.log("Hello World!")
|
||||||
|
</script>
|
||||||
|
#+END_EXPORT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue