Mdformat GFM

1.0.0 · active · verified Sun Apr 12

Mdformat-gfm is an mdformat plugin that extends the core mdformat library to support GitHub Flavored Markdown (GFM) syntax extensions, including tables, task list items, strikethroughs, and autolinks. It allows mdformat to properly format Markdown files that utilize these GFM features. The library is currently at version 1.0.0 and typically releases new versions in sync with its parent library, mdformat.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mdformat` with the `mdformat-gfm` plugin via its Python API. The `mdformat-gfm` plugin is automatically loaded by `mdformat` once installed, and its GFM capabilities are enabled by passing `extensions=['gfm']` to `mdformat.text()` or `mdformat.file()`.

import mdformat

unformatted_gfm = """
# My GFM Document

- [ ] Task list item
- [x] Another task

| Header 1 | Header 2 |
| -------- | -------- |
| Cell 1   | Cell 2   |

This is a ~~strikethrough~~ text.
"""

# To format a string with GFM support:
formatted_text = mdformat.text(unformatted_gfm, extensions=['gfm'])
print(formatted_text)

# To format a file in place:
# with open('my_gfm_file.md', 'w') as f:
#     f.write(unformatted_gfm)
# mdformat.file('my_gfm_file.md', extensions=['gfm'])
# with open('my_gfm_file.md', 'r') as f:
#     print(f.read())

view raw JSON →