Skip to main content

Format and lint Python code blocks within markdown files.

Project description

Python License: MIT

A Python package/CLI to format and lint Python code blocks within Markdown files. Specifically designed for Markdown files used with mkdocs-material.

md-snakeoil is built on the awesome ruff formatter and linter and helps you to keep your Markdown files looking sharp. ๐Ÿค™๐Ÿฝ


before vs. after

Before implementation After implementation


Quickstart

Use pipx:

pipx install md-snakeoil

Format and lint Markdown files within a directory (recursively):

snakeoil path/to/directory

That's it! ๐Ÿš€

[!NOTE] If, your using uv, install it with uv tool install md-snakeoil

Command Line Interface

The package provides a command-line interface (CLI) using typer.

Help

snakeoil --help
 Usage: snakeoil [OPTIONS] [PATH] COMMAND [ARGS]...                                                                                              
                                                                                                                                                 
 Format and lint Python code blocks in Markdown files.

โ•ญโ”€ Arguments โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚   path      [PATH]  File or directory to format [default: None]                                                                               โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --line-length               INTEGER  Maximum line length for the formatted code [default: 79]                                                 โ”‚
โ”‚ --rules                     TEXT     Ruff rules to apply (comma-separated) [default: I,W]                                                     โ”‚
โ”‚ --install-completion                 Install completion for the current shell.                                                                โ”‚
โ”‚ --show-completion                    Show completion for the current shell, to copy it or customize the installation.                         โ”‚
โ”‚ --help                               Show this message and exit.                                                                              โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

By default, the line length is set to 79 characters, and the Ruff rules W and I are enabled. You can change these defaults using the --line-length and --rules options.

Single Markdown

snakeoil path/to/file.md

Formatting all files in a directory

snakeoil path/to/directory

This will recursively format and lint the Python code blocks in all Markdown files within path/to/directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

md_snakeoil-0.1.5.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

md_snakeoil-0.1.5-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file md_snakeoil-0.1.5.tar.gz.

File metadata

  • Download URL: md_snakeoil-0.1.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for md_snakeoil-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b7e253ddea3a35137cb576778ba0c91fc384e1ab658f03bd6cf08095f4255dac
MD5 c7f455299e3333e0d9cab6ba30ff7b76
BLAKE2b-256 b205b98b2ac7139061a0732353de7940025426e9e10639de5b0e56b9f07428e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for md_snakeoil-0.1.5.tar.gz:

Publisher: publish.yml on mciwing/md-snakeoil

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file md_snakeoil-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: md_snakeoil-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for md_snakeoil-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 497fc8574129c4204d6cbd75c0ecfb96c7c41b34f72ffbdd8140ed3735eb9308
MD5 536fc5bf65dc6d989205fb2bb4c49c2e
BLAKE2b-256 a43b3cad8fba92a80f2f7c60f0b243842e28cab0f3b3496b5aee9cef51dfd708

See more details on using hashes here.

Provenance

The following attestation bundles were made for md_snakeoil-0.1.5-py3-none-any.whl:

Publisher: publish.yml on mciwing/md-snakeoil

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page