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
## Additional Features
### Interactive Menus
```python
import clickmd
choice = clickmd.menu("## Choose Provider", [
("groq", "Groq โ fast & free tier"),
("openrouter", "OpenRouter โ multi-model"),
("ollama", "Ollama โ local, no API key"),
])
Tables & Panels
from clickmd import table, panel
table(
headers=["Name", "Version", "Status"],
rows=[
["clickmd", "1.1.0", "โ
OK"],
["click", "8.1.7", "โ
OK"],
],
)
panel("Deployment complete!", title="Success", style="green")
Logger
from clickmd import get_logger
log = get_logger("myapp")
log.info("Starting process...")
log.success("Build complete!")
log.warning("Deprecated API")
log.error("Connection failed")
Themes
from clickmd import set_theme, list_themes
list_themes() # Show available themes
set_theme("monokai") # Switch theme
Developer Tools
from clickmd import debug, inspect_obj, diff, tree
debug(my_variable) # Pretty-print with type info
inspect_obj(my_object) # Show object attributes
diff("old text", "new text") # Side-by-side diff
tree("/path/to/dir") # Directory tree
Examples
See the examples/ directory for 17 demo scripts:
basic.pyโ Basic markdown renderingcli_app.pyโ Full CLI application with Clickcustom_renderer.pyโ Custom renderer configurationcolored_logging.pyโ Log-style colored outputphase1_features.pyโ Tables, panels, blockquotes, checklistsphase3_progress.pyโ Progress bars, spinners, live updatesphase4_themes.pyโ Theming systemphase5_devtools.pyโ Debug, inspect, diff, tree toolslogger_usage.pyโ Structured loggingmarkdown_help.pyโ Markdown help formatter for Click
Project Structure
clickmd/
โโโ src/clickmd/ # Package source (src layout)
โ โโโ __init__.py # Public API: md(), echo(), menu(), select()
โ โโโ renderer.py # Core markdown renderer & syntax highlighting
โ โโโ decorators.py # Click decorator re-exports
โ โโโ help.py # Markdown help formatter for Click
โ โโโ logger.py # Markdown-aware structured logger
โ โโโ progress.py # Progress bars, spinners, live updates
โ โโโ themes.py # Color themes & NO_COLOR support
โ โโโ devtools.py # Debug, inspect, diff, tree tools
โ โโโ rich_backend.py # Optional Rich integration
โ โโโ py.typed # PEP 561 type marker
โโโ tests/ # Test suite (69 tests)
โโโ examples/ # 17 demo scripts
โโโ docs/ # API reference & contributing guide
โโโ scripts/ # Build & version tools
โโโ tools/ # Markdown-to-HTML converter
โโโ pyproject.toml # Project config (hatchling)
โโโ Makefile # Dev commands
Development
# Clone the repository
git clone https://github.com/wronai/clickmd.git
cd clickmd
# Install development dependencies
pip install -e ".[dev,click]"
# Run tests
make test
# Run linter & format
make lint
make format
# Build & publish
make build
make publish
License
Apache License 2.0 - see LICENSE for details.
Author
Created by Tom Sapletta - tom@sapletta.com
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.1.4.tar.gz.
File metadata
- Download URL: clickmd-1.1.4.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22f7a6fec042c4f8c07282496917cfc4f9490194752688968e0bdafa0cfce14f
|
|
| MD5 |
cbce8d72aa4ffc9921935ff5130e667c
|
|
| BLAKE2b-256 |
3e652711afcac21511a0017ce8da5a044ab935ea83779bd9f33caea1dab56b74
|
File details
Details for the file clickmd-1.1.4-py3-none-any.whl.
File metadata
- Download URL: clickmd-1.1.4-py3-none-any.whl
- Upload date:
- Size: 42.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5d0bfdb6238bc9f1a17a73b5306a6795d2d0be9a4ca1c2f56f19f55b66a0070
|
|
| MD5 |
72aac4d165275ebfeca0f03614bff491
|
|
| BLAKE2b-256 |
965a01cf5ca80ef0889c33f9f5884eb5d1cb050d585b04abe82ef1f9c08bf53b
|