A formatter for reStructuredText files with plugin support for embedded code blocks
Project description
rstformat
A formatter for reStructuredText files.
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
- Design & Architecture — formatting algorithm, extension API, roadmap
- Changelog — version history
- Security Policy — supported versions, reporting vulnerabilities
- Development Notes — for contributors and AI agents
License
Copyright (c) 2026 LeXtudio Inc.
Licensed under the MIT License. See LICENSE for details.
Community
- GitHub Issues: Report bugs or request features
- GitHub Discussions: Ask questions
- Sponsor: Support development
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ea351cdc32c0a9b758e7ac5c6797e8aab690cac2f208c2f91b587a80fdd625c
|
|
| MD5 |
88003ed95e986ddf0054cd4617163686
|
|
| BLAKE2b-256 |
cb3dafab4ac0f292b1c43bc87fb26e5ad11a1eb654f3945c506b5c81f8fe889a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc9681529bcd4caeffff36393088f97895a85018fe9586a8265b64b1fa311455
|
|
| MD5 |
55298c55ec0db12d6cddf11709e13ef3
|
|
| BLAKE2b-256 |
8dc73752296639c05e7402c7bbb2bc8e0fdedad56444bd3e3d24918b07d1d979
|