问题描述
如何在Markdown文档中使用pandoc创建的Reveal.js幻灯片中,如何将行号显示在代码块的左侧?
How can I get the line-numbers to display on the left edge of a code block in a Reveal.js slide show created with pandoc from a markdown document?
我尝试了以下降价促销:
I have tried the following markdown:
---
title: 'Display Code-block Line Numbers'
date: 'Aug 2020'
---
--------
~~~ { .python .number-lines startFrom="1" data-line-numbers="3,4-5" }
def main():
print( "hello pan" )
if __name__ == '__main__:
main()
~~~
--------
使用适用于pandoc的命令:
With this command for pandoc:
pandoc -s -i -t revealjs --section-divs -o slides.html slides.md
我还尝试了 fenced_code_attributes
的各种更改: {.python .number-lines}
, {.python .numberLines}
;和 pandoc
命令:删除 -i
标志并尝试一些-variable
s.
I have also tried various alterations of the fenced_code_attributes
:{ .python .number-lines }
, { .python .numberLines }
; and pandoc
commands: removing the -i
flag and trying some --variable
s.
此外,以下操作也不起作用: https://stackoverflow.com/a/55845381/5060792
Also, the following does not work either: https://stackoverflow.com/a/55845381/5060792
推荐答案
Reveal.js结合使用Highlight.js和 highlightjs-line-numbers.js v2.6,用于代码突出显示和行编号.因此,
Reveal.js uses highlight.js with highlightjs-line-numbers.js v2.6 for code highlighting and line numbering. Because of that,
-
数据行编号
应该在< code>
元素中进行行编号 元素中的
startFrom
选项或data-ln-start-from
属性将不起作用(当前),因此此功能已添加到Highlightjs-line-numbers.js v2.8中.
data-line-numbers
is expected in the<code>
element for line numbering- the
startFrom
option or rather thedata-ln-start-from
attribute in the<code>
element will not work (currently), hence this feature was added in highlightjs-line-numbers.js v2.8.
默认情况下,pandoc的代码块HTML输出的工作方式与Reveal.js期望的不同.例如,受防护的代码数据属性放在包装的< div>
中,reveal.js在其中找不到它们.您将需要编写原始HTML或使用过滤器更改输出,以使用Reveal.js的代码演示功能像是行编号.
By default, pandoc's HTML output for code blocks works differently than reveal.js expects it. For example, fenced code data attributes are put in a wrapping <div>
, where reveal.js can't find them. You will need to write raw HTML or change the output with a filter to use reveal.js' code presentation features like line numbering.
正如@tarleb上面评论的那样,我编写了一个lua过滤器,该过滤器适应pandoc的HTML输出以支持这些功能: https://github.com/pandoc/lua-filters/tree/master/revealjs-codeblock .
As @tarleb commented above, I wrote a lua filter which adapts pandoc's HTML output to support those features: https://github.com/pandoc/lua-filters/tree/master/revealjs-codeblock.
这篇关于使用Pandoc在Reveal.js代码块中的lineNumbers-markdown转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!