org-mode 转 html 时用 htmlize.el 高亮代码, 无效

org-mode中代码段的内容如下:

#+begin_src bash
cd ~
ls -la
find . -name .bashrc
#+end_src

html的实际显示效果如下:

html文件中代码段的内容如下:

<div class="org-src-container">
<pre class="src src-bash"><span class="org-builtin">cd</span> ~
ls -la
find . -name .bashrc
</pre>
</div>

感觉htmlize.el没有起作用. 软件和插件版本如下: Emacs version: 26.1, Org-mode version: 9.1.9, htmlize.el version: 1.55

.emacs中的配置如下:

(require 'htmlize)
(setq org-src-fontify-natively t)
;; (setq org-html-htmlize-output-type 'css)

...

(let ((org-publish-project-alist
       '(("images"
          :base-directory "src"
          :base-extension "jpg\\|png\\|c\\|gif"
          :publishing-directory "html"
          :recursive t
          :htmlized-source t
          :publishing-function org-publish-attachment)
         ("static"
          :base-directory "static"
          :base-extension "jpg\\|png\\|c\\|gif\\|css\\|js\\|html\\|ttf\\|svg\\|otf\\|eot\\|woff\\|woff2"
          :publishing-directory "html/static"
          :recursive t
          :htmlized-source t
          :publishing-function org-publish-attachment)
         ("wiki-src"
          :base-directory "src"
          :base-extension "org"
          :publishing-directory "html"
          :recursive t
          :htmlized-source t
          :publishing-function org-html-publish-to-html
          :headline-levels 4)
         ("wiki-project" :components ("wiki-src" "static" "images"))))
      ;;; 设置CSS样式
      ;; (org-html-head-extra "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/css/test.css\" />")
      (org-html-head-extra "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/css/bootstrap-fontawesome.css\" />")
      ;;; 取消默认的CSS
      (org-html-head-include-default-style nil)
      ;;; 取消默认的Javascript代码
      (org-html-head-include-scripts nil)
      ;;; XXX 用org-html-head可以设置<head>部分
      ;; (org-html-preamble (read-html-template "preamble.html"))
      (org-html-preamble (read-html-template "default.html"))
      ;; (org-html-postamble (read-html-template "postamble.html"))
      )
  ;;; 设置Mathjax库的路径
  (add-to-list 'org-html-mathjax-options '(path "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"))
  (org-publish-project "wiki-project"))

你的 org-html-htmlize-output-type 有问题,没有 t 这个选项,默认值是 inline-css

写错了, 感谢指出来, 已更正. 应该是 (setq org-src-fontify-natively t)

问题还是存在.

我猜你将 org-html-htmlize-output-type 设置为了 'css

检查一下外部的 css 文件 bootstrap-fontawesome.css 有没有包含 .org-builtin,可以用 org-html-htmlize-generate-css 生成并添加,或者依版主所说将它设置回默认值试试。

bootstrap-fontawesome.css里好像没有搜到 .org-builtin, 试着用 org-html-htmlize-generate-css生成一下, 结果报错: Invalid face: isearch-lazy-highlight-face.

google 了半天没有找到好的办法, 临时先放下了, 水平还不错.

isearch-lazy-highlight-face 已更名为 lazy-highlight

估计你使用了比较老的包或配置,定义 face 时 inherit 了 isearch-lazy-highlight-face

出错时可以看一下 *Backtrace* buffer,在 htmlize-face-size 这一行中应该可以找到该 face。

感谢提醒~~