Search code examples
formattingmarkdownmkdocs

Support extended markdown table syntax with Mkdocs


I have markdown tables like the following in my docs:

+----------------------+----------------------------------------------+
| `code`               | *italics*                                    |
+======================+==============================================+
| `more code`          | | column 1 | column 2 | column 3 |           |
|                      | |----------|----------|----------|           |
|                      | | abcd     | efg      | hijk     |           |
|                      | | lmnop    | qrs      | tuv      |           |
|                      | | wx       | y        | z        |           |
+----------------------+----------------------------------------------+
| `even more code`     | Regular text that spans multiple lines       |
|                      | within this cell.                            |
|                      |                                              |
|                      |                                              |
+----------------------+----------------------------------------------+
| **bold**             | Regular text that spans multiple lines       |
|                      | within this cell.                            |
|                      |                                              |
|                      | **bolded text in a separate paragraph.**     |
+----------------------+----------------------------------------------+

Is there some way (e.g. with a plugin) that I can get Mkdocs to render it as a table in the resulting HTML?

The above table can be reformatted as required, but ultimately it needs to support table cells that contain arbitrary markdown within them, allowing for nested tables, paragraphs that span multiple lines, italics, etc.

Notably, Pandoc supports this Markdown format. Maybe I can hook into Mkdoc (e.g. by making my own plugin) to render the markdown using Pandoc's syntax for it.

I would like to avoid writing inline HTML.


Solution

  • Thanks to the link Waylan provided, I found an unmaintained project that provides what I needed.

    I've made a fork of the project (which I intend to maintain), and have published it to PyPI.

    It can be installed with pip install markdown-grid-tables, then used by adding markdown_grid_table to your list of Markdown extensions.