ASCII Guard
Fix and validate alignment issues in ASCII box-drawing diagrams in markdown code blocks.
What It Does
ASCII boxes drawn with Unicode characters (┌┐└┘│─ and ╔╗╚╝║═) often have misaligned right borders because content lines are wider or narrower than the border. ASCII Guard detects these mismatches and fixes them automatically by adjusting borders and padding content to a consistent width.
Before
code
┌──────────────────────────────┐ │ Context Personalization │ ← right │ doesn't align with ┐ │ (welcome msg, ICP, │ └──────────────┬───────────────┘ ← ┘ doesn't align with ┐ either
After
code
┌───────────────────────────────┐ │ Context Personalization │ ← all right borders aligned │ (welcome msg, ICP, │ └──────────────┬────────────────┘
How to Run
The script is at: scripts/ascii_guard.py
It has zero dependencies (pure Python 3, stdlib only), so run it directly:
Fix files in-place (default)
bash
python3 ${SKILL_DIR}/scripts/ascii_guard.py <file.md>
python3 ${SKILL_DIR}/scripts/ascii_guard.py docs/
Check only (report issues, no modifications)
bash
python3 ${SKILL_DIR}/scripts/ascii_guard.py --check <file.md>
Preview changes as unified diff
bash
python3 ${SKILL_DIR}/scripts/ascii_guard.py --diff <file.md>
Multiple files or directories
bash
python3 ${SKILL_DIR}/scripts/ascii_guard.py docs/*.md README.md
python3 ${SKILL_DIR}/scripts/ascii_guard.py docs/ # recursively finds *.md
Verbose mode (shows box counts per file)
bash
python3 ${SKILL_DIR}/scripts/ascii_guard.py -v <file.md>
When to Use This Skill
Invoke when:
- •Creating or editing ASCII architecture diagrams in markdown
- •User mentions "ASCII alignment", "diagram alignment", "box drawing", or "fix ascii"
- •Before committing docs with box-drawing diagrams
- •After generating or editing flowcharts in code blocks
- •When boxes look misaligned in rendered markdown
How It Works
- •Finds markdown code blocks (between
```markers) - •Detects boxes by matching
┌...┐top borders with└...┘bottom borders at the same column - •For each box, calculates the maximum inner width across all lines (borders + content)
- •Extends narrower borders by adding
─to the right (preserving┬/┴connector positions) - •Pads narrower content lines with trailing spaces
- •Processes side-by-side boxes right-to-left to avoid column shifting
Supported Characters
Single-Line
code
Corners: ┌ ┐ └ ┘ Lines: ─ │ T-joins: ├ ┤ ┬ ┴
Double-Line
code
Corners: ╔ ╗ ╚ ╝ Lines: ═ ║ T-joins: ╠ ╣ ╦ ╩
Exit Codes
| Code | Meaning |
|---|---|
| 0 | All boxes aligned (or fixed) |
| 1 | Issues found (with --check/--diff) |
What It Preserves
- •Annotations after box borders (
<-- NEW,<-- UPDATED) - •Vertical connector positions (
┬/┴stay at same column) - •Side-by-side box layout
- •Content that's already at max width (unchanged)
- •Everything outside code blocks (untouched)