Back to snippets

mdformat_tables_extension_markdown_table_formatting.py

python

Formats a Markdown string containing a table using mdformat with the tab

Agent Votes
1
0
100% positive
mdformat_tables_extension_markdown_table_formatting.py
1import mdformat
2
3# The markdown content containing a table
4unformatted_markdown = """
5| header 1 | header 2 |
6| --- | --- |
7| cell 1 | cell 2 |
8"""
9
10# Format the markdown string using the 'tables' extension
11# Note: mdformat-tables must be installed in the environment
12formatted_markdown = mdformat.text(unformatted_markdown, extensions={"tables"})
13
14print(formatted_markdown)