mdformat-myst

0.3.0 · active · verified Fri Apr 17

mdformat-myst is a plugin for the mdformat Markdown formatter, providing compatibility with MyST (Markedly Structured Text) Markdown syntax. It enables mdformat to correctly parse and format MyST-specific elements like directives, roles, and math blocks. The current version is 0.3.0, and it follows an active release cadence, frequently updating to support new mdformat features and MyST specifications.

Common errors

Warnings

Install

Imports

Quickstart

To use mdformat-myst, you invoke `mdformat` from the command line or use its Python API, specifying `myst` as an enabled extension or plugin. The plugin automatically integrates with `mdformat` to handle MyST-specific syntax. The example demonstrates programmatic usage; for command line, save the MyST markdown to a file and run `mdformat <file> --plugin myst`.

import os
from mdformat import text

# Example Markdown with MyST syntax
myst_markdown = """
---
title: MyST Example
author: Me
---

# MyST Title

````{myst-role}
This is a myst role content.
````

$$a^2 + b^2 = c^2$$

:::{note}
This is a MyST directive.
:::
"""

# --- Command Line Usage ---
# For command line, save the content to a file, e.g., 'example.md'
# Then run: mdformat example.md --plugin myst

# --- Python API Usage ---
formatted_text = text(myst_markdown, extensions=("myst",))
print(formatted_text)

# To verify it's formatted by mdformat-myst
# Note: This is a simplified check, actual verification requires inspecting output
assert ':::{note}' in formatted_text or '$a^2 + b^2 = c^2$' in formatted_text, \
    "MyST specific elements should be preserved/formatted."

view raw JSON →