ruff
ffa07b57 - Apply formatting to markdown code blocks (#22470)

Commit
27 days ago
Apply formatting to markdown code blocks (#22470) Adds initial support for formatting Python code blocks inside Markdown files. - Adds `Markdown` source types/kinds - Maps `.md` file extension to `Markdown` by default - Uses simple regex adapted from blacken-docs to find and format fenced python code blocks - Dedents contents before formatting, and reapplies indent from fenced <code>```py</code> header - Selects `Python` vs `Stub` options based on language label on code block - Silently skips formatting for any code block with syntax errors or that produce formatting errors. - CLI tests formatting via both stdin and from filesystem - Requires running with `--preview`, and otherwise emits formatting error when given a markdown file - Requires a user to `extend-include = ["**/*.md"]` if they want to format markdown files by default Limitations: - Returns a formatting error if run with a range of any sort - Ignores implicit code blocks (no code fence) - Doesn't yet support `~~~` fences, arbitrary fence lengths, or code blocks inside blockquotes Issue #3792
Author
Parents
Loading