Markdown rendering for CLI applications with syntax highlighting
Project description
clickmd
Markdown rendering for CLI applications with syntax highlighting.
clickmd provides beautiful terminal output with:
- 🎨 Syntax highlighting for code blocks (Python, TypeScript, JSON, YAML, Bash, etc.)
- 📝 Markdown rendering with headers, bold, links, and more
- 🔧 Zero dependencies for core functionality
- 🖱️ Optional Click integration for CLI decorators
Installation
# Core package (no dependencies)
pip install clickmd
# With Click support
pip install clickmd[click]
Quick Start
Basic Usage (No Dependencies)
from clickmd import md, echo
# Render markdown with syntax highlighting
md("""
# Hello World
This is **bold** and this is a [link](https://example.com).
```python
def greet(name: str) -> str:
return f"Hello, {name}!"
""")
Smart echo - auto-detects markdown
echo("## Status Update") echo("Regular text without markdown")
### With Click Integration
```python
import clickmd as click
@click.group()
def cli():
"""My awesome CLI tool"""
pass
@cli.command()
@click.option("--name", "-n", default="World")
def hello(name: str):
"""Say hello"""
click.md(f"""
## 👋 Hello, {name}!
Welcome to **clickmd** - making CLIs beautiful.
""")
if __name__ == "__main__":
cli()
Features
Syntax Highlighting
clickmd provides syntax highlighting for multiple languages:
| Language | Extensions | Highlight Features |
|---|---|---|
| Python | .py |
Keywords, strings, comments, decorators |
| TypeScript/JavaScript | .ts, .js |
Keywords, strings, template literals |
| JSON | .json |
Keys, strings, numbers, booleans |
| YAML | .yaml, .yml |
Keys, values, comments |
| Bash/Shell | .sh, .bash |
Commands, comments |
| Markdown | .md |
Headers, bold, links |
| Log | .log |
Errors (red), warnings (yellow), success (green) |
Markdown Elements
from clickmd import md
md("""
# Heading 1
## Heading 2
### Heading 3
**Bold text** and regular text.
[Links](https://example.com) are supported.
```python
# Code blocks with syntax highlighting
print("Hello, World!")
- List items
- Are rendered
- Correctly """)
### MarkdownRenderer Class
For more control, use the `MarkdownRenderer` class directly:
```python
from clickmd import MarkdownRenderer
import sys
renderer = MarkdownRenderer(use_colors=True, stream=sys.stdout)
renderer.heading(1, "My Title")
renderer.codeblock("python", 'print("Hello!")')
Progress and Status Output
from clickmd import md
# Log-style output with automatic coloring
md("""
```log
🚀 Starting process...
📦 Installing dependencies...
✅ Build successful!
⚠️ Warning: deprecated API
🛑 Error: connection failed
""")
## API Reference
### Core Functions
#### `md(text: str) -> None`
Render markdown text with syntax highlighting.
#### `echo(message, file=None, nl=True, err=False, color=None) -> None`
Smart echo that auto-detects markdown and renders it.
#### `render_markdown(text, text_lang="markdown", stream=None, use_colors=True) -> None`
Low-level markdown rendering function.
#### `get_renderer(stream=None, use_colors=True) -> MarkdownRenderer`
Get a `MarkdownRenderer` instance.
### Click Decorators (requires `click` package)
When `click` is installed, these decorators are available:
- `@clickmd.group()` - Create a command group
- `@clickmd.command()` - Create a command
- `@clickmd.option()` - Add an option
- `@clickmd.argument()` - Add an argument
- `@clickmd.pass_context` - Pass Click context
- `clickmd.Choice` - Choice type
- `clickmd.Path` - Path type
### Constants
- `CLICK_AVAILABLE: bool` - Whether Click is installed
## Examples
See the [examples/](examples/) directory for more usage examples:
- `examples/basic.py` - Basic markdown rendering
- `examples/cli_app.py` - Full CLI application with Click
- `examples/custom_renderer.py` - Custom renderer configuration
- `examples/logging.py` - Log-style colored output
## Development
```bash
# Clone the repository
git clone https://github.com/wronai/clickmd.git
cd clickmd
# Install development dependencies
pip install -e ".[dev]"
# Run tests
make test
# Run linter
make lint
# Format code
make format
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please read our Contributing Guide first.
Related Projects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clickmd-1.0.0.tar.gz.
File metadata
- Download URL: clickmd-1.0.0.tar.gz
- Upload date:
- Size: 22.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
108a99513e9aa1ce80905c797fcb0222a194b6e03a7b8b149f318b8660b63c96
|
|
| MD5 |
82600faa8db9147e0621bf63e2eae0c7
|
|
| BLAKE2b-256 |
77ed264b42fe1bd92846d83190a0560d927ea956947829bd88c71eeb27073a78
|
File details
Details for the file clickmd-1.0.0-py3-none-any.whl.
File metadata
- Download URL: clickmd-1.0.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed1d881d41ef92c9050689f4bddb27da5d9df2dd5b75786ee2c1346f4bb585ad
|
|
| MD5 |
bb1e69119e9be381d6fe8cf23bd2647b
|
|
| BLAKE2b-256 |
ece7faea706d132e30c5bce7b58ef51f6f2dedff257904b11e9af137040bf05b
|