From 97fe8b7850b5178ac27adc1eb592dc16ebc8acc2 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Sun, 28 Jul 2019 16:40:09 +0200 Subject: [PATCH] html: Fix code block export (superfluous newlines) I didn't consider that all newlines in the pre block will be printed and we thus shouldn't wrap html that has it's tags on separate lines (i.e. contains superfluous newlines) - wrapping in a div less accurately represents org-html-export but it provides the same information and gives us more freedom in the return value of HighlightCodeBlock as well as allowing us to keep the html tags on new lines (consistency). --- org/html_writer.go | 4 ++-- org/testdata/blocks.html | 12 ++++++------ org/testdata/captions.html | 4 ++-- org/testdata/footnotes.html | 4 ++-- org/testdata/headlines.html | 4 ++-- org/testdata/keywords.html | 5 +++-- org/testdata/lists.html | 8 ++++---- org/testdata/misc.html | 20 ++++++++++---------- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/org/html_writer.go b/org/html_writer.go index 05713e6..ad1bedd 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -59,7 +59,7 @@ func NewHTMLWriter() *HTMLWriter { log: defaultConfig.Log, htmlEscape: true, HighlightCodeBlock: func(source, lang string) string { - return fmt.Sprintf("%s\n
\n%s\n
\n", `
`, html.EscapeString(source)) + return fmt.Sprintf("
\n
\n%s\n
\n
", html.EscapeString(source)) }, footnotes: footnotes{ mapping: map[string]int{}, @@ -109,7 +109,7 @@ func (w *HTMLWriter) WriteBlock(b Block) { lang = strings.ToLower(b.Parameters[0]) } content = w.HighlightCodeBlock(content, lang) - w.WriteString(fmt.Sprintf("
\n%s\n
\n", lang, content)) + w.WriteString(fmt.Sprintf("
\n%s\n
\n", lang, content)) case name == "EXAMPLE": w.WriteString(`
` + "\n" + content + "\n
\n") case name == "EXPORT" && len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html": diff --git a/org/testdata/blocks.html b/org/testdata/blocks.html index 253f2fe..38a304c 100644 --- a/org/testdata/blocks.html +++ b/org/testdata/blocks.html @@ -1,5 +1,5 @@
-
+
 echo "a bash source block"
@@ -11,18 +11,18 @@ function hello {
 hello
 
-
+
block caption
-
+
 a source block without a language
 
-
+
 an example block with
 multiple lines including
@@ -124,13 +124,13 @@ this unindented line is outside of the list item
 

list item 2

-
+
 #+BEGIN_EXAMPLE
 
-
+

#+END_EXAMPLE

diff --git a/org/testdata/captions.html b/org/testdata/captions.html index f2a4a03..d5df4e5 100644 --- a/org/testdata/captions.html +++ b/org/testdata/captions.html @@ -2,13 +2,13 @@ Anything can be captioned.

-
+
 echo "i have a caption!"
 
-
+
captioned soure block
diff --git a/org/testdata/footnotes.html b/org/testdata/footnotes.html index 7575443..e74da17 100644 --- a/org/testdata/footnotes.html +++ b/org/testdata/footnotes.html @@ -75,13 +75,13 @@ and other elements

like blocks

-
+
 other non-plain
 
-
+
  • diff --git a/org/testdata/headlines.html b/org/testdata/headlines.html index 6dc8805..c9d0cf6 100644 --- a/org/testdata/headlines.html +++ b/org/testdata/headlines.html @@ -68,11 +68,11 @@ headline with custom status

    it's possible to use #+SETUPFILE - in this case the setup file contains the following

    -
    +
     #+TODO: TODO DONE CUSTOM
     #+EXCLUDE_TAGS: noexport custom_noexport
     
    -
    + diff --git a/org/testdata/keywords.html b/org/testdata/keywords.html index 406be0d..351df78 100644 --- a/org/testdata/keywords.html +++ b/org/testdata/keywords.html @@ -1,9 +1,10 @@
    -
    +
    +
    echo "a bash source block with custom html attributes"
     
    -
    +
    and multiple lines of captions!
    diff --git a/org/testdata/lists.html b/org/testdata/lists.html index 46db977..b09c908 100644 --- a/org/testdata/lists.html +++ b/org/testdata/lists.html @@ -59,13 +59,13 @@ and some lines of text

    and another subitem

    -
    +
     echo with a block
     
    -
    +
  • @@ -133,13 +133,13 @@ term

    details on a new line (with an empty line in between) continued

    -
    +
     echo "Hello World!"
     
    -
    +

    diff --git a/org/testdata/misc.html b/org/testdata/misc.html index d6a389f..2a308cc 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -114,7 +114,7 @@ for now files can be included as:

    src block

    -
    +
     #+SETUPFILE: setup_file_org
    @@ -147,7 +147,7 @@ this headline and it's content are not exported as it is marked with an =EXC
     By default =EXCLUDE_TAGS= is just =:noexport:=.
     
    -
    +
  • @@ -392,13 +392,13 @@ inline code -- --- a

    src/example/export blocks should not be converted!

    -
    +
     --, ---
     
    -
    +
     --, ---
     
    @@ -427,25 +427,25 @@ The behaviour of Org mode <s TAB changed and it

    lowercased:

    -
    +
     uname -a
     
    -
    +
  • uppercased

    -
    +
     uname -a
     
    -
    +
  • @@ -463,7 +463,7 @@ When inserting an image link like #4006 source code blocks in org not rendered correctly

    -
    +
     (defun small-shell ()
    @@ -474,7 +474,7 @@ When inserting an image link like 
     Footnotes