Why i wrote?
이맥스 org-mode에서 Jekyll을 위한 포스팅 html 추출 시 code highlight가 적용되지 않아 인식 되는 ccode 를 추출해야함

현재 블러그는 Jekyll로 되어있습니다. 기존 2.0에서 3.0으로 마이그레이션, 확인 결과 rouge 사용.
CSS class인식 문제로 아래와 같이 템플릿을 수정하여 사용해보도록 하겠습니다.

org html 추출 템플릿 수정하기

  1. M-x
  2. C-h f
  3. org-html-src-block 을 누르면 아래와 같은 함수 설명이 나온다.
org-html-export-block is a Lisp closure in ‘ox-html.el’.
(org-html-export-block EXPORT-BLOCK CONTENTS INFO)
Transcode a EXPORT-BLOCK element from Org to HTML.
CONTENTS is nil.  INFO is a plist holding contextual information.

[back]

설명에서 org-html.el을 눌러 org-html-src-block을 찾아 아래와 같이 수정해주자.

(defun org-html-src-block (src-block _contents info)
  "Transcode a SRC-BLOCK element from Org to HTML.
CONTENTS holds the contents of the item.  INFO is a plist holding
contextual information."
  (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 class=\"example\"%s>\n%s</pre>" label code)
  (format "%s%s"
    ;; 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 "<div class=\"language-%s highlighter-rouge\"%s%s><div class=\"highlight\"><pre class=\"highlight\"><code>%s</code></pre></div></div>"
          lang
          label
          (if (string= lang "html")
        " data-editor-type=\"html\""
            "")
          code)
      (format "<div class=\"language-%s highlighter-rouge\"%s><div class=\"highlight\"><pre class=\"highlight\"><code>%s</code></pre></div></div>"
                          lang label code)))))))