Pandoc如何在Markdown中给表格添加类?

13

我们可以使用 Pandoc 给标题、代码块和 span 元素添加 {.class} 来添加类。

# Heading 1 {.my_class_for_heading1}

Here is some `code`{.my_class_for_code} and 
for a [span]{.my_class_for_span} it is working as well
and for img and url it is available as well
for [pandoc](http://www.pandoc.org/){.my_class_for_url}
我正在使用Bootstrap,并希望指定"class"为"table"和/或"table-hover",以便HTML视图可以使用Bootstrap CSS装饰表格。有人可以帮忙吗?

这可能与之相关:Python markdown add class to table。虽然它讨论的是不同的工具(因此不严格重复),但支持相同的语法,我认为相同的推理也适用。我还怀疑解决方法也将是相同的。 - Waylan
1个回答

11
在 pandoc 的内部文档 AST 中,自 pandoc 2.10 起,表格具有属性,但是 markdown 阅读器尚未更新。(其他格式也是如此)
然而,您可以:
  • 使用带类的原始 HTML div 包装表格(这对于期望类在表格上的 bootstrap CSS 不起作用),
  • 编写pandoc 过滤器, 或者
  • 在这种情况下可能更容易: 后处理输出 HTML 添加一个类。

1
选项#3是我所采用的,使用jQuery。 - karelv
我个人更喜欢在命令行中使用Perl来直接修改HTML。例如:perl -pi -e 's/<table>/<table class="table table-striped table-hover table-sm">/' output.html用于处理Bootstrap表格类。 - WebDragon
考虑使用 Paru 过滤器来解决问题:https://github.com/htdebeer/paru/blob/master/examples/filters/add_css_class_to_tables.rb - xbelanch

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