I'm using the org-mode reader for Pelican to generate articles for my blog (Export to HTML). Code blocks in Markdown version of the article look perfect but I cannot enable Pygments for org-mode.

Is there any way to process org-mode code blocks using Pygments?

P.S I know about Pandoc but I need a more emacs-way solution to be able to customize export options using Emacs Lisp, not Haskell.

1 Answer 1


I've found the solution to my issue and described full explanation in my blog.

In a few words, I've created custom export backend and pass the block contents to an external script.

(require 'org)
(require 'ox)
(require 'ox-html)

;; Path for pygments or command name
(defvar pygments-path "pygmentize")

(defun pygments-org-html-code (code contents info)
  ;; Generating tmp file path.
  ;; Current date and time hash will ideally pass our needs.
  (setq temp-source-file (format "/tmp/pygmentize-%s.txt"(md5 (current-time-string))))
  ;; Writing block contents to the file.
  (with-temp-file temp-source-file (insert (org-element-property :value code)))
  ;; Exectuing the shell-command an reading an output
  (shell-command-to-string (format "%s -l \"%s\" -f html %s"
                   (or (org-element-property :language code)

(org-export-define-derived-backend 'pelican-html 'html
  :translate-alist '((src-block .  pygments-org-html-code)
             (example-block . pygments-org-html-code)))

You can use these org reader variables to load the emacs functions in pelican:

ORG_READER_EMACS_SETTINGS = os.path.abspath('lisp/config.el')
ORG_READER_BACKEND = "'pelican-html"
  • Can you post the code here, please?
    – Dan
    May 15, 2017 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.