mdformat-tables
mdformat-tables is a plugin for the `mdformat` markdown formatter, designed specifically for rendering tables according to the GitHub Flavored Markdown (GFM) specification. It ensures tables are consistently formatted and properly aligned. The library is actively maintained, with its current version being 1.0.0, and follows a stable release cadence driven by updates to `mdformat`.
Warnings
- breaking Python 3.6 support was dropped in `v1.0.0`. Users on older Python versions must either upgrade their Python environment or pin `mdformat-tables` to an earlier version (e.g., `<1.0.0`).
- gotcha Compatibility with `mdformat` versions is crucial. `mdformat-tables` versions are often synced with specific `mdformat` versions due to internal API changes (e.g., `v0.3.0` synced with `mdformat 0.6.0`). Mismatched versions can lead to unexpected formatting or errors.
- gotcha Prior to `v0.4.1`, tables containing unescaped pipe characters (`|`) within cells could be incorrectly rendered or parsed, leading to malformed output.
- gotcha Before `v0.4.0`, lines that visually resembled table delimiter rows (e.g., `--- | ---`) but were not intended as such could be misinterpreted and incorrectly escaped, affecting non-table content.
Install
-
pip install mdformat-tables mdformat
Imports
- mdformat_tables
import mdformat_tables
Quickstart
import mdformat import mdformat_tables # This registers the plugin markdown_with_table = """ | Header 1 | Header 2 | |----------|----------| | Row 1 Col 1 | Row 1 Col 2 | | Row 2 Col 1 | Row 2 Col 2 | """ formatted_markdown = mdformat.format_markdown(markdown_with_table, plugins=['tables']) print(formatted_markdown)