I would like to use Emacs in batch mode to export a number of org files to HTML from the command-line. And I would like to get the same result than interactively using C-cC-eh, in particular:
- honor file-local variables (such as
org-export-publishing-directory) - honor all options specified through
#+KEYWORD:headlines
Starting from the example given in org-export-as-html-batch, I got to this point:
emacs --batch \
--visit=/tmp/foo.org \
--eval "(defun safe-local-variable-p (sym val) t)" \
--funcall hack-local-variables \
--eval "(setq org-export-headline-levels 4)" \
--funcall org-export-as-html-batch
However, some problems remain:
-
I need to explicitly specify the headline level and I fail to see why all other
#+OPTIONSare honored (liketoc:nil) but not this one -
I had to manually trigger file-local variables parsing using
hack-local-variables(I guess it is not automatically done in batch mode) but more importantly I had to resort to a hack to mark all local variables as safe (I’m sure there is much space for improvement here).
NB:
In case it matters, I’m using emacs 23.2.1 (Debian Squeeze flavour)
Here is a sample org file on which I tested this:
#+TITLE: Foo
#+OPTIONS: H:4 toc:nil author:nil
* 1
** 2
*** 3
**** 4
# Local Variables:
# org-export-publishing-directory: "/some/where";
# End:
I eventually got the following script, which seems to fulfill all my requirements:
A few notes on this script:
The executable emacs-lisp script trick comes from this question.
The only way I found to use the
org-export-headline-levelsvalue from the#+OPTIONS:headline is to callorg-export-as-htmlinteractively, instead oforg-export-as-html-batch.hack-local-variablesdoes not need to be explicitly called, provided that local variables are marked as safe before the file is opened.I think it is better to only mark org-related variables as safe, using the
safe-local-variablesymbol property.