Support html export blocks

This commit is contained in:
Niklas Fasching 2018-12-11 16:03:04 +01:00
parent 04db858934
commit 53b61abfd0
4 changed files with 18 additions and 7 deletions

View file

@ -24,7 +24,7 @@ func lexBlock(line string) (token, bool) {
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) {
t, start, lines := d.tokens[i], i, []string{}

View file

@ -107,22 +107,24 @@ func (w *HTMLWriter) writeNodes(ns ...Node) {
}
func (w *HTMLWriter) writeBlock(b Block) {
switch b.Name {
case "SRC":
switch name := b.Name; {
case name == "SRC":
source, lang := b.Children[0].(Text).Content, "text"
if len(b.Parameters) >= 1 {
lang = b.Parameters[0]
lang = strings.ToLower(b.Parameters[0])
}
w.WriteString(w.HighlightCodeBlock(source, lang) + "\n")
case "EXAMPLE":
case name == "EXAMPLE":
w.WriteString(`<pre class="example">` + "\n")
w.writeNodes(b.Children...)
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.writeNodes(b.Children...)
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.writeNodes(b.Children...)
w.WriteString("</div>\n")

View file

@ -19,3 +19,6 @@ Mongodb is very webscale
and quote blocks can contain multiple paragraphs
</p>
</blockquote>
<script>
console.log("Hello World!")
</script>

View file

@ -19,3 +19,9 @@ Mongodb is very webscale
and quote blocks can contain multiple paragraphs
#+END_QUOTE
#+BEGIN_EXPORT html
<script>
console.log("Hello World!")
</script>
#+END_EXPORT