Jekyll在Github Pages上:有没有办法在Markdown中添加脚注?

81

我最近转而使用Jekyll在Github Pages上运行我的各种博客,并且很喜欢它,因为我只需将Markdown文件推送到Github,他们就会处理。我想继续以这种方式使用它(而不是在本地运行Jekyll,然后将预先生成的站点推送到Github),因为Github UI使添加和调整帖子变得容易,即使我不在自己的机器上。

只有一件事我一直没能解决:我无法让Markdown脚注工作。我正在使用这个样式:

I bet you'd like more information about this sentence [^1].

[^1]: Well lucky for you, I've included more information in footnote form.

我确实找到了一篇帖子(位置不明),建议为redcarpet markdown处理器启用脚注扩展,但这也没有解决问题:

markdown: redcarpet
redcarpet:
  extensions: ["footnotes"]

有没有办法在推送到Github之前不预先生成静态站点的情况下使用Markdown脚注?


GitHub Markdown现在(2021年9月)支持脚注。但这并不一定能转换为Jekyll GitHub页面。 - VonC
4个回答

74

我使用kramdown来解析markdown,它可以很好地处理脚注。

在你的_config.yml文件中修改这一行:

markdown: redcarpet

收件人:

markdown: kramdown

19
我也非常喜欢你。 - Brian Willis
不幸的是,kramdown 可能会导致由 (文本在此 生成的代码块未正确排序换行符,但我可以通过使用三个波浪线 ~~~ 在文本之前和之后来解决这个问题。这对大多数人可能不是问题,但我有很多这样的代码块,因此更改 markdown 样式需要我编辑一些帖子。 - ComputerScientist
奇怪的是,我的_config.yml文件中有markdown:kramdown,但它从未呈现脚注。非常奇怪。 - Alex White

47

截至Jekyll 3.0.0版本,kramdown是默认的Markdown处理器,因此OP问题中的示例现在可以直接使用。模式如下:

Some text[^1].

Some other text[^2].

The identifier in the square brackets does not have to be numeric[^my_footnote].

[^1]: Some footnote.
[^2]: Other footnote.

[^my_footnote]: This also works fine.

2020年1月3日更新:


7

Redcarpet

如果你想使用redcarpet,目前似乎没有方便的解决方案。 虽然Redcarpet 3支持注释的语法,但它没有包含在Jekyll中,因为Redcarpet 3删除了Ruby 1.8兼容性(来源)。

解决方案1:使用forked Redcarpet 2

参见Jerod Santo的这个解决方案

在Jekyll文件夹的根目录下添加一个名为Gemfile的文件,并加入以下内容:

source "https://rubygems.org"

gem "jekyll"
gem "redcarpet", github: "triplecanopy/redcarpet"

或者可以选择使用djui/redcarpet

然后你需要调整你的_config.yml文件:

markdown: redcarpet
redcarpet:
  extensions: [footnotes]

解决方案2:Fork Jekyll并包含Redcarpet 3

我不知道最简单的方法是什么。欢迎留言。

Maruku

似乎支持脚注(来源, 来源)。


FYI:extensions: [footnotes] 可与 Jekyll 2.2.0 一起使用(尽管我不知道它是何时添加的)。 - docwhat
vmg/redcarpet的原始Github存储库作为指向的最佳来源,不是吗? - sameers

0

是的,那就是我在 https://dev59.com/Zl8e5IYBdhLWcg3wlbTx#69396272 中提到的帖子。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接