0

バッチorgモードでEmacsを使用して、コマンドラインから多数のファイルをHTMLにエクスポートしたいと思います。C-cC-ehそして、特に、インタラクティブに使用するのと同じ結果を得たいと思います。

  • ファイルを尊重する-ローカル変数(などorg-export-publishing-directory
  • #+KEYWORD:見出しで指定されたすべてのオプションを尊重する

で与えられた例から始めてorg-export-as-html-batch、私はこの点に到達しました:

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

ただし、いくつかの問題が残っています。

  • 見出しのレベルを明示的に指定する必要がありますが、他のすべてが(のように)#+OPTIONS尊重される理由がわかりませんが、これはそうではありませんtoc:nil

  • を使用してファイルローカル変数の解析を手動でトリガーする必要がhack-local-variablesありましたが(バッチモードでは自動的に実行されないと思います)、さらに重要なことに、すべてのローカル変数を安全としてマークするためにハックに頼らなければなりませんでした(ここで改善)。


注意

重要な場合は、emacs 23.2.1(Debian Squeezeフレーバー)を使用しています

orgこれは私がこれをテストしたサンプルファイルです:

#+TITLE: Foo
#+OPTIONS: H:4 toc:nil author:nil

* 1
** 2
*** 3
**** 4

# Local Variables:
#  org-export-publishing-directory: "/some/where";
# End:
4

1 に答える 1

1

最終的に、次のスクリプトを取得しました。これは、すべての要件を満たしているようです。

#!/bin/sh
":"; exec emacs --script "$0" -- "$@" # -*-emacs-lisp-*-
;; 
;; Usage:
;;    org2html FILE1 [FILE2 ...]


;; Mark org-related variables as safe local variables,
;; regardless of their value.
(defun my/always-safe-local-variable (val) t)
(dolist (sym '(org-export-publishing-directory
               org-export-html-preamble
               org-export-html-postamble))
  (put sym 'safe-local-variable 'my/always-safe-local-variable))


(defun my/org-export-as-html (filename)
  "Export FILENAME as html, as if `org-export-to-html' had been called
interactively.

This ensures that `org-export-headline-levels' is correctly read from
the #+OPTIONS: headline."
  (save-excursion
    (find-file filename)
    (message "Exporting file `%s' to HTML" filename)
    (call-interactively 'org-export-as-html)))

(mapcar 'my/org-export-as-html
        (cdr argv)) ;; "--" is the first element of argv

このスクリプトに関する注意事項:

  • 実行可能な emacs-lisp スクリプトのトリックは、この質問から来ています。

  • org-export-headline-levels見出しの値を使用する唯一の方法は、の代わりにインタラクティブ#+OPTIONS:に呼び出すことです。org-export-as-htmlorg-export-as-html-batch

  • hack-local-variablesファイルを開く前にローカル変数が安全であるとマークされていれば、明示的に呼び出す必要はありません。

  • safe-local-variablesymbol プロパティを使用して、組織関連の変数のみを安全としてマークする方がよいと思います。

于 2013-01-03T21:21:20.700 に答える