简体   繁体   English

emacs orgmode中#+ begin_src块内的语法突出显示无法正常工作

[英]Syntax highlighting within #+begin_src block in emacs orgmode not working

I have tried many different languages and copied various examples, but none of my code blocks within orgmode get syntax highlighting. 我尝试了很多不同的语言并复制了各种示例,但orgmode中的代码块都没有得到语法高亮。 Here is what I'm trying: 这是我正在尝试的:

#+begin_src python

def main():
  print "Hello %s" % ("what's the problem")

#+end_src

#+begin_src c++

for (int i = 0; i < 30; i++) 
{
  cout << "Hello" << endl;
}

#+end_src

When exported to HTML, it shows up in a source code block, but with no highlighting there either. 导出到HTML时,它会显示在源代码块中,但也没有突出显示。

I am using the newest org (7.8.10). 我正在使用最新的组织(7.8.10)。 Am I missing something here? 我在这里错过了什么吗?

你有这个吗?

(setq org-src-fontify-natively t)

I had a similar problem where despite adding htmlize.el, I couldn't get the code syntax highlighting when exporting to html. 我有一个类似的问题,尽管添加了htmlize.el,但是在导出到html时我无法获得代码语法突出显示。 I then found this very useful post and just followed the steps: 然后我发现这个非常有用的帖子,只是按照步骤:

Syntax highlighting R code in WordPress using Emacs 使用Emacs在WordPress中突出显示R代码的语法

Just to reiterate the steps: 只是重申一下步骤:

  1. I copied the htmlize.el in ~/.emacs.d/ directory 我在〜/ .emacs.d /目录中复制了htmlize.el
  2. In org mode, typed Mx byte-compile-file and navigate to the directory where the htmlize.el is located, select it and press enter. 在组织模式下,键入Mx byte-compile-file并导航到htmlize.el所在的目录,选择它并按Enter键。 This will compile the htmlize.el file. 这将编译htmlize.el文件。
  3. Restart emacs and export a file with code block in it. 重新启动emacs并导出包含代码块的文件。 The exported html file will now have syntax highlighted code. 导出的html文件现在将具有语法突出显示的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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