Skip to main content

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.

License Python CI codecov Code style: ruff Type checked: mypy PRs Welcome


๐ŸŽฏ 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
  • ๐Ÿ›ก๏ธ 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 uv is 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

Before (misaligned):

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Box Content         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ† Missing one character!

After (fixed):

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Box Content         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ† Perfect alignment โœ“

๐ŸŽญ 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:

  1. Vertical alignment - All โ”‚ characters in a column align
  2. Horizontal alignment - All โ”€ characters connect properly
  3. Corner correctness - Corner characters match adjacent lines
  4. Width consistency - Top, middle, and bottom borders match
  5. Content fit - Content stays within box borders

๐Ÿค 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


๐Ÿ™ 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


Download files

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

Source Distribution

ascii_guard-2.2.2.tar.gz (57.5 kB view details)

Uploaded Source

Built Distribution

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

ascii_guard-2.2.2-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file ascii_guard-2.2.2.tar.gz.

File metadata

  • Download URL: ascii_guard-2.2.2.tar.gz
  • Upload date:
  • Size: 57.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ascii_guard-2.2.2.tar.gz
Algorithm Hash digest
SHA256 e6ce6668dabae6e95020742f20f7b4991d27c01f66ca4a9921c99a24fb0c3bd7
MD5 8e0250e0f29932b2684d00a1fa3b6c39
BLAKE2b-256 9c3bd00f9c20d436d331ab5252f2a60993f0eef85caaaea1d0d57d7d7b5a1595

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_guard-2.2.2.tar.gz:

Publisher: release.yml on fxstein/ascii-guard

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

File details

Details for the file ascii_guard-2.2.2-py3-none-any.whl.

File metadata

  • Download URL: ascii_guard-2.2.2-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ascii_guard-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 825f085f5d2cf29c0058efdf34940eff8a857109dedba67cd4dd9401599ae2bf
MD5 e307892713d63924ead5c97d0c2cfd4c
BLAKE2b-256 ba632ae6fb9624ba9bf45407084c34e49e0b52e637ea2b69105f373c17718355

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_guard-2.2.2-py3-none-any.whl:

Publisher: release.yml on fxstein/ascii-guard

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