2

I have set org-src-fontify-natively to t, and have htmlize installed. But my example blocks still don't have syntax highlighting when exported to HTML.

#+begin_example python
print(8*8)
#+end_example

My current workaround is to use :eval never with source blocks instead:

#+BEGIN_SRC python :eval never
def hello_world():
    print("Hello, world!")
#+END_SRC

1 Answer 1

-1

TLDR: use SRC blocks for syntax highlighting exports. When I have to export code that I want highlighted, I use SRC blocks.

The documentation says the following :

You can include literal examples that should not be subjected to markup. Such examples are typeset in monospace, so this is well suited for source code and similar examples.

#+BEGIN_EXAMPLE
 Some example from a text file.
#+END_EXAMPLE

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

#+BEGIN_SRC emacs-lisp
  (defun org-xor (a b)
    "Exclusive or."
    (if a (not b) b))
 #+END_SRC

It's true that this does not talk explicitly about exporting, but this is supported by the CSS support documentation which tells you that you can customize the following CSS classes:

pre.src     formatted source code
pre.example normal example

So, what is happening for you is the expected behavior, and what you consider a workaround is what is recommended. You only need :eval never if you are routinely evaluating all the code in the file, in literate programming style. If you don't do that, you should not need to add that flag.

The main reason for this is that EXAMPLE blocks don't use attributes, so whereas BEGIN_SRC python is a hint that we should be using Python syntax highlighting (which is to say, here is how you recognize the various bits of syntax), BEGIN_EXAMPLE python is just meaningless since it's .. monospaced, without markup.

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.