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.
This commit is contained in:
parent
f1a747ad72
commit
37d33c1206
8 changed files with 30 additions and 2 deletions
|
@ -108,7 +108,8 @@ func (w *HTMLWriter) WriteBlock(b Block) {
|
||||||
if len(b.Parameters) >= 1 {
|
if len(b.Parameters) >= 1 {
|
||||||
lang = strings.ToLower(b.Parameters[0])
|
lang = strings.ToLower(b.Parameters[0])
|
||||||
}
|
}
|
||||||
w.WriteString(w.HighlightCodeBlock(content, lang) + "\n")
|
content = w.HighlightCodeBlock(content, lang)
|
||||||
|
w.WriteString(fmt.Sprintf("<pre class=\"src src-%s\">\n%s\n</pre>\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":
|
||||||
|
|
6
org/testdata/blocks.html
vendored
6
org/testdata/blocks.html
vendored
|
@ -1,4 +1,5 @@
|
||||||
<figure>
|
<figure>
|
||||||
|
<pre class="src src-bash">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
echo "a bash source block"
|
echo "a bash source block"
|
||||||
|
@ -10,15 +11,18 @@ function hello {
|
||||||
hello
|
hello
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
<figcaption>
|
<figcaption>
|
||||||
block caption
|
block caption
|
||||||
</figcaption>
|
</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
|
<pre 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>
|
||||||
<pre class="example">
|
<pre class="example">
|
||||||
an example block with
|
an example block with
|
||||||
multiple lines including
|
multiple lines including
|
||||||
|
@ -120,11 +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="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
#+BEGIN_EXAMPLE
|
#+BEGIN_EXAMPLE
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
#+END_EXAMPLE
|
#+END_EXAMPLE
|
||||||
</p>
|
</p>
|
||||||
|
|
2
org/testdata/captions.html
vendored
2
org/testdata/captions.html
vendored
|
@ -2,11 +2,13 @@
|
||||||
Anything can be captioned.
|
Anything can be captioned.
|
||||||
</p>
|
</p>
|
||||||
<figure>
|
<figure>
|
||||||
|
<pre 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>
|
||||||
<figcaption>
|
<figcaption>
|
||||||
captioned soure block
|
captioned soure block
|
||||||
</figcaption>
|
</figcaption>
|
||||||
|
|
2
org/testdata/footnotes.html
vendored
2
org/testdata/footnotes.html
vendored
|
@ -70,11 +70,13 @@ and other elements
|
||||||
<p>
|
<p>
|
||||||
like blocks
|
like blocks
|
||||||
</p>
|
</p>
|
||||||
|
<pre class="src src-text">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
other non-plain
|
other non-plain
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
|
|
2
org/testdata/headlines.html
vendored
2
org/testdata/headlines.html
vendored
|
@ -68,9 +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="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>
|
||||||
|
|
3
org/testdata/keywords.html
vendored
3
org/testdata/keywords.html
vendored
|
@ -1,8 +1,9 @@
|
||||||
<figure>
|
<figure>
|
||||||
<div class="highlight a b c d" id="it">
|
<pre 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>
|
||||||
<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>
|
||||||
|
|
4
org/testdata/lists.html
vendored
4
org/testdata/lists.html
vendored
|
@ -59,11 +59,13 @@ and some lines of text
|
||||||
<p>
|
<p>
|
||||||
and another subitem
|
and another subitem
|
||||||
</p>
|
</p>
|
||||||
|
<pre 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>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
|
@ -131,11 +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="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
echo "Hello World!"
|
echo "Hello World!"
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
<dd>
|
<dd>
|
||||||
</dl>
|
</dl>
|
||||||
<p>
|
<p>
|
||||||
|
|
10
org/testdata/misc.html
vendored
10
org/testdata/misc.html
vendored
|
@ -114,6 +114,7 @@ for now files can be included as:
|
||||||
<p>
|
<p>
|
||||||
src block
|
src block
|
||||||
</p>
|
</p>
|
||||||
|
<pre class="src src-org">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
#+SETUPFILE: setup_file_org
|
#+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:=.
|
By default =EXCLUDE_TAGS= is just =:noexport:=.
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
|
@ -390,11 +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="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
--, ---
|
--, ---
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
<pre class="example">
|
<pre class="example">
|
||||||
--, ---
|
--, ---
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -423,21 +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="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
uname -a
|
uname -a
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
uppercased
|
uppercased
|
||||||
</p>
|
</p>
|
||||||
|
<pre class="src src-bash">
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
uname -a
|
uname -a
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h2 id="headline-24">
|
<h2 id="headline-24">
|
||||||
|
@ -455,6 +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="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
(defun small-shell ()
|
(defun small-shell ()
|
||||||
|
@ -465,6 +474,7 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
|
||||||
(ansi-term))
|
(ansi-term))
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
</pre>
|
||||||
<h1 id="headline-27">
|
<h1 id="headline-27">
|
||||||
Footnotes
|
Footnotes
|
||||||
</h1>
|
</h1>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue