markdown-tool
markdown-tool is a powerful command-line utility for converting and formatting
Markdown documents to various formats including HTML, LaTeX, and abstract syntax
tree (AST) representations.
Features
- Multiple Output Formats: Convert Markdown to HTML, LaTeX, JSON-based AST, and YAML-based AST formats
- Markdown Formatting: Format and beautify Markdown files with consistent style and configurable options
- LaTeX Support: Generate LaTeX documents with configurable table styles and code highlighting
- Configurable Output: Customize formatting options for each output format
- Dry-run Mode: Check formatting requirements without modifying files
- Lightweight CLI: Zero-dependency binary, easily scriptable in CI/CD workflows
- Round-trip Capable: Parse and regenerate Markdown with consistent formatting
Installation
Install via crates.io (requires Rust and Cargo):
Alternatively, download pre-built packages:
-
Debian (
.deb):
sudo dpkg -i markdown-tool__.deb
## Usage
The tool uses a modern subcommand structure for better organization:
```text
Usage: markdown-tool <COMMAND>
Commands:
convert-to Convert to various output formats
format Format markdown files
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Convert Command
Convert documents between different formats:
Usage: markdown-tool convert-to [OPTIONS] <COMMAND>
Commands:
markdown Convert to Markdown format
html Convert to HTML format
latex Convert to LaTeX format
ast-json Convert to AST JSON format
ast-yaml Convert to AST YAML format
Options:
-f, --from <FROM> Input format: markdown, ast-json, ast-yaml [default: markdown]
-h, --help Print help
Format Command
Format and beautify Markdown files:
Usage: markdown-tool format [OPTIONS] <FILES>...
Arguments:
<FILES>... Files to format
Options:
--width <WIDTH>
Width for markdown output formatting [default: 80]
--spaces-before-list-item <SPACES_BEFORE_LIST_ITEM>
Number of spaces before list items (0-3) [default: 1]
--no-empty-line-before-list
Disable empty line before lists
-n, --dry-run
Check if files need formatting without modifying them
-h, --help
Print help
Quick Start
Most common use cases:
Convert Markdown to HTML:
|
# Output: <h1>Hello World</h1>
Format Markdown files:
# Format single file
# Format multiple files
# Check if files need formatting (dry-run)
# or with short option
Supported Formats
| Format | Input | Output | Description |
|---|---|---|---|
| markdown | ✅ | ✅ | Standard Markdown text |
| html | ❌ | ✅ | HTML-formatted text |
| latex | ❌ | ✅ | LaTeX document format |
| ast-json | ✅ | ✅ | JSON-formatted abstract syntax tree |
| ast-yaml | ✅ | ✅ | YAML-formatted abstract syntax tree |
Examples
Basic Conversions
Convert Markdown to HTML (default input format):
Convert Markdown to LaTeX with custom formatting:
Convert Markdown to JSON AST:
Advanced Usage
Convert JSON AST back to Markdown:
Convert YAML AST to Markdown with custom width:
Pretty-print Markdown with custom formatting:
Formatting Files
Format Markdown files in place with consistent styling:
# Format a single file
# Format multiple files at once
# Format with custom options
# Check if files need formatting without modifying them
# Exit code 1 if any files need formatting (useful for CI)
if ; then
else
fi
Format-Specific Options
Markdown Output
HTML Output
LaTeX Output
Available LaTeX options:
- Table styles:
tabular(default),longtabu,booktabs - Code styles:
verbatim(default),listings,minted
LaTeX Package Requirements
Depending on the options used, you may need these LaTeX packages:
hyperref- for links (\href)graphicx- for images (\includegraphics)ulem- for strikethrough (\sout)booktabs- if using--table-style booktabslongtabu- if using--table-style longtabulistings- if using--code-style listingsminted- if using--code-style minted(requires Python + Pygments)
📚 Documentation
Contributing
Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request on GitHub.
License
Dual-licensed under MIT. See LICENSE for details.