From 699f4383447f40d038abd5498412d147da91b563 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Tue, 30 Apr 2019 14:35:48 -0400 Subject: Add replacement for 'ox-html-src-block --- ox-haunt.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'ox-haunt.el') diff --git a/ox-haunt.el b/ox-haunt.el index c99ed5b..631c54b 100644 --- a/ox-haunt.el +++ b/ox-haunt.el @@ -42,6 +42,7 @@ (org-open-file (ox-haunt-export-to-html nil s v b))))))) :translate-alist '((link . ox-haunt-link) + (src-block . ox-haunt-src-block) (template . ox-haunt-template)) :options-alist '((:hugo-base-dir "HAUNT_BASE_DIR" nil nil))) @@ -72,6 +73,50 @@ valid executable." (unless (file-directory-p dest-path) (user-error "The HAUNT_BASE_DIR property must name a directory"))) +;; From the W3 HTML 5.2 Specification: +;; +;; "Authors who wish to mark elements with the language used, e.g., so +;; that syntax highlighting scripts can use the right rules, can use the class +;; attribute, e.g., by adding a class prefixed with "language-" to the element." +(defun ox-haunt-src-block (src-block _contents info) + "Transcode a SRC-BLOCK element from Org to HTML." + (if (org-export-read-attribute :attr_html src-block :textarea) + (org-html--textarea-block src-block) + (let* ((lang (org-element-property :language src-block)) + (code (org-html-format-code src-block info)) + (label (let ((lbl (and (org-element-property :name src-block) + (org-export-get-reference src-block info)))) + (if lbl (format " id=\"%s\"" lbl) ""))) + (klipsify (and (plist-get info :html-klipsify-src) + (member lang '("javascript" "js" + "ruby" "scheme" "clojure" "php" "html"))))) + (if (not lang) (format "
\n%s
" label code) + (format "
\n%s%s\n
" + ;; Build caption. + (let ((caption (org-export-get-caption src-block))) + (if (not caption) "" + (let ((listing-number + (format + "%s " + (format + (org-html--translate "Listing %d:" info) + (org-export-get-ordinal + src-block info nil #'org-html--has-caption-p))))) + (format "" + listing-number + (org-trim (org-export-data caption info)))))) + ;; Contents. + (if klipsify + (format "
%s
" + lang + label + (if (string= lang "html") + " data-editor-type=\"html\"" + "") + code) + (format "
%s
" + lang label code))))))) + (defun ox-haunt-link (link desc info) "Transcode a LINK object from Org to HTML." (let* ((orig-path (org-element-property :path link)) -- cgit v1.3