Emacs org-mode - 导出为不带语法高亮的html

5

我正在使用org-mode编写博客文章(wordpress)。因为我使用了一个语法高亮插件,所以不需要使用org-mode的语法高亮。

这里是一个例子。

在emacs中的源代码。 enter image description here

导出的输出结果。 enter image description here

当我删除BEGIN_SRC后面的语言字段时,语法高亮也会消失。但我只想在导出时禁用语法高亮而不删除语言字段(emacs-lisp)。

我也测试了以下内容,但它不起作用。

(setq org-src-fontify-natively t)

============ 更新 ============

我应用了以下内容。(感谢@Picaud Vincent) (setq org-html-htmlize-output-type 'nil)

它可以正确地处理没有语言字段的源代码块。但是,在有语言字段的源代码块中,它不能正常工作。

这里是一个例子。

在.emacs文件中。 (setq org-html-htmlize-output-type 'nil)

  1. 没有语言字段的情况下 原始

#+BEGIN_SRC
      (setq org-todo-keywords
            '((sequence "TODO" "FEEDBACK" "VERIFY" "|" "DONE" "DELEGATED")))
#+END_SRC

导出

<pre class="example">
    (setq org-todo-keywords
          '((sequence "TODO" "FEEDBACK" "VERIFY" "|" "DONE" "DELEGATED")))
</pre>

  1. 带有语言字段 原始数据

#+BEGIN_SRC emacs-lisp
      (setq org-todo-keywords
            '((sequence "TODO" "FEEDBACK" "VERIFY" "|" "DONE" "DELEGATED")))
#+END_SRC

导出

<div class="org-src-container">

<pre class="src src-emacs-lisp"></pre>

============ 更新 ============

最终,我找到了解决方案。

  1. 按照@Picaud Vincent的回答操作。 (setq org-html-htmlize-output-type nil)

  2. 如果源代码块中没有语言字段的代码,请在语言字段中添加exports: code。 例如:#+BEGIN_SRC emacs-lisp:exports code

虽然添加“exports:code”会禁用org-mode缓冲区中的语法高亮,但它解决了我的问题。


太棒了!感谢您接受了我的(不完整的)答案并进行了澄清!我没有意识到:exports code的影响。 - Picaud Vincent
也许有帮助。在文件开头加上>>#+PROPERTY: header-args :exports code<<(然后在此行上按C-c C-c以更新配置),您就不需要为每个代码块重复它。 - Picaud Vincent
1个回答

6
也许您可以尝试自定义org-html-htmlize-output-type变量:
通常的HTML导出看起来像:

enter image description here

然而,通过这种定制化。
(setq org-html-htmlize-output-type `nil)

您获得纯文本:

enter image description here

这个变量和其他可定制的变量在ox-html.el文件中被定义。

更新:完整的HTML源代码

之前:

<div class="org-src-container">
<pre class="src src-emacs-lisp">(<span style="color: #a020f0;">defcustom</span> <span style="color: #a0522d;">org-html-htmlize-output-type</span> 'inline-css
  <span style="color: #8b2252;">"Output type to be used by htmlize when formatting code snippets.</span>
<span style="color: #8b2252;">Choices are `</span><span style="color: #008b8b;">css</span><span style="color: #8b2252;">' to export the CSS selectors only,`</span><span style="color: #008b8b;">inline-css</span><span style="color: #8b2252;">'</span>
<span style="color: #8b2252;">to export the CSS attribute values inline in the HTML or `</span><span style="color: #008b8b;">nil</span><span style="color: #8b2252;">' to</span>
<span style="color: #8b2252;">export plain text.  We use as default `</span><span style="color: #008b8b;">inline-css</span><span style="color: #8b2252;">', in order to</span>
<span style="color: #8b2252;">make the resulting HTML self-containing.</span>

<span style="color: #8b2252;">However, this will fail when using Emacs in batch mode for export, because</span>
<span style="color: #8b2252;">then no rich font definitions are in place.  It will also not be good if</span>
<span style="color: #8b2252;">people with different Emacs setup contribute HTML files to a website,</span>
<span style="color: #8b2252;">because the fonts will represent the individual setups.  In these cases,</span>
<span style="color: #8b2252;">it is much better to let Org/Htmlize assign classes only, and to use</span>
<span style="color: #8b2252;">a style file to define the look of these classes.</span>
<span style="color: #8b2252;">To get a start for your css file, start Emacs session and make sure that</span>
<span style="color: #8b2252;">all the faces you are interested in are defined, for example by loading files</span>
<span style="color: #8b2252;">in all modes you want.  Then, use the command</span>
<span style="color: #8b2252;">`\\[</span><span style="color: #008b8b;">org-html-htmlize-generate-css</span><span style="color: #8b2252;">]' to extract class definitions."</span>
  <span style="color: #483d8b;">:group</span> 'org-export-html
  <span style="color: #483d8b;">:type</span> '(choice (const css) (const inline-css) (const nil)))

(<span style="color: #a020f0;">defcustom</span> <span style="color: #a0522d;">org-html-htmlize-font-prefix</span> <span style="color: #8b2252;">"org-"</span>
  <span style="color: #8b2252;">"The prefix for CSS class names for htmlize font specifications."</span>
  <span style="color: #483d8b;">:group</span> 'org-export-html
  <span style="color: #483d8b;">:type</span> 'string)
</pre>
</div>

之后:

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defcustom org-html-htmlize-output-type 'inline-css
  "Output type to be used by htmlize when formatting code snippets.
Choices are `css' to export the CSS selectors only,`inline-css'
to export the CSS attribute values inline in the HTML or `nil' to
export plain text.  We use as default `inline-css', in order to
make the resulting HTML self-containing.

However, this will fail when using Emacs in batch mode for export, because
then no rich font definitions are in place.  It will also not be good if
people with different Emacs setup contribute HTML files to a website,
because the fonts will represent the individual setups.  In these cases,
it is much better to let Org/Htmlize assign classes only, and to use
a style file to define the look of these classes.
To get a start for your css file, start Emacs session and make sure that
all the faces you are interested in are defined, for example by loading files
in all modes you want.  Then, use the command
`\\[org-html-htmlize-generate-css]' to extract class definitions."
  :group 'org-export-html
  :type '(choice (const css) (const inline-css) (const nil)))

(defcustom org-html-htmlize-font-prefix "org-"
  "The prefix for CSS class names for htmlize font specifications."
  :group 'org-export-html
  :type 'string)
</pre>
</div>

谢谢您的友好回答!我尝试了您的解决方案,但在评估您的建议后,生成了如下的空代码块。<div class="org-src-container"> <pre class="src src-emacs-lisp"></pre> - Lee Jeongmin
@LeeJeongmin 您好。我进行了再次测试,并更新了我的回答,包括HTML源代码。我自己测试过没有问题,但很抱歉不确定为什么在您这里无法正常运行,我的Org-mode版本为9.1.1。 - Picaud Vincent
@LeeJeongmin 也许你可以检查一下 nil 前面是不是有 '`' 符号,否则我也不知道了,抱歉。 - Picaud Vincent
我尝试过使用'nil'和"nil",但结果相同。你的答案看起来是解决我的问题的正确方法,但我不知道为什么它对我不起作用。我会再仔细查看一下。非常感谢你的回答。 - Lee Jeongmin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接