When I export an elisp source code block to html, the indentation of the code gets messed up. I've tried calling (setq org-src-preserve-indentation t)
, but that didn't help. I imagine there is perhaps something in my code that is being wrongly interpreted by org-html-publish-to-html
?
As a minimum working example, I try exporting the following org file:
#+TITLE: Test
Let's check the html output of this file...
#+BEGIN_SRC elisp :tangle yes
(setq org-publish-project-alist
`(("index"
:with-title nil :base-directory "~/website/org/"
:base-extension "org" :publishing-directory "~/website/public/html/"
:headline-levels 3 :section-numbers nil
:publishing-function org-html-publish-to-html :with-toc nil
:html-head ,index-html-extra-head
:html-head-include-default-style nil
:html-head-include-scripts nil
:html-preamble nil :html-postamble t)))
#+END_SRC
and as a result comes out the following (notice how the code gets 4 tabs of indentation starting from the 3rd line):
HTML here, in case it helps...:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2016-01-19 Tue 00:08 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Test</title>
<meta name="generator" content="Org-mode" />
<meta name="author" content="name" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
pre.src-sh:before { content: 'sh'; }
pre.src-bash:before { content: 'sh'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-R:before { content: 'R'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-java:before { content: 'Java'; }
pre.src-sql:before { content: 'SQL'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
/*]]>*/-->
</style>
</head>
<body>
<div id="content">
<h1 class="title">Test</h1>
<p>
Let's check the html output of this file.
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #268bd2;">(</span><span style="color: #859900;">setq</span> org-publish-project-alist
`<span style="color: #2aa198;">(</span><span style="color: #b58900;">(</span><span style="color: #2aa198;">"index"</span>
<span style="color: #859900;">:with-title</span> nil <span style="color: #859900;">:base-directory</span> <span style="color: #2aa198;">"~/website/org/"</span>
<span style="color: #859900;">:base-extension</span> <span style="color: #2aa198;">"org"</span> <span style="color: #859900;">:publishing-directory</span> <span style="color: #2aa198;">"~/website/public/html/"</span>
<span style="color: #859900;">:headline-levels</span> 3 <span style="color: #859900;">:section-numbers</span> nil
<span style="color: #859900;">:publishing-function</span> org-html-publish-to-html <span style="color: #859900;">:with-toc</span> nil
<span style="color: #859900;">:html-head</span> ,index-html-extra-head
<span style="color: #859900;">:html-head-include-default-style</span> nil
<span style="color: #859900;">:html-head-include-scripts</span> nil
<span style="color: #859900;">:html-preamble</span> nil <span style="color: #859900;">:html-postamble</span> t<span style="color: #b58900;">)</span><span style="color: #2aa198;">)</span><span style="color: #268bd2;">)</span>
</pre>
</div>
</div>
</body>
</html>
Emacs 25 with latest org-mode.
How to get the indentation correctly?!
C-'
on the code block and then select all and indent? The code seems to be shifted one colon to the left from where it would normally be. Not sure this is a problem, but you never know...org-publish-project-alist
and my css files. I also switched to spacemacs some time ago, and the problem kinda dissapeared. Did you find anything in the meantime?