Skip to content

semcod/clickmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

clickmd

PyPI version Python 3.10+ License: Apache-2.0 Tests codecov

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 rendering
  • cli_app.py β€” Full CLI application with Click
  • custom_renderer.py β€” Custom renderer configuration
  • colored_logging.py β€” Log-style colored output
  • phase1_features.py β€” Tables, panels, blockquotes, checklists
  • phase3_progress.py β€” Progress bars, spinners, live updates
  • phase4_themes.py β€” Theming system
  • phase5_devtools.py β€” Debug, inspect, diff, tree tools
  • logger_usage.py β€” Structured logging
  • markdown_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

Licensed under Apache-2.0.

Licensed under Apache-2.0.

Licensed under Apache-2.0.

Licensed under Apache-2.0.

Apache License 2.0 - see LICENSE for details.

Author

Tom Sapletta

Tom Sapletta

Tom Sapletta

Tom Sapletta

Created by Tom Sapletta - tom@sapletta.com

Contributing

Contributions are welcome! Please read our Contributing Guide first.

Related Projects

  • Click - Python CLI framework
  • Rich - Rich text and beautiful formatting

About

Markdown rendering for CLI applications with syntax highlighting.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors