Skip to content

Real-World Formatting & Linting Examples

import { Tabs, TabItem } from ‘@astrojs/starlight/components’;

This guide demonstrates concrete examples of how agent-md transforms bloated Markdown into concise, LLM-optimized documents.


Here is a standard Markdown document generated by human authors or older AI templates:

# My Project
## Overview
This is a really awesome project with many outstanding features:
| Feature | Description | Status |
|:---|:---|:---|
| API | Complete RESTful API | ✅ Complete |
| UI | Modern user interface | 🚧 In Progress |
| Tests | Unit tests and integration tests | ✅ Complete |
### Steps to Follow
1. Clone repository
2. Install dependencies: `bun i`
3. Run server: `bun dev`
>Note: Make sure you have Node.js 22+ installed!
Terminal window
agent-md lint document.md

The linter detects token-wasting patterns:

{
"valid": false,
"errors": [
{ "line": 8, "column": 1, "message": "Complex table alignment detected", "rule": "table-syntax" }
],
"warnings": []
}
Terminal window
agent-md fmt document.md
# My Project
## Overview
This is a really awesome project with many outstanding features:
| Feature | Description | Status |
|---|---|---|
| API | Complete RESTful API | (Complete) |
| UI | Modern user interface | (In Progress) |
| Tests | Unit tests and integration tests | (Complete) |
## Steps to Follow
1. Clone repository
2. Install dependencies: `bun i`
3. Run server: `bun dev`
Note: Make sure you have Node.js 22+ installed.
  • Token count: Reduced by ~18–22%.
  • Table normalization: Separator line stripped from :---: to |---|---|.
  • Spacing: No redundant trailing spaces or padding inside table cells.
  • Section Extraction: Clean headings allow instant retrieval via agent-md read document.md --content "## Steps to Follow".

Example 2: Nested Shell Scripts and Indentation

Section titled “Example 2: Nested Shell Scripts and Indentation”
Terminal window
# Setup script
bun install # Install all packages
bun run build # Build production bundles
bun test # Run all integration tests
Terminal window
# Setup script
bun install # Install all packages
bun run build # Build production bundles
bun test # Run all integration tests

The formatter collapses multi-space gaps before # comments into a single space, saving 6–10 tokens on every commented line.


my-app/
├── public/
│ ├── favicon.svg
│ └── robots.txt
├── src/
│ ├── index.ts
│ └── utils.ts
└── package.json
my-app/
├─public/
│ ├─favicon.svg
│ └─robots.txt
├─src/
│ ├─index.ts
│ └─utils.ts
└─package.json
  • Replaces three-byte UTF-8 glyphs ├── and └── with compact two-character markers ├─ and └─.
  • Strips empty spacer lines and standardizes branch indentation.