From 09a8437b597225e9cf6b86cdd1357e4fa5cab34d Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Mon, 3 Dec 2018 00:50:44 +0100 Subject: [PATCH] HTMLWriter: Change code block markup to resemble hugo chroma output The highlight function from hugo already wraps the highlighted source code in div > pre > code e.g.
echo hello world
So now we always delegate all that to the highlight function --- org/html.go | 6 ++---- org/testdata/example.html | 18 +++++------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/org/html.go b/org/html.go index 9c47dd0..70f4f40 100644 --- a/org/html.go +++ b/org/html.go @@ -34,7 +34,7 @@ var listTags = map[string][]string{ func NewHTMLWriter() *HTMLWriter { return &HTMLWriter{ HighlightCodeBlock: func(source, lang string) string { - return fmt.Sprintf("
%s
", html.EscapeString(source)) + return fmt.Sprintf(`
%s
`, html.EscapeString(source)) }, } } @@ -112,9 +112,7 @@ func (w *HTMLWriter) writeBlock(b Block) { for _, n := range b.Children { lines = append(lines, n.(Line).Children[0].(Text).Content) } - w.WriteString(fmt.Sprintf(``, lang) + "\n") - w.WriteString(w.HighlightCodeBlock(strings.Join(lines, "\n"), lang)) - w.WriteString("\n\n") + w.WriteString(w.HighlightCodeBlock(strings.Join(lines, "\n"), lang) + "\n") case "EXAMPLE": w.WriteString(`
\n`)
 		w.writeNodes(b.Children...)
diff --git a/org/testdata/example.html b/org/testdata/example.html
index ea6c340..59aa612 100644
--- a/org/testdata/example.html
+++ b/org/testdata/example.html
@@ -63,9 +63,7 @@ and some lines of text
 

and another subitem

- -
echo with a block
-
+
echo with a block
  • @@ -166,14 +164,10 @@ auto link, i.e. not inside \[[square brackets]\] <

  • blocks

    - -
    echo a bash source block
    -
    - -
    a source block without a language
    +
    echo a bash source block
    +
    a source block without a language
     and a second line
    -and a third one
    -
    +and a third one
    \nan example block
     with multiple lines
     
    @@ -280,9 +274,7 @@ and other elements

    like blocks

    - -
    other non-plain
    -
    +
    other non-plain