【问题标题】:running `org-export-as-html' in emacs batch mode在 emacs 批处理模式下运行“org-export-as-html”
【发布时间】:2014-03-02 03:10:52
【问题描述】:

在批处理模式下使用 `org-export-as-html' 时,从代码块生成的 html 没有语法着色。

如何在批处理模式下启用语法着色?

编辑:

我从终端运行emacs --script make.el。 在 make.el 中,我包含 org 和 org-html 并最终调用 (org-export-as-html 3)

以下将加粗/下划线关键字但仍然没有颜色:

    (add-to-list 'load-path "~/elisp/org/contrib/lisp")
    (require 'htmlize)
    (setq c-standard-font-lock-fontify-region-function 'font-lock-default-fontify-region) ;; fixes bug
    (org-export-as-html 3)

编辑 2:

我尝试过的其他几件事 - 它们没有任何区别:

    (setq org-src-fontify-natively t)
    (org-babel-do-load-languages 'org-babel-load-languages '((java .t)))

我也尝试过加载我的整个 .emacs

我正在使用 GNU Emacs 24.3.1 和 Org 7.9.2

【问题讨论】:

  • 试试emacs --batch -l ~/.emacs ...
  • 您好,您可以发布您用于导出 html 的代码吗?我猜你不是requireing htmlize 库,这是导出语法突出显示的 html 所需要的
  • 您是否尝试加载htmlize,例如(load "~/elisp/org/contrib/lisp/htmlize")。这对我有用。

标签: emacs org-mode


【解决方案1】:

显然,如果您使用 color-theme 库,那么(出于我还不知道的神秘原因)在批处理模式下导出时,您可以通过 htmlize 获得彩色输出。

例如,评估要导出的 org 缓冲区中的以下代码使htmlize 使用通过主题定义的颜色,并且在以批处理模式和交互方式导出时都有效(通过创建临时框架并设置适当的颜色主题以避免弄乱包含要导出的 org 缓冲区的框架):

(require 'cl)                           ;for `lexical-let'

(add-hook
 ;; This is for org 8.x (use `org-export-first-hook' for earlier versions).
 (make-local-variable 'org-export-before-processing-hook)
 (lambda (backend)
   (add-to-list (make-local-variable 'load-path) (expand-file-name "./etc"))
   (require 'color-theme)
   (color-theme-initialize)

   (when (display-graphic-p)            ;Are we running in interactive mode?
     ;; If so, create a temporary frame to install the color theme used by
     ;; htmlize:
     (lexical-let ((buff (switch-to-buffer-other-frame (current-buffer)))
                   (frame (selected-frame)))
       (setq color-theme-is-global nil)
       (make-frame-invisible frame)
       ;; Schedule deletion of temporary frame:
       (add-to-list
        ;; The following is for org 8.x (earlier versions use other hooks like
        ;; `org-latex-final-hook').
        (make-local-variable 'org-export-filter-final-output-functions)
        (lambda (string backend info) (delete-frame frame)))))

   ;; Install color theme.
   (color-theme-blippblopp)))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多