Jekyll 中的语法高亮 Markdown 代码块(不使用 Liquid 标签)
Jekyll 中的语法高亮似乎仅限于使用 Liquid 标签和 pygments,如下所示
{% highlight bash %}
cd ~
{% endhighlight %}
:浏览每篇文章并修复代码块。另外,我想将我的帖子保留为纯降价格式,以防我需要再次切换博客平台。
我将 Jekyll 解析器切换到了 redcarpet,希望能够使用这个 markdown 语法:
```bash
cd ~
```
但它似乎不起作用。它只是将其包装在一个普通的代码块中。有什么想法吗?
It seems like syntax highlighting in Jekyll is limited to using liquid tags and pygments like so:
{% highlight bash %}
cd ~
{% endhighlight %}
But I've imported my existing blog from wordpress and it was written in markdown (using markdown code blocks) and I don't want to have to go through each post and fix the code blocks. Also, I want to keep my posts in pure markdown format in case I ever need to switch blogging platforms again.
I switched my Jekyll parser to redcarpet
with the hope that I could use this markdown syntax:
```bash
cd ~
```
But it doesn't seem to work. It just wraps it in a normal code
block. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
围栏块
已介绍
与 Redcarpet 2. Jekyll 一起
现在支持
Redcarpet 2.
顺便说一句,我正在使用 Redcarpet
胭脂
直到
Kramdown 支持
可用。
另外有些人更喜欢
Nanoc
杰基尔。
Fenced blocks
were introduced
with Redcarpet 2. Jekyll
now supports
Redcarpet 2.
As an aside I am using Redcarpet with
Rouge
until
Kramdown support
is available.
In addition some people prefer
Nanoc
to Jekyll.
替代解决方案
Markdown 允许 HTML,所以如果您不介意添加一点 JS,您可以这样做:
然后您可以使用 Highlight.js(文档此处)基于此添加突出显示班级。
这不是一个理想的解决方案,但它应该适用于任何 Markdown 解析器。
Alternate solution
Markdown allows HTML, so if you don't mind adding a bit of JS, you could do this:
Then you could use Highlight.js (documentation here) to add highlighting based on that class.
It's not an ideal solution, but it should work with any Markdown parser.
我最终切换到 kramdown 来解析 附带的 markdown coderay 用于语法高亮。这样做的好处是它是一个可以在 Heroku 上运行的纯 ruby 解决方案。
I ended up switching to kramdown to parse markdown which comes with coderay for syntax highlighting. This has the benefit of being a pure ruby solution which works on heroku.
第 1 步。安装Redcarpet。
第 2 步。像这样更新
_config.yaml
中的构建设置。Step 1. Install Redcarpet.
Step 2. Update the build settings in your
_config.yaml
like this.在最新的jekyll中支持代码块,但是如果你使用旧版本,你需要破解。
下面怎么样?
尝试将以下文件添加为您的
_plugin/triple-backtick.rb
In latest jekyll support code blocks, but if you use older version, you need to hack.
How about below?
Try to add below's file as your
_plugin/triple-backtick.rb
默认情况下,Redcarpet 已集成到 Jekyll 中,并且代码突出显示将按预期运行。
对于较旧的 Jekyll 博客:
安装 redcarpet gem:
gem install redcarpet
更新_config.yaml
有关参考和更多信息,请参阅:
已关闭的 Github 问题< /a>
更新了 Jekyll 代码库
Redcarpet is integrated integrated into Jekyll by default and code highlighting will function as expected.
For older Jekyll blogs:
Install redcarpet gem:
gem install redcarpet
Update _config.yaml
For reference and further info see:
Closed Github Issue
Updated Jekyll Codebase
所以我也遇到了这个问题,在尝试了很多地方后终于意识到 Jekyll 中的官方 redcarpet2 支持非常简单。
将其写入您的 _config.yml
确保您有 pygments css 文件并且它已包含在内。这一步很重要。
您可以阅读我的博客文章 http:// blog.championswimmer.in/2015/10/jekyllsyntax-highlighting-in-github-favored-markdown-codeblocks/ 了解详细信息。
So I ran into this problem as well and after banging my head around a lot of places finally realised with official redcarpet2 support in Jekyll this is pretty simple.
Write this in your _config.yml
Make sure that you have pygments css file and it is included. THIS STEP IS IMPORTANT.
You can read my blog post http://blog.championswimmer.in/2015/10/jekyllsyntax-highlighting-in-github-favoured-markdown-codeblocks/ for details.
您还可以使用三重波形符语法:
Kramdown (Jekyll) 支持该语法。
You can also use the triple-tilde syntax:
which is supported by Kramdown (Jekyll).