简体   繁体   中英

Emacs org-mode - Export to html without syntax highlighting

I'm using org-mode to write blog post(wordpress). Because I'm using a plugin for syntax highlighting, I don't need to use org-mode's syntax highlighting.

Here is example.

Source in emacs. 在此输入图像描述

Exported output. 在此输入图像描述

When I remove language field followed BEGIN_SRC , syntax highlighting is also disapeared. But I just want to disable syntax highlighting only when exporting without removing language field(emacs-lisp).

Also I tested below, but it does not work.

(setq org-src-fontify-natively t)

============ UPDATE ============

I applied below. (Thanks @Picaud Vincent) (setq org-html-htmlize-output-type 'nil)

It works fine with source block without language field. But It does not work with source block with language field.

here is example.

In .emacs file.. (setq org-html-htmlize-output-type 'nil)

  1. without language field origin

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

exported

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

  1. with language field origin

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

exported

 <div class="org-src-container"> <pre class="src src-emacs-lisp"></pre> 

============ UPDATE ============

Finally, I found solution.

  1. Follow @Picaud Vincent' answer. (setq org-html-htmlize-output-type nil)`

  2. If There is no code in source block with language field, add exports: code to language field. ex> #+BEGIN_SRC emacs-lisp:exports code

Although adding 'exports: code` disables syntax highlighting in org-mode buffer, but it solve my problem.

Maybe you can try to customize the org-html-htmlize-output-type variable:

Usual HTML export looks like:

在此输入图像描述

however, with this customization

(setq org-html-htmlize-output-type `nil)

you get plain text:

在此输入图像描述

This variable and other customizable ones are defined in the ox-html.el file.


Update: complete html sources

Before:

<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>

After:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM