13

For a heading, for a code-block, for a span element we can with pandoc add {.class} to add a 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}

I'm working with bootstrap, and it would be nice to specify "table" and/or "table-hover" as class such that the html view gets the table decorated with bootstrap CSS.

Anyone?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
karelv
  • 756
  • 9
  • 20
  • This may be related: [Python markdown add class to table](http://stackoverflow.com/q/21830882/866026). While that discusses a different tool (so not strictly a duplicate), the same syntax is supported and I expect the same reasoning would apply. I also suspect the way to work around it will be the same. – Waylan Jan 26 '17 at 16:09

1 Answers1

11

In pandoc's internal document AST, tables have attributes since pandoc 2.10, but the markdown reader hasn't been updated for that yet. (Same for other formats.)

However, you can:

  • wrap a table in a raw HTML div with a class (this won't work for bootstrap CSS which expects the class to be on the table),
  • write a pandoc filter, or
  • probably in this case easier: post-process the output HTML to add a class.
mb21
  • 34,845
  • 8
  • 116
  • 142
  • 1
    option #3 is what I did, using jquery. – karelv Jan 29 '17 at 11:22
  • myself I prefer perl at the commandline for modifying the resulting html in place. Something like: `perl -pi -e 's//
    /' output.html` for working with bootstrap table classes.
    – WebDragon Apr 02 '19 at 20:09
  • Think this can help to solve it using a Paru filter: https://github.com/htdebeer/paru/blob/master/examples/filters/add_css_class_to_tables.rb – xbelanch Jun 12 '19 at 18:12