diff --git a/README.org b/README.org index af67a39..49faa3f 100644 --- a/README.org +++ b/README.org @@ -5,8 +5,6 @@ A basic org-mode parser in go * next - hugo frontmatter - see https://gohugo.io/content-management/front-matter/ - captions: images, tables & blocks -- blocks: highlighted src code, blockquote -- basic tables * later - affiliated keywords see org-element.el - org-element-affiliated-keywords diff --git a/org/html.go b/org/html.go index 41af658..277af26 100644 --- a/org/html.go +++ b/org/html.go @@ -33,7 +33,9 @@ var listTags = map[string][]string{ func NewHTMLWriter() *HTMLWriter { return &HTMLWriter{ - HighlightCodeBlock: func(source, lang string) string { return html.EscapeString(source) }, + HighlightCodeBlock: func(source, lang string) string { + return fmt.Sprintf("
%s", html.EscapeString(source)) + }, } } @@ -110,17 +112,31 @@ func (w *HTMLWriter) writeLines(lines []Node) { } func (w *HTMLWriter) writeBlock(b Block) { - w.WriteString("") - lang := "" - if len(b.Parameters) >= 1 { - lang = b.Parameters[0] + switch b.Name { + case "SRC": + lines, lang := []string{}, "text" + if len(b.Parameters) >= 1 { + lang = b.Parameters[0] + } + for _, n := range b.Children { + lines = append(lines, n.(Line).Children[0].(Text).Content) + } + w.WriteString(fmt.Sprintf(`
\n") } func (w *HTMLWriter) writeFootnoteDefinition(f FootnoteDefinition) { diff --git a/org/testdata/example.html b/org/testdata/example.html index 4d6af74..96d9397 100644 --- a/org/testdata/example.html +++ b/org/testdata/example.html @@ -23,7 +23,9 @@`, lang) + "\n") + w.WriteString(w.HighlightCodeBlock(strings.Join(lines, "\n"), lang)) + w.WriteString("\n
\n") + case "EXAMPLE": + w.WriteString(`` + "\n") + w.writeNodes(b.Children...) + w.WriteString("\n\n") + case "QUOTE": + w.WriteString("\n") + w.writeNodes(b.Children...) + w.WriteString("\n\n") + case "CENTER": + w.WriteString(`` + "\n") + w.writeNodes(b.Children...) + w.WriteString("\n\n") } - lines := []string{} - for _, n := range b.Children { - lines = append(lines, n.(Line).Children[0].(Text).Content) - } - w.WriteString(w.HighlightCodeBlock(strings.Join(lines, "\n"), lang)) - w.WriteString("
unordered list item 3 - and a link and some lines of text
and another subitem
-echo with a block
+
+echo with a block
+
and another one with a table