Jekyll简明教程(二)关于Jekyll代码高亮

来源:互联网 发布:单片机常用代码 编辑:程序博客网 时间:2024/06/07 00:42

说明

自jekyll3.0后,jekyll强制使用Rouge进行语法高亮,详细说明见https://jekyllrb.com/news/2015/10/26/jekyll-3-0-released/。
如果您是在对这中文版的http://jekyll.com.cn练习,那么恭喜你,你遇到问题了,因为中文版的文档没有及时更新,你可能会遇到下面的错误信息:

Dependency Error: Yikes! It looks like you don't have pygments or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- pygments' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!   Liquid Exception: pygments in /home/gavin/TE/_posts/2017-08-19-welcome-to-jekyll.markdown             ERROR: YOUR SITE COULD NOT BE BUILT:                    ------------------------------------                    pygments

其中有如下提示信息:

Deprecation: The ‘pygments’ configuration option has been renamed to ‘highlighter’. Please update your config file accordingly. The allowed values are ‘rouge’, ‘pygments’ or null.
意思是说,目前版本的pygments配置选项已经被修改成了highlighter选项,请修改配置文件。根据提示信息,这里应该修改成 highlighter:rouge

配置代码高亮

在_config.yml中添加“highlighter:rouge”,即可。
其实,你不用做此步骤修改,Jekyll会默认使用这个配置,这里之所以这么写是为了给您说明一下这个问题。如下所示,官方说的已经很清楚,现在默认使用Rouge代替Pygments,所以如果你的Jekyll是3.0以上版本,不必自己配置代码高亮了,系统已经内置了。

Default highlighter is now Rouge instead of Pygments

感想

做技术,如果官方文档是英文的,还是看英文的好,翻译过的虽然看着舒服,但是难免会因没有及时更新翻译而给你带来麻烦。