如何使用 jekyll 突出显示 Markdown 中存在的特定代码片段行?

问题描述 投票:0回答:1

我们正在使用 Jekyll 将 md(markdown)文件转换为 html 文件,并将 html 文件托管在站点中。

我想突出显示代码片段的特定行,如下所示。

Microsoft Document

我已经通过检查检查了 Microsoft 源代码。他们这样做了。

https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/updating-lated-data-with-the-entity- asp-net-mvc-application 中的框架#customize-courses-pages

Microsoft Document Source

我的 MD 文件代码片段部分如下所示。

{% 突出显示 c# %}

int x = 5;
int y = 6;
int sum = x + y;
Console.WriteLine(sum);

{% endhighlight %}

例如,我必须用黄色突出显示第 3 行 (int sum = x + y;)。

如何实现这一目标?

html markdown jekyll
1个回答
0
投票

Jekyll 文档表示将从 4.4 版本开始提供https://jekyllrb.com/docs/liquid/tags/#marking-specific-lines

{% highlight ruby mark_lines="1 2" %}
def foo
  puts 'foo'
end
{% endhighlight %}

但是,我在 Jekyll 4.3.2(kramdown v2.4.0 和 rouge v4.1.3)上进行了测试,现在它确实可以工作了。

您声明的每一行都将包含在

<span class="hll">
中,您只需在 CSS 文件中定义样式即可。

© www.soinside.com 2019 - 2024. All rights reserved.