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.0.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.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mdsyntax-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 e0f6f27cdcf59d47073d8419063b8a0ff37a0d8a5cb24e254ac81e5dafc49e2b
MD5 964554f1fbac2475ab3da4c587f02678
BLAKE2b-256 8ce65089c8a4f4d7625df404e832dbe3201713e13bcb6df12f17ab9e4cfc8dbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdsyntax-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: mdsyntax-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec81dc1ec77d40d77bf399d25e3637e229fc4c9f52041740941f6062a3d10e74
MD5 5f861d16582a810d602c7a1f4d1a4623
BLAKE2b-256 2798a1efeef12026b9978cba785f1d6015ab60ff4df6360406d5892a09371e61

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdsyntax-0.1.0-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