mdformat-front-matters

raw JSON →
2.0.0 verified Fri May 01 auth: no python

An mdformat plugin for formatting YAML, TOML, or JSON front matter in Markdown files. Current version: 2.0.0. Release cadence is irregular; major version bumps when there are breaking changes in mdformat or plugin API.

pip install mdformat-front-matters
error ImportError: cannot import name 'mdformat_front_matters' from 'mdformat_front_matters'
cause Incorrect import path: the package is not a module with submodules; just `import mdformat_front_matters` works.
fix
Use import mdformat_front_matters without any submodule.
error mdformat.errors.MdformatConfigError: Unknown option 'front_matter_style'
cause Option name changed in v2.0.0 from `front_matter_style` to `prefer_style`.
fix
Use prefer_style instead of front_matter_style in mdformat options.
error FileNotFoundError: [Errno 2] No such file or directory: '...' (when using mdformat.file())
cause mdformat.file() expects a path to an existing file. This is a general mdformat gotcha.
fix
Ensure the file path is correct and the file exists.
breaking Version 2.0.0 drops support for Python <3.10. Ensure you're using Python 3.10+.
fix Upgrade Python to 3.10 or higher.
deprecated The option --front-matter-style has been renamed to --prefer-style. Old style may be removed in future.
fix Update CLI or API calls to use `prefer_style` instead of `front_matter_style`.
gotcha Plugin auto-registers on import; if you import it after calling mdformat functions, plugin won't be active.
fix Ensure `import mdformat_front_matters` is called before any mdformat formatting.
gotcha When using with other mdformat plugins, ordering may affect behavior if multiple plugins modify front matter. Check plugin priority.
fix Explicitly list plugins in `mdformat` options or control plugin loading order via Python code.

Importing the plugin automatically registers it with mdformat. Then use mdformat.text() or mdformat.file() as usual.

import mdformat_front_matters
import mdformat

# Format a markdown string with YAML front matter
formatted = mdformat.text('---\ntitle: My Doc\n---\n\nHello, world!', options={
    'wrap': 80,
    'end_of_line': 'lf'
})
print(formatted)