Skip to main content

Render markdown with syntax highlighting in the terminal

Project description

mdsyntax

PyPI version Python versions CI License: MIT

Render markdown with syntax highlighting in the terminal.

Installation

pip install mdsyntax

Usage

Python API

from mdsyntax import md_print, md_render

# Print directly to terminal
md_print("""
# Hello World

This is **bold** and *italic* text.

```python
def greet(name):
    return f"Hello, {name}!"

""")

Get ANSI string for further processing

output = md_render("Some inline code here")


### Command Line

```bash
# Render a file
mdsyntax README.md

# Pipe from stdin
echo "# Hello" | mdsyntax

# Use a different syntax theme
mdsyntax --style dracula document.md

# List available themes
mdsyntax --list-styles

Features

  • Headers (h1-h6) with color coding
  • Bold, italic, bold italic
  • Strikethrough
  • Inline code
  • Fenced code blocks with syntax highlighting
  • Links
  • Unordered and ordered lists
  • Task lists
  • Blockquotes
  • Horizontal rules

Configuration

Code Styles

Any Pygments style is supported. Popular options:

  • monokai (default)
  • dracula
  • one-dark
  • gruvbox-dark
  • nord
  • github-dark

True Color

By default, md-print auto-detects 24-bit color support via the COLORTERM environment variable. You can override this:

# Force 256-color mode
md_print(text, true_color=False)

# Force true color
md_print(text, true_color=True)

API Reference

md_print(text, *, code_style="monokai", code_width=None, true_color=None)

Print markdown to terminal.

  • text: Markdown string to render
  • code_style: Pygments style name for code blocks
  • code_width: Fixed width for code blocks (default: terminal width)
  • true_color: Use 24-bit color (default: auto-detect)

md_render(...) -> str

Same arguments as md_print, but returns the ANSI-formatted string instead of printing.

MarkdownRenderer

Dataclass for more control:

from mdsyntax import MarkdownRenderer

renderer = MarkdownRenderer(
    code_style="dracula",
    code_width=80,
    true_color=True,
)
output = renderer.render(markdown_text)

SyntaxHighlighter

Standalone code highlighter:

from mdsyntax import SyntaxHighlighter

hl = SyntaxHighlighter(style="monokai")
print(hl.highlight("print('hello')", "python"))
print(SyntaxHighlighter.available_styles())

License

MIT

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdsyntax-0.1.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdsyntax-0.1.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file mdsyntax-0.1.1.tar.gz.

File metadata

  • Download URL: mdsyntax-0.1.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mdsyntax-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b7757bd1e77364ecdd385603770e2b01349cdd22d8b44aac928f3e0c81029e2b
MD5 03ee535fc222a34f3b0c415475f0351c
BLAKE2b-256 6b8d7198c835fe9940a859f26ed29066a549e81900af8457eac21a7fd54aa569

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdsyntax-0.1.1.tar.gz:

Publisher: release.yml on Azaias/mdsyntax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mdsyntax-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mdsyntax-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mdsyntax-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 800775050e339cebae0d2d0166fcb5bef32a091539708f2b2024916401cce41f
MD5 5ecff7389136c3a59df288dfb977a105
BLAKE2b-256 658225210e73eed8812babb563618a2b96050b0418ce45c228db21a6021d42f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdsyntax-0.1.1-py3-none-any.whl:

Publisher: release.yml on Azaias/mdsyntax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page