2

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

3

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" pygments-path (or (org-element-property :language code) "") temp-source-file))) (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" 
1
  • Can you post the code here, please? Commented May 15, 2017 at 14:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.