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 {
|
||||
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":
|
||||
w.WriteString(`<pre class="example">` + "\n" + content + "\n</pre>\n")
|
||||
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>
|
||||
<pre class="src src-bash">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
echo "a bash source block"
|
||||
|
@ -10,15 +11,18 @@ function hello {
|
|||
hello
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<figcaption>
|
||||
block caption
|
||||
</figcaption>
|
||||
</figure>
|
||||
<pre class="src src-text">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
a source block without a language
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<pre class="example">
|
||||
an example block with
|
||||
multiple lines including
|
||||
|
@ -120,11 +124,13 @@ this unindented line is outside of the list item
|
|||
<p>
|
||||
list item 2
|
||||
</p>
|
||||
<pre class="src src-text">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
#+BEGIN_EXAMPLE
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<p>
|
||||
#+END_EXAMPLE
|
||||
</p>
|
||||
|
|
2
org/testdata/captions.html
vendored
2
org/testdata/captions.html
vendored
|
@ -2,11 +2,13 @@
|
|||
Anything can be captioned.
|
||||
</p>
|
||||
<figure>
|
||||
<pre class="src src-sh">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
echo "i have a caption!"
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<figcaption>
|
||||
captioned soure block
|
||||
</figcaption>
|
||||
|
|
2
org/testdata/footnotes.html
vendored
2
org/testdata/footnotes.html
vendored
|
@ -70,11 +70,13 @@ and other elements
|
|||
<p>
|
||||
like blocks
|
||||
</p>
|
||||
<pre class="src src-text">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
other non-plain
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
|
|
2
org/testdata/headlines.html
vendored
2
org/testdata/headlines.html
vendored
|
@ -68,9 +68,11 @@ headline with custom status
|
|||
<p>
|
||||
it's possible to use <code class="verbatim">#+SETUPFILE</code> - in this case the setup file contains the following
|
||||
</p>
|
||||
<pre class="src src-org">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
#+TODO: TODO DONE CUSTOM
|
||||
#+EXCLUDE_TAGS: noexport custom_noexport
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
|
|
3
org/testdata/keywords.html
vendored
3
org/testdata/keywords.html
vendored
|
@ -1,8 +1,9 @@
|
|||
<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>
|
||||
</div>
|
||||
</pre>
|
||||
<figcaption>
|
||||
and <span style="text-decoration: underline;">multiple</span> lines of <strong>captions</strong>!
|
||||
</figcaption>
|
||||
|
|
4
org/testdata/lists.html
vendored
4
org/testdata/lists.html
vendored
|
@ -59,11 +59,13 @@ and some lines of text
|
|||
<p>
|
||||
and another subitem
|
||||
</p>
|
||||
<pre class="src src-sh">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
echo with a block
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
|
@ -131,11 +133,13 @@ term<dd>
|
|||
details on a new line (with an empty line in between)
|
||||
<strong>continued</strong>
|
||||
</p>
|
||||
<pre class="src src-bash">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
echo "Hello World!"
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<dd>
|
||||
</dl>
|
||||
<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>
|
||||
src block
|
||||
</p>
|
||||
<pre class="src src-org">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
#+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:=.
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
|
@ -390,11 +392,13 @@ inline code <code class="verbatim">--</code> <code class="verbatim">---</code> a
|
|||
<p>
|
||||
src/example/export blocks should not be converted!
|
||||
</p>
|
||||
<pre class="src src-sh">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
--, ---
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<pre class="example">
|
||||
--, ---
|
||||
</pre>
|
||||
|
@ -423,21 +427,25 @@ The behaviour of Org mode <code class="verbatim"><s TAB</code> changed and it
|
|||
<p>
|
||||
lowercased:
|
||||
</p>
|
||||
<pre class="src src-bash">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
uname -a
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
uppercased
|
||||
</p>
|
||||
<pre class="src src-bash">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
uname -a
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
</li>
|
||||
</ul>
|
||||
<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">
|
||||
<a href="https://github.com/gohugoio/hugo/issues/4006">#4006</a> source code blocks in org not rendered correctly
|
||||
</h3>
|
||||
<pre class="src src-emacs-lisp">
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
(defun small-shell ()
|
||||
|
@ -465,6 +474,7 @@ When inserting an image link like <img src="/home/amos/Pictures/Screenshots/img-
|
|||
(ansi-term))
|
||||
</pre>
|
||||
</div>
|
||||
</pre>
|
||||
<h1 id="headline-27">
|
||||
Footnotes
|
||||
</h1>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue