Can I style rendered markdown tables in mkdocs (supply table with class / id)

Viewed 59

With mkdocs, I convert some markdown tables containing technical information. I would like to style these tables with css - but not every table on the site. My goal is to have an id or class for certain tables.

My original markdown (example)

## COMMAND

|Specifier|alias|parameters |function               |
|---------|-----|-----------|-----------------------|
|start    |R    |           |Start                  |
|load     |F    |;myfilename|Load                   |

Resulting html, using the "material" theme. The two div's wrapping the table are inserted using javascript from the theme.

<h2 id="command">COMMAND</h2>
<div class="md-typeset__scrollwrap">   <!-- this is automatically inserted -->
<div class="md-typeset__table">        <!-- this is automatically inserted -->
   <table>                             <!-- I would like to id / class this -->
      <thead>
         <tr>
            <th>Specifier</th>
            <th>alias</th>
            <th>parameters</th>
            <th>function</th>
         </tr>
      </thead>
      <tbody>
         <tr>
            <td>start</td>
            <td>R</td>
            <td></td>
            <td>Start</td>
         </tr>
         <tr>
            <td>load</td>
            <td>F</td>
            <td>;myfilename</td>
            <td>Load</td>
         </tr>
      </tbody>
   </table>
</div>
</div>

If I enclose the markdown table in tags with a class, it does not render as html. Any attempt to put a class before or after the table ({: .myTableClass }) also fails to render markdown.

So, how can I achieve to put an id, or a class, on certain markdown tables ? It is a few tables, so an automatic id would also work. In above example, something like <table class='myTableClass'>

1 Answers

Looking at the Attribute List plugin for mkdocs (which it appears you are using) - I don't think this is possible. See the Limitations section for details.

Implied Elements:
There are various HTML elements which are not represented in Markdown text, but only implied. For example, the ul and ol elements do not exist in Markdown. They are only implied by the presence of list items (li). There is no way to use an attribute list to define attributes on implied elements, including but not limited to the following: ul, ol, dl, table, thead, tbody, and tr.

Related