Skip to main content

A formatter for reStructuredText files with plugin support for embedded code blocks

Project description

rstformat

A formatter for reStructuredText files.

Become a Sponsor PyPI PyPI Downloads Python Versions GitHub license

An open source and free formatter for reStructuredText (.rst) files, distributed under the MIT License.

Features

Feature Setting
Trim trailing whitespace trim_trailing_whitespace
Output line ending (LF / CRLF / auto-detect) line_ending
Resize section adornments to title width normalize_section_underlines
Add/remove blank lines around headings normalize_section_spacing
Limit consecutive blank lines max_consecutive_blank_lines
Insert final newline insert_final_newline
East-Asian double-width character support (implicit)

Plugin system for delegating embedded code-block formatting to language-specific tools:

  • Python code blocks → Black or Ruff formatter
  • Shell script blocks → shfmt formatter
  • SQL blocks → sqlfluff formatter (planned)

Installation

Install from PyPI:

pip install rstformat

Or with uv:

uv tool install rstformat

To enable optional features:

pip install rstformat[editorconfig]  # Honor .editorconfig settings
pip install rstformat[lint]          # Pre-flight validation via docutils/rstcheck
pip install rstformat[dev]           # Development dependencies (tests, ruff)

Usage

Format files in-place:

rstformat file.rst dir/

Check mode (exit 1 if any file would change):

rstformat --check file.rst

Show unified diff without writing:

rstformat --diff file.rst

Read from stdin, write to stdout:

echo "Title\n=====" | rstformat

Control output line endings:

rstformat --line-ending crlf file.rst    # Force Windows (CRLF)
rstformat --line-ending auto file.rst    # Preserve input style

For all options, run:

rstformat --help

Configuration

Create pyproject.toml or .rstfmt.toml in your project:

[tool.rstformat]
adornments            = "#*=-^\"'`:.~_+"
insert_final_newline  = true
line_ending           = "lf"   # "lf" | "crlf" | "auto"
max_consecutive_blank_lines = 2
normalize_section_spacing   = true
normalize_section_underlines = true
trim_trailing_whitespace     = true

rstformat also respects .editorconfig for compatible settings:

[*.rst]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

For more details, see DESIGN.md.

Documentation

License

Copyright (c) 2026 LeXtudio Inc.

Licensed under the MIT License. See LICENSE for details.

Community

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

rstformat-0.1.0.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

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

rstformat-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file rstformat-0.1.0.tar.gz.

File metadata

  • Download URL: rstformat-0.1.0.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for rstformat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3ea351cdc32c0a9b758e7ac5c6797e8aab690cac2f208c2f91b587a80fdd625c
MD5 88003ed95e986ddf0054cd4617163686
BLAKE2b-256 cb3dafab4ac0f292b1c43bc87fb26e5ad11a1eb654f3945c506b5c81f8fe889a

See more details on using hashes here.

File details

Details for the file rstformat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rstformat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for rstformat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc9681529bcd4caeffff36393088f97895a85018fe9586a8265b64b1fa311455
MD5 55298c55ec0db12d6cddf11709e13ef3
BLAKE2b-256 8dc73752296639c05e7402c7bbb2bc8e0fdedad56444bd3e3d24918b07d1d979

See more details on using hashes here.

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