~jakob/ox-haunt

699f4383447f40d038abd5498412d147da91b563 — Jakob L. Kreuze 5 years ago 20d397d
Add replacement for 'ox-html-src-block
1 files changed, 45 insertions(+), 0 deletions(-)

M ox-haunt.el
M ox-haunt.el => ox-haunt.el +45 -0
@@ 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 <code> 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 "<pre><code class=\"example\"%s>\n%s</code></pre>" label code)
	    (format "<div class=\"org-src-container\">\n%s%s\n</div>"
		        ;; Build caption.
		        (let ((caption (org-export-get-caption src-block)))
		          (if (not caption) ""
		            (let ((listing-number
			               (format
			                "<span class=\"listing-number\">%s </span>"
			                (format
			                 (org-html--translate "Listing %d:" info)
			                 (org-export-get-ordinal
			                  src-block info nil #'org-html--has-caption-p)))))
		              (format "<label class=\"org-src-name\">%s%s</label>"
			                  listing-number
			                  (org-trim (org-export-data caption info))))))
		        ;; Contents.
		        (if klipsify
		            (format "<pre><code class=\"src language-%s\"%s%s>%s</code></pre>"
			                lang
			                label
			                (if (string= lang "html")
				                " data-editor-type=\"html\""
			                  "")
			                code)
		          (format "<pre><code class=\"src language-%s\"%s>%s</code></pre>"
                          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))