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).
This commit is contained in:
parent
777899c803
commit
97fe8b7850
8 changed files with 31 additions and 30 deletions
|
@ -59,7 +59,7 @@ func NewHTMLWriter() *HTMLWriter {
|
||||||
log: defaultConfig.Log,
|
log: defaultConfig.Log,
|
||||||
htmlEscape: true,
|
htmlEscape: true,
|
||||||
HighlightCodeBlock: func(source, lang string) string {
|
HighlightCodeBlock: func(source, lang string) string {
|
||||||
return fmt.Sprintf("%s\n<pre>\n%s\n</pre>\n</div>", `<div class="highlight">`, html.EscapeString(source))
|
return fmt.Sprintf("<div class=\"highlight\">\n<pre>\n%s\n</pre>\n</div>", html.EscapeString(source))
|
||||||
},
|
},
|
||||||
footnotes: footnotes{
|
footnotes: footnotes{
|
||||||
mapping: map[string]int{},
|
mapping: map[string]int{},
|
||||||
|
@ -109,7 +109,7 @@ func (w *HTMLWriter) WriteBlock(b Block) {
|
||||||
lang = strings.ToLower(b.Parameters[0])
|
lang = strings.ToLower(b.Parameters[0])
|
||||||
}
|
}
|
||||||
content = w.HighlightCodeBlock(content, lang)
|
content = w.HighlightCodeBlock(content, lang)
|
||||||
w.WriteString(fmt.Sprintf("<pre class=\"src src-%s\">\n%s\n</pre>\n", lang, content))
|
w.WriteString(fmt.Sprintf("<div class=\"src src-%s\">\n%s\n</div>\n", lang, content))
|
||||||
case name == "EXAMPLE":
|
case name == "EXAMPLE":
|
||||||
w.WriteString(`<pre class="example">` + "\n" + content + "\n</pre>\n")
|
w.WriteString(`<pre class="example">` + "\n" + content + "\n</pre>\n")
|
||||||
case name == "EXPORT" && len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html":
|
case name == "EXPORT" && len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html":
|
||||||
|
|
12
org/testdata/blocks.html
vendored
12
org/testdata/blocks.html
vendored
|
@ -1,5 +1,5 @@
|
||||||
<figure>
|
<figure>
|
||||||
<pre class="src src-bash">
|
<div class="src src-bash">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
echo "a bash source block"
|
echo "a bash source block"
|
||||||
|
@ -11,18 +11,18 @@ function hello {
|
||||||
hello
|
hello
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<figcaption>
|
<figcaption>
|
||||||
block caption
|
block caption
|
||||||
</figcaption>
|
</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
<pre class="src src-text">
|
<div class="src src-text">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
a source block without a language
|
a source block without a language
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<pre class="example">
|
<pre class="example">
|
||||||
an example block with
|
an example block with
|
||||||
multiple lines including
|
multiple lines including
|
||||||
|
@ -124,13 +124,13 @@ this unindented line is outside of the list item
|
||||||
<p>
|
<p>
|
||||||
list item 2
|
list item 2
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-text">
|
<div class="src src-text">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
#+BEGIN_EXAMPLE
|
#+BEGIN_EXAMPLE
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
#+END_EXAMPLE
|
#+END_EXAMPLE
|
||||||
</p>
|
</p>
|
||||||
|
|
4
org/testdata/captions.html
vendored
4
org/testdata/captions.html
vendored
|
@ -2,13 +2,13 @@
|
||||||
Anything can be captioned.
|
Anything can be captioned.
|
||||||
</p>
|
</p>
|
||||||
<figure>
|
<figure>
|
||||||
<pre class="src src-sh">
|
<div class="src src-sh">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
echo "i have a caption!"
|
echo "i have a caption!"
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<figcaption>
|
<figcaption>
|
||||||
captioned soure block
|
captioned soure block
|
||||||
</figcaption>
|
</figcaption>
|
||||||
|
|
4
org/testdata/footnotes.html
vendored
4
org/testdata/footnotes.html
vendored
|
@ -75,13 +75,13 @@ and other elements
|
||||||
<p>
|
<p>
|
||||||
like blocks
|
like blocks
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-text">
|
<div class="src src-text">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
other non-plain
|
other non-plain
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
|
|
4
org/testdata/headlines.html
vendored
4
org/testdata/headlines.html
vendored
|
@ -68,11 +68,11 @@ headline with custom status
|
||||||
<p>
|
<p>
|
||||||
it's possible to use <code class="verbatim">#+SETUPFILE</code> - in this case the setup file contains the following
|
it's possible to use <code class="verbatim">#+SETUPFILE</code> - in this case the setup file contains the following
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-org">
|
<div class="src src-org">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
#+TODO: TODO DONE CUSTOM
|
#+TODO: TODO DONE CUSTOM
|
||||||
#+EXCLUDE_TAGS: noexport custom_noexport
|
#+EXCLUDE_TAGS: noexport custom_noexport
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
|
|
5
org/testdata/keywords.html
vendored
5
org/testdata/keywords.html
vendored
|
@ -1,9 +1,10 @@
|
||||||
<figure>
|
<figure>
|
||||||
<pre class="src src-sh a b c d" id="it"><div class="highlight">
|
<div class="src src-sh a b c d" id="it">
|
||||||
|
<div class="highlight">
|
||||||
<pre>echo "a bash source block with custom html attributes"
|
<pre>echo "a bash source block with custom html attributes"
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<figcaption>
|
<figcaption>
|
||||||
and <span style="text-decoration: underline;">multiple</span> lines of <strong>captions</strong>!
|
and <span style="text-decoration: underline;">multiple</span> lines of <strong>captions</strong>!
|
||||||
</figcaption>
|
</figcaption>
|
||||||
|
|
8
org/testdata/lists.html
vendored
8
org/testdata/lists.html
vendored
|
@ -59,13 +59,13 @@ and some lines of text
|
||||||
<p>
|
<p>
|
||||||
and another subitem
|
and another subitem
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-sh">
|
<div class="src src-sh">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
echo with a block
|
echo with a block
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
|
@ -133,13 +133,13 @@ term<dd>
|
||||||
details on a new line (with an empty line in between)
|
details on a new line (with an empty line in between)
|
||||||
<strong>continued</strong>
|
<strong>continued</strong>
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-bash">
|
<div class="src src-bash">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
echo "Hello World!"
|
echo "Hello World!"
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<dd>
|
<dd>
|
||||||
</dl>
|
</dl>
|
||||||
<p>
|
<p>
|
||||||
|
|
20
org/testdata/misc.html
vendored
20
org/testdata/misc.html
vendored
|
@ -114,7 +114,7 @@ for now files can be included as:
|
||||||
<p>
|
<p>
|
||||||
src block
|
src block
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-org">
|
<div class="src src-org">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
#+SETUPFILE: setup_file_org
|
#+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:=.
|
By default =EXCLUDE_TAGS= is just =:noexport:=.
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
|
@ -392,13 +392,13 @@ inline code <code class="verbatim">--</code> <code class="verbatim">---</code> a
|
||||||
<p>
|
<p>
|
||||||
src/example/export blocks should not be converted!
|
src/example/export blocks should not be converted!
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-sh">
|
<div class="src src-sh">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
--, ---
|
--, ---
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<pre class="example">
|
<pre class="example">
|
||||||
--, ---
|
--, ---
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -427,25 +427,25 @@ The behaviour of Org mode <code class="verbatim"><s TAB</code> changed and it
|
||||||
<p>
|
<p>
|
||||||
lowercased:
|
lowercased:
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-bash">
|
<div class="src src-bash">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
uname -a
|
uname -a
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
uppercased
|
uppercased
|
||||||
</p>
|
</p>
|
||||||
<pre class="src src-bash">
|
<div class="src src-bash">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
uname -a
|
uname -a
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h2 id="headline-24">
|
<h2 id="headline-24">
|
||||||
|
@ -463,7 +463,7 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
|
||||||
<h3 id="headline-26">
|
<h3 id="headline-26">
|
||||||
<a href="https://github.com/gohugoio/hugo/issues/4006">#4006</a> source code blocks in org not rendered correctly
|
<a href="https://github.com/gohugoio/hugo/issues/4006">#4006</a> source code blocks in org not rendered correctly
|
||||||
</h3>
|
</h3>
|
||||||
<pre class="src src-emacs-lisp">
|
<div class="src src-emacs-lisp">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
(defun small-shell ()
|
(defun small-shell ()
|
||||||
|
@ -474,7 +474,7 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
|
||||||
(ansi-term))
|
(ansi-term))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</pre>
|
</div>
|
||||||
<h1 id="headline-27">
|
<h1 id="headline-27">
|
||||||
Footnotes
|
Footnotes
|
||||||
</h1>
|
</h1>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue