A minimal-dependency Python linter for detecting and fixing misaligned ASCII art boxes in documentation
Project description
ascii-guard
Zero-dependency Python linter for detecting and fixing misaligned ASCII art boxes in documentation.
๐ฏ Why ascii-guard?
AI-generated ASCII flowcharts and diagrams often have subtle formatting errors where box borders are misaligned by 1-2 characters. This breaks visual integrity and makes documentation harder to read.
ascii-guard automatically detects and fixes these alignment issues, ensuring your ASCII art looks perfect.
โจ Key Features
- ๐ Minimal dependencies - Zero for Python 3.11+, one tiny dep for Python 3.10 (
tomli) - ๐พ Tiny footprint - Lightweight and fast
- ๐ Minimal supply chain risk - Pure stdlib on 3.11+
- โก Quick startup - No import overhead
- ๐ฆ Simple installation - One command, automatic dependency handling
- ๐ Python API - Stable programmatic interface for integration into pipelines and scripts
- ๐ก๏ธ Type-safe - Full mypy strict mode
- โ Well tested - Comprehensive test coverage
๐ฆ Installation
We recommend using uv for the fastest installation experience, but pip and pipx are fully supported alternatives. uv provides faster dependency resolution and better reproducibility, while pip and pipx work with any standard Python environment.
Recommended: Using uv (Fastest)
# Install ascii-guard
uv tool install ascii-guard
Note: If
uvis not installed, you may install it with:curl -LsSf https://astral.sh/uv/install.sh | sh
Alternative: Using pip
pip install ascii-guard
Alternative: Using pipx (Isolated Environment)
pipx install ascii-guard
That's it! No other dependencies needed.
๐ Quick Start
Check files for ASCII art issues
ascii-guard lint README.md
ascii-guard lint docs/**/*.md
Auto-fix alignment issues
ascii-guard fix README.md
ascii-guard fix --dry-run docs/guide.md # Preview changes first
Example 1: Simple Box
Before (misaligned):
โโโโโโโโโโโโโโโโโโโโโโโ
โ Box Content โ
โโโโโโโโโโโโโโโโโโโโโโ โ Missing one character!
After (fixed):
โโโโโโโโโโโโโโโโโโโโโโโ
โ Box Content โ
โโโโโโโโโโโโโโโโโโโโโโโ โ Perfect alignment โ
Example 2: Flowchart
Before (multiple alignment issues):
โโโโโโโโโโโโโโโโ
โ Start โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโผโโโโโโโโ
โ Step โ โ Right border misaligned
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโผโโโโโโโโ
โ End โโ โ Duplicate right border
โโโโโโโโโโโโโโโ โ Broken bottom right corner
After (all boxes aligned):
โโโโโโโโโโโโโโโโ
โ Start โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโผโโโโโโโโ
โ Step โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโผโโโโโโโโ
โ End โ
โโโโโโโโโโโโโโโโ
ascii-guard automatically detects and fixes alignment issues across multiple boxes, nested structures, and complex flowcharts.
๐ญ Ignore Markers
Need to show intentionally broken boxes in your docs? Use ignore markers:
**โ Common Mistake (don't do this):**
<!-- ascii-guard-ignore-next -->
โโโโโโโโโโโโโโโโโโโโโโโ
โ Box Content โ
โโโโโโโโโโโโโโโโโโโโโโ โ Misaligned on purpose for demonstration
**โ
Correct Way:**
โโโโโโโโโโโโโโโโโโโโโโโ
โ Box Content โ
โโโโโโโโโโโโโโโโโโโโโโโ โ Perfect alignment
The ignore markers are invisible in rendered markdown but tell ascii-guard to skip validation. Perfect for:
- Before/after comparisons
- Tutorial examples showing common mistakes
- Documentation with intentionally broken examples
See USAGE.md for complete syntax and examples.
๐จ Supported Box-Drawing Characters
ascii-guard supports Unicode box-drawing characters:
| Type | Characters | Description |
|---|---|---|
| Horizontal | โ (U+2500) |
Horizontal line |
| Vertical | โ (U+2502) |
Vertical line |
| Corners | โ โ โ โ |
Standard corners |
| T-junctions | โ โค โฌ โด |
Connection points |
| Cross | โผ |
Four-way intersection |
| Heavy lines | โ โ โ โ โ โ |
Bold variants |
| Double lines | โ โ โ โ โ โ |
Double-line variants |
๐ Validation Rules
ascii-guard checks for:
- Vertical alignment - All
โcharacters in a column align - Horizontal alignment - All
โcharacters connect properly - Corner correctness - Corner characters match adjacent lines
- Width consistency - Top, middle, and bottom borders match
- Content fit - Content stays within box borders
๐ Python API
ascii-guard provides a stable Python API for programmatic use. Perfect for integrating into documentation pipelines, CI/CD scripts, or custom tooling.
from ascii_guard import lint_file, fix_file, detect_boxes
# Lint a file for issues
result = lint_file("README.md")
if result.has_errors:
print(f"Found {len(result.errors)} alignment errors")
for error in result.errors:
print(f" Line {error.line + 1}: {error.message}")
# Auto-fix alignment issues
result = fix_file("README.md", dry_run=True) # Preview first
print(f"Would fix {result.boxes_fixed} boxes")
# Detect boxes without validation
boxes = detect_boxes("docs/guide.md")
print(f"Found {len(boxes)} ASCII art boxes")
Available functions:
lint_file()- Lint a file for ASCII art alignment issuesfix_file()- Fix alignment issues in a filedetect_boxes()- Detect ASCII art boxes without validationvalidate_box()- Validate a single Box objectfix_box()- Fix a single Box object
Data models: Box, ValidationError, LintResult, FixResult
๐ Full API documentation: See API Reference for complete details, type signatures, and advanced examples.
๐ค Contributing
We welcome contributions! Here's how to get started:
Prerequisites:
- Python 3.10+
- uv - Fast Python package manager
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Fork and clone the repository
git clone https://github.com/YOUR-USERNAME/ascii-guard.git
cd ascii-guard
# One-step setup (creates venv, installs deps, configures hooks)
./setup.sh
# Use uv run for commands
uv run pytest # Run tests
uv run ruff check . # Lint code
uv run mypy src/ # Type check
# Make your changes and submit a PR
For detailed development guide, see docs/DEVELOPMENT.md
For contribution guidelines, see CONTRIBUTING.md
๐ License
Apache License 2.0 - see LICENSE for details.
Copyright 2025 Oliver Ratzesberger
๐ Links
- Repository: https://github.com/fxstein/ascii-guard
- Issues: https://github.com/fxstein/ascii-guard/issues
- PyPI: https://pypi.tw.martin98.com/project/ascii-guard/
- Documentation:
- User Guide - Complete usage documentation
- Python API Reference - Complete API documentation
- Development Guide - Setup, workflow, architecture
- FAQ - Frequently asked questions
๐ Acknowledgments
Inspired by the need for better ASCII art formatting in AI-generated documentation.
Built with โค๏ธ using only Python's standard library.
Note: ascii-guard is stable and actively maintained. Contributions and feedback are welcome!
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 ascii_guard-2.3.0.tar.gz.
File metadata
- Download URL: ascii_guard-2.3.0.tar.gz
- Upload date:
- Size: 58.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d02cbbac7f283ca4bc77fb0a050c5d9f5bacb5d26f7acfce7e957b011e645114
|
|
| MD5 |
b5e18b618c658a057073857e3bc8d49d
|
|
| BLAKE2b-256 |
35fbb9496737a03c47c08e6619fa0cfadd7ae462c2199f51183af15c0e5ade12
|
Provenance
The following attestation bundles were made for ascii_guard-2.3.0.tar.gz:
Publisher:
release.yml on fxstein/ascii-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ascii_guard-2.3.0.tar.gz -
Subject digest:
d02cbbac7f283ca4bc77fb0a050c5d9f5bacb5d26f7acfce7e957b011e645114 - Sigstore transparency entry: 943452818
- Sigstore integration time:
-
Permalink:
fxstein/ascii-guard@86a5ecaf169dcaa9bdfebbe5be3cd03552ed3a04 -
Branch / Tag:
refs/tags/v2.3.0 - Owner: https://github.com/fxstein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@86a5ecaf169dcaa9bdfebbe5be3cd03552ed3a04 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ascii_guard-2.3.0-py3-none-any.whl.
File metadata
- Download URL: ascii_guard-2.3.0-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6594432b9770ca9c52883541abe1052469d1816bc6aa0c51993e7fabadebddfc
|
|
| MD5 |
3b6987b7d37f2ef57db2d596e3e75000
|
|
| BLAKE2b-256 |
1283b05c5a6e7dc6771a4f1c6f13c9868b9e377358953aad37df94c21b5165f4
|
Provenance
The following attestation bundles were made for ascii_guard-2.3.0-py3-none-any.whl:
Publisher:
release.yml on fxstein/ascii-guard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ascii_guard-2.3.0-py3-none-any.whl -
Subject digest:
6594432b9770ca9c52883541abe1052469d1816bc6aa0c51993e7fabadebddfc - Sigstore transparency entry: 943452847
- Sigstore integration time:
-
Permalink:
fxstein/ascii-guard@86a5ecaf169dcaa9bdfebbe5be3cd03552ed3a04 -
Branch / Tag:
refs/tags/v2.3.0 - Owner: https://github.com/fxstein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@86a5ecaf169dcaa9bdfebbe5be3cd03552ed3a04 -
Trigger Event:
push
-
Statement type: