itaysk itaysk - 2 months ago 29
Markdown Question

Jekyll \ kramdown - add `.table` class to generated tables

Jekyll 3.2.1 + kramdown. I have a theme that uses bootstrap css.
Generated

<table>
s should be decorated with
class="table"
as bootstrap css requires.

I have seen other suggestions to add
{: class=table}
or
{.table}
to the markdown table but I really dislike this solution as it 'pollutes' the pure markdown with html\css details. I want my markdown to be readable as is and agnostic to the target format.

Preferred solution would be to customize Jekyll or kramdown such that markdown tables will be generated with this class automatically.
Is this possible?

Answer

It's probably easier to apply the styles to the table tag if all tables are going to have that class. This way you avoid polluting both your Markdown and markup. To avoid forking or modifying Bootstrap you could even have table extend those styles with Sass:

table {
  @extend .table;
}