Github风味的Markdown和pygments在Jekyll中突出显示 [英] Github flavored Markdown and pygments highlighting in Jekyll

查看:139
本文介绍了Github风味的Markdown和pygments在Jekyll中突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VPS上部署了我的Jekyll博客。我现在想使用Pygments突出显示来添加Github-flavored Markdown,但我不知道要编辑哪些文件以及如何编辑。



到目前为止,我配置的唯一文件是 _config.yml ,如下所示:

  1安全:false 
2 auto:false
3服务器:false
4 server_port:4000
5 baseurl:/
6 url:http:/ / localhost:4000
7
8来源:。
9目的地:./_site
10个插件:./_plugins
11
12未来:真
13 lsi:false
14 pygments:false
15 markdown:maruku
16 permalink:date
17
18 maruku:
19 use_tex:false
20 use_divs:false
21 png_engine: blahtex
22 png_dir:images / latex
23 png_url:/ images / latex
24
25 rdiscount:
26个扩展:[]
27
28 kramdown:
29 auto_ids:true,
30 footnote_nr:1
31 entity_output:as_char
32 toc_levels:1..6
33 use_coderay:false
34
35 coderay:
36 coderay_wrap:div
37 coderay_line_numbers:inline
38 coderay_line_numbers_start:1
39 coderay_tab_width:4
coderay_bold_every: 10
41 coderay_css:style

如何正确配置Jekyll使用Github风格的Markdown和Pygments突出显示?

解决方案

编辑:现在更简单



截至Jekyll> = 0.12.1 redcarpet2原生支持通过Jekyll,所以你可以简单地将你的配置设置为 markdown:redcarpet ,并且你可以使用GFM /围栅代码块,而不需要这个mumbojumbo的其余部分...... p>

原始答案



您明确要求提供Github风格的降价,所以我认为您并未寻找答案用非标记液体格式创建代码块:

  {%highlight python%} 
def yourfunction():
打印Hello World!
{%endhighlight%}

但宁可用围栏代码块:

 ```python 
def yourfunction():
printHello World!
```

等。为此,您需要使用 redcarpet markdown解析器。

Github-flavored markdown使用一个名为Redcarpet的降价解析器 1 。具有讽刺意味的是,尽管Github风格降价使用 redcarpet2 ,但默认情况下,Jekyll不支持此降价解析器。相反,你可以通过安装这个ruby gem添加这个插件。

  gem install redcarpet 

,然后添加 redcarpet2 Jekyll插件。 (在Jekyll中安装一个插件就等于将该仓库中的 .rb ruby​​脚本放到你的 _plugins 目录中。也在 _plugins 的子目录中)。然后,按照那里的文档所述,编辑你的 _config.yml 以使用redcarpet2:

  markdown:redcarpet2 
redcarpet:
extensions:[no_intra_emphasis,fenced_code_blocks,autolink,strikethrough ,superscript]

它增加了github-flavored-markdown aka提供的常用扩展名redcarpet2(好吧,这几乎不会做github特定的markdown事情,比如通过数字来标识问题,或者通过哈希提交,所以它们在技术上并不相同)。

拥有插件意味着,目前,您必须在本地构建您的站点并将 _site 复制到github如果你在那里托管你的网站,因为redcarpet2在Github版本的jekyll引擎上不可用(见开放问题在Jekyll上)



注意:您并不需要您指定的所有降价编辑器顺便说一句,你的 _config.yml 。对于使用redcarpet2的基本示例,您可能想要查看此配置和与之相关联的jekyll目录。

I've deployed my Jekyll blog on a VPS. I would now like to add Github-flavored Markdown to it, using Pygments highlighting, but I don't know which files do I have to edit and how.

So far, the only file I've configured is _config.yml wich looks like this:

  1 safe:        false
  2 auto:        false
  3 server:      false
  4 server_port: 4000
  5 baseurl:    /
  6 url: http://localhost:4000
  7 
  8 source:      .
  9 destination: ./_site
 10 plugins:     ./_plugins
 11 
 12 future:      true
 13 lsi:         false
 14 pygments:    false
 15 markdown:    maruku
 16 permalink:   date
 17 
 18 maruku:
 19   use_tex:    false
 20   use_divs:   false
 21   png_engine: blahtex
 22   png_dir:    images/latex
 23   png_url:    /images/latex
 24 
 25 rdiscount:
 26   extensions: []
 27 
 28 kramdown:
 29   auto_ids: true,
 30   footnote_nr: 1
 31   entity_output: as_char
 32   toc_levels: 1..6 
 33   use_coderay: false
 34 
 35 coderay:
 36   coderay_wrap: div
 37   coderay_line_numbers: inline
 38   coderay_line_numbers_start: 1
 39   coderay_tab_width: 4
 40   coderay_bold_every: 10
 41   coderay_css: style

How do I properly configure Jekyll to use Github flavored Markdown and Pygments highlighting?

解决方案

Edit: Easier now

as of Jekyll >= 0.12.1 redcarpet2 is natively supported by Jekyll, so you can simply set your config to markdown: redcarpet and you are good to go with GFM / fenced code blocks without the rest of this mumbojumbo...

Original answer

You explicitly ask for Github-flavored markdown, so I presume you aren't looking for answers that create code blocks with the non-markdown liquid format:

{% highlight python %}
def yourfunction():
     print "Hello World!"
{% endhighlight %}

but would rather be able to write something with fenced code blocks:

```python
def yourfunction():
     print "Hello World!"
```

etc. For this, you will want to use the redcarpet markdown parser.

Github-flavored markdown uses a markdown parser called "Redcarpet" 1. Ironically, though Github flavored markdown uses redcarpet2, this markdown parser is not supported by Jekyll by default. Instead, you can add this as a plugin by installing that ruby gem

gem install redcarpet

and then adding the redcarpet2 Jekyll plugin. (Installing a plugin in Jekyll amounts to placing the .rb ruby script given in that repository into your _plugins directory. Can be in a subdirectory of _plugins too).

Then, as explained on the documentation there, edit your _config.yml to use redcarpet2:

markdown: redcarpet2
redcarpet:
  extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript"]

which adds the common extensions provided by github-flavored-markdown aka redcarpet2 (Well, almost. This won't do github specific markdown things like identify issues by number, or commits by hash, so they aren't technically the same).

Having the plugin means, for the moment, you will have to build your site locally and copy the _site to github if you are hosting your site there, as redcarpet2 isn't available on the Github version of the jekyll engine (see this open issue on Jekyll)

Note: You don't need all the markdown editors you've specified in your _config.yml by the way. For a basic example using redcarpet2, you might want to see this config and the associated jekyll directory that goes with it.

这篇关于Github风味的Markdown和pygments在Jekyll中突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆