From 37d33c120656072472beba8bf3cf70e1d13ae14a Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Sun, 7 Jul 2019 10:19:24 +0200 Subject: [PATCH] HTML export: Export src block language as css class Org mode exports source blocks with the language as a css-class of the exported source block - it's easy enough to do the same. --- org/html_writer.go | 3 ++- org/testdata/blocks.html | 6 ++++++ org/testdata/captions.html | 2 ++ org/testdata/footnotes.html | 2 ++ org/testdata/headlines.html | 2 ++ org/testdata/keywords.html | 3 ++- org/testdata/lists.html | 4 ++++ org/testdata/misc.html | 10 ++++++++++ 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/org/html_writer.go b/org/html_writer.go index 33f3acc..94f3c8b 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -108,7 +108,8 @@ func (w *HTMLWriter) WriteBlock(b Block) { if len(b.Parameters) >= 1 { lang = strings.ToLower(b.Parameters[0]) } - w.WriteString(w.HighlightCodeBlock(content, lang) + "\n") + content = w.HighlightCodeBlock(content, lang) + 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 ed270fe..253f2fe 100644 --- a/org/testdata/blocks.html +++ b/org/testdata/blocks.html @@ -1,4 +1,5 @@
+
 
 echo "a bash source block"
@@ -10,15 +11,18 @@ function hello {
 hello
 
+
block caption
+
 
 a source block without a language
 
+
 an example block with
 multiple lines including
@@ -120,11 +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 4e9ab45..f2a4a03 100644 --- a/org/testdata/captions.html +++ b/org/testdata/captions.html @@ -2,11 +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 ea722e5..4e50b35 100644 --- a/org/testdata/footnotes.html +++ b/org/testdata/footnotes.html @@ -70,11 +70,13 @@ and other elements

like blocks

+
 
 other non-plain
 
+
  • diff --git a/org/testdata/headlines.html b/org/testdata/headlines.html index 3c491e4..6dc8805 100644 --- a/org/testdata/headlines.html +++ b/org/testdata/headlines.html @@ -68,9 +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 135c47e..406be0d 100644 --- a/org/testdata/keywords.html +++ b/org/testdata/keywords.html @@ -1,8 +1,9 @@
    -
    +
    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 9729362..46db977 100644 --- a/org/testdata/lists.html +++ b/org/testdata/lists.html @@ -59,11 +59,13 @@ and some lines of text

    and another subitem

    +
     
     echo with a block
     
    +
  • @@ -131,11 +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 0ec917c..a925348 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -114,6 +114,7 @@ for now files can be included as:

    src block

    +
     
     #+SETUPFILE: setup_file_org
    @@ -146,6 +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:=.
     
    +
  • @@ -390,11 +392,13 @@ inline code -- --- a

    src/example/export blocks should not be converted!

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

    lowercased:

    +
     
     uname -a
     
    +
  • uppercased

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

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