Skip to content

Commit 0a784ff

Browse files
committed
fix(orgmode): use org-export-unravel-code to handle indentation
1 parent 6ac28db commit 0a784ff

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

v8/orgmode/init.el

+15-29
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@
3232
(expand-file-name "macros.org" (file-name-directory load-file-name)))
3333
(org-macro--collect-macros)))
3434

35-
;;; Code highlighting
36-
(defun org-html-decode-plain-text (text)
37-
"Convert HTML character to plain TEXT. i.e. do the inversion of
38-
`org-html-encode-plain-text`. Possible conversions are set in
39-
`org-html-protect-char-alist'."
40-
(mapc
41-
(lambda (pair)
42-
(setq text (replace-regexp-in-string (cdr pair) (car pair) text t t)))
43-
(reverse org-html-protect-char-alist))
44-
text)
45-
4635
;; Use pygments highlighting for code
4736
(defun pygmentize (lang code)
4837
"Use Pygments to highlight the given code and return the output"
@@ -64,7 +53,8 @@
6453
("clojure" . "clojure")
6554
("css" . "css")
6655
("d" . "d")
67-
("emacs-lisp" . "scheme")
56+
("emacs-lisp" . "emacs-lisp")
57+
("elisp" . "elisp")
6858
("F90" . "fortran")
6959
("gnuplot" . "gnuplot")
7060
("groovy" . "groovy")
@@ -98,20 +88,16 @@ See: http://orgmode.org/worg/org-contrib/babel/languages.html and
9888
http://pygments.org/docs/lexers/ for adding new languages to the mapping.")
9989

10090
;; Override the html export function to use pygments
101-
(defun org-html-src-block (src-block contents info)
91+
(define-advice org-html-src-block (:around (old-src-block src-block contents info))
10292
"Transcode a SRC-BLOCK element from Org to HTML.
10393
CONTENTS holds the contents of the item. INFO is a plist holding
10494
contextual information."
105-
(if (org-export-read-attribute :attr_html src-block :textarea)
106-
(org-html--textarea-block src-block)
107-
(let ((lang (org-element-property :language src-block))
108-
(code (org-element-property :value src-block))
109-
(code-html (org-html-format-code src-block info)))
110-
(if nikola-use-pygments
111-
(progn
112-
(unless lang (setq lang ""))
113-
(pygmentize (downcase lang) (org-html-decode-plain-text code)))
114-
code-html))))
95+
(if (or (not nikola-use-pygments)
96+
(org-export-read-attribute :attr_html src-block :textarea))
97+
(funcall old-src-block src-block contents info)
98+
(let ((lang (or (org-element-property :language src-block) ""))
99+
(code (car (org-export-unravel-code src-block))))
100+
(pygmentize (downcase lang) code))))
115101

116102
;; Export images with custom link type
117103
(defun org-custom-link-img-url-export (path desc format)
@@ -129,12 +115,12 @@ contextual information."
129115

130116
;; Support for magic links (link:// scheme)
131117
(org-link-set-parameters
132-
"link"
133-
:export (lambda (path desc backend)
134-
(cond
135-
((eq 'html backend)
136-
(format "<a href=\"link:%s\">%s</a>"
137-
path (or desc path))))))
118+
"link"
119+
:export (lambda (path desc backend)
120+
(cond
121+
((eq 'html backend)
122+
(format "<a href=\"link:%s\">%s</a>"
123+
path (or desc path))))))
138124

139125
;; Export function used by Nikola.
140126
(defun nikola-html-export (infile outfile)

0 commit comments

Comments
 (0)