How to get htmlize.el work for project publishing in Emacs org-mode?
Asked Answered
A

3

10

I want to publish a project in Emacs org-mode, which contains several .html files. There are some python code examples in them that I wanna highlight. But htmlize.el won't do that for me. Strangely, when exporting single .html file (using C-c C-e h), the code examples are highlighted . So how could I get htmlize.el work for project publishing?

Andersen answered 3/12, 2010 at 3:33 Comment(2)
Org-mode is a fast-moving target. Can you give more information about your setup? Specifically, what operating system you're using, what version of Emacs you're using and what version of Org-mode you're using would help me give some advice.Guardian
Do you have a solution that still works today? Adding :htmlized-source t as Dave Bacher suggested does not work for me. I have the most recent version of htmlize.el (1.56) installed, but still in the exactly same situation as you were.Compose
M
4

In your org-publish-project-alist, set the htmlized-source property to non-nil:

(setq org-publish-project-alist
      '(("my-project"
           :base-directory ...
           :htmlized-source t
             ...
       )))

See the Publishing action section of the Org-mode manual.

Mimas answered 3/12, 2010 at 18:54 Comment(1)
Thank you. I've made it this way~ :)Andersen
P
3

You have to put your code inside #+BEGIN_SRC and #+END_SRC . For example

* My python code
#+BEGIN_SRC python
def foo():
  if bar == 1:
     bar = 2
  else: 
     bar = 3
#+END_SRC
Pelagia answered 3/12, 2010 at 9:20 Comment(1)
I've tried this before, but it actually doesn't work. PuzzledAndersen
F
-1

using htmlize.el to highlight your code in orgfile, just add codes listed here to your .emacs file:

(require 'htmlize)

Notes: please make sure htmlize.el in your load-path

Fireeater answered 27/9, 2012 at 3:10 Comment(1)
It already works for a single file, the question is related to publishing.Apodal

© 2022 - 2024 — McMap. All rights reserved.