I've been trying to get the syntax highlighting to work when exporting org-mode formatted file to HTML, but none of what I've done so far has worked. I followed the Babel configuration guide but the code block on the generated HTML page still looks plain. I have also set (setq org-src-fontify-natively t)
. What am I missing?
Code block syntax highlighting in Org-mode's HTML export depends on the htmlize
library, which Org-mode's documentation says is included but may actually need to be installed separately:
If the example is source code from a programming language, or any other text that can be marked up by font-lock in Emacs, you can ask for the example to look like the fontified Emacs buffer¹¹⁹. This is done with the ‘
src
’ block, where you also need to specify the name of the major mode that should be used to fontify the example¹²⁰, see Easy Templates for shortcuts to easily insert code blocks.#+BEGIN_SRC emacs-lisp (defun org-xor (a b) "Exclusive or." (if a (not b) b)) #+END_SRC
...
¹¹⁹This works automatically for the HTML back-end (it requires version 1.34 of the
htmlize.el
package, which is distributed with Org). Fontified code chunks in LaTeX can be achieved using either the listings or the minted package. Refer toorg-latex-listings
documentation for details.
htmlize.el
is available via MELPA.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With