mdriver - Streaming Markdown Printer
A streaming markdown printer for the terminal that renders GitHub Flavored Markdown with ANSI escape codes. The key feature is incremental emission: blocks are emitted immediately once parsed, not waiting for the entire document.
Installation
From crates.io (Recommended)
From Pre-built Binaries
Download the latest release for your platform from the GitHub Releases page:
- Linux:
mdriver-x86_64-unknown-linux-gnu.tar.gzormdriver-x86_64-unknown-linux-musl.tar.gz - macOS:
mdriver-x86_64-apple-darwin.tar.gz(Intel) ormdriver-aarch64-apple-darwin.tar.gz(Apple Silicon)
Extract and add to your PATH:
From Source
The binary will be available at target/release/mdriver.
Usage
# Read from file
# Pipe markdown from a file
|
# Pipe from echo
|
# Redirect from file
# Use a specific syntax highlighting theme
# Set default theme via environment variable
MDSTREAM_THEME="Solarized (dark)"
# List available themes
# Show help
Example
|
Output (with ANSI colors in your terminal):
- # Demo (in blue and bold)
- This is bold and italic
Features
- ✅ Streaming: Renders markdown incrementally as it arrives
- ✅ ATX Headings:
# Headingwith blue/bold formatting - ✅ Paragraphs: Text blocks with inline formatting
- ✅ Code Blocks: Fenced blocks with
```and syntax highlighting - ✅ Lists: Unordered (
-) and ordered (1.) lists - ✅ Inline Formatting:
**bold**,*italic*,`code`with nested support - ✅ Hyperlinks:
[text](url)converted to clickable OSC8 terminal links - ✅ Syntax Highlighting: 100+ languages supported with customizable themes
- ✅ ANSI Colors: Beautiful terminal output with 24-bit true color
- ✅ Zero Warnings: Strict clippy linting, no compiler warnings
Syntax Highlighting Themes
mdstream uses the syntect library for syntax highlighting, supporting 100+ languages with customizable color themes.
Available Themes
Use mdstream --list-themes to see all available themes. Popular options include:
- InspiredGitHub - Bright, vibrant colors inspired by GitHub's syntax highlighting
- Solarized (dark) - The classic Solarized dark color scheme
- Solarized (light) - Solarized optimized for light backgrounds
- base16-ocean.dark - Calm oceanic colors (default)
- base16-mocha.dark - Warm mocha tones
- base16-eighties.dark - Retro 80s aesthetic
Setting a Theme
There are three ways to configure the theme (in order of precedence):
- Command-line flag:
mdstream --theme "InspiredGitHub" file.md - Environment variable:
export MDSTREAM_THEME="Solarized (dark)" - Default:
base16-ocean.dark
Example
# Use InspiredGitHub theme
# Set environment variable for persistent default
# Combine with piping
MDSTREAM_THEME="base16-mocha.dark" |
Conformance Test Suite
This project uses a comprehensive conformance test suite to verify streaming behavior, markdown parsing, and ANSI formatting.
Test Structure
Tests are written as TOML fixture files that specify:
- Input chunks: Markdown arriving incrementally (simulating streaming)
- Expected emissions: What should be output after each chunk (empty string if block incomplete)
- Raw ANSI codes: Actual escape sequences for exact terminal output matching
Test Format Example
= "heading-basic"
= "Heading should emit after newline is received"
[[]]
= "#"
= ""
[[]]
= " Hello"
= ""
[[]]
= "\n"
= "\u001b[1;34m# Hello\u001b[0m\n"
Key Points:
- Each
[[chunks]]represents a piece of markdown fed to the parser input: The markdown chunkemit: Expected terminal output (empty""means no emission yet)- ANSI codes use
\u001bformat (TOML Unicode escape)
Test Categories
Tests are organized in tests/fixtures/:
blocks/- Individual block types (headings, paragraphs, code blocks, lists)streaming/- Incremental emission and block boundary detectionansi/- ANSI escape sequence formatting (bold, italic, colors)complex/- Real-world documents with mixed block types
Running Tests
# Run all conformance tests
# Run specific test category
# Run with verbose output
Test Output
When tests fail, you see clear diagnostics:
Running 4 tests from blocks...
✗ heading-basic
Heading should emit after newline is received
Chunk 4 failed:
Input: "\n"
Expected: "\u{1b}[1;34m# Hello\u{1b}[0m\n"
Actual: ""
Writing New Tests
- Create a
.tomlfile in the appropriatetests/fixtures/subdirectory - Define test name and description
- Add chunks with input and expected emissions
- Use
\u001bfor ESC character in ANSI codes
Example ANSI codes:
- Bold:
\u001b[1m...\u001b[0m - Italic:
\u001b[3m...\u001b[0m - Color:
\u001b[1;34m...\u001b[0m(bold blue) - Background:
\u001b[48;5;235m...\u001b[0m
Current Status
All Systems Operational ✅
- ✅ Parser Implementation: Complete with full streaming support
- ✅ Test Suite: 8 conformance tests - all passing
- ✅ CLI: Working binary for command-line usage
- ✅ Code Quality: Zero compiler warnings, zero clippy errors
- ✅ Documentation: Comprehensive CLAUDE.md for AI assistants
Test Coverage:
- Block types: heading, paragraph, code block, list
- Streaming: incremental emission, block boundaries
- Formatting: inline ANSI codes (bold, italic, code)
- Complex: mixed document scenarios
Future Enhancements
Potential areas for expansion:
- Additional GFM features (tables, task lists, strikethrough)
- Blockquotes and nested structures
- Terminal width awareness and text wrapping
- Performance benchmarks for large documents
- Image rendering using terminal graphics protocols
Project Structure
mdstream/
├── Cargo.toml
├── README.md
├── CLAUDE.md # AI assistant context and guidelines
├── gfmspec.md # GitHub Flavored Markdown specification
├── .clippy.toml # Clippy linting configuration
├── src/
│ ├── lib.rs # StreamingParser implementation
│ └── main.rs # CLI binary
└── tests/
├── conformance.rs # Test runner
├── common/
│ ├── mod.rs
│ └── fixture_loader.rs
└── fixtures/
├── blocks/ # 4 tests: heading, paragraph, code_block, list
├── streaming/ # 2 tests: incremental_emit, block_boundaries
├── ansi/ # 1 test: inline_formatting
└── complex/ # 1 test: mixed_document
Design Philosophy
- Streaming First: Blocks emit immediately when complete, enabling real-time rendering
- Test-Driven: Comprehensive test suite defines expected behavior before implementation
- Exact Output: Tests verify exact ANSI codes, not just content
- Incremental Testing: Tests verify streaming property, not just final output
- Zero Tolerance: No compiler warnings, no clippy errors - strict code quality standards
Development
Code Quality Standards
This project maintains strict code quality requirements:
# All must pass before committing:
See CLAUDE.md for comprehensive development guidelines and best practices.
Contributing
- Fork the repository
- Create a feature branch
- Write tests first (TDD approach)
- Implement feature to pass tests
- Ensure all quality checks pass
- Submit pull request
Key Files
CLAUDE.md: Comprehensive guide for AI assistants and developersgfmspec.md: GitHub Flavored Markdown specification (authoritative source).clippy.toml: Linting configurationtests/fixtures/: Conformance test cases in TOML format
License
MIT