Render markdown with syntax highlighting in the terminal
Project description
mdsyntax
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
Styling API
Style arbitrary text without markdown:
from mdsyntax import Style, style
# Static methods
print(Style.bold_text("important"))
print(Style.italic_text("emphasis"))
print(Style.color("warning", fg="red"))
print(Style.color("highlight", fg="white", bg="blue"))
# Chainable API
print(style("hello").bold().italic())
print(style("fancy").fg("cyan").underline())
print(style("rgb").fg((255, 100, 50))) # RGB colors
Available styles:
bold()/Style.bold_text()dim()/Style.dim_text()italic()/Style.italic_text()underline()/Style.underline_text()strikethrough()/Style.strike_text()fg(color)/bg(color)- named colors or RGB tuples
Named colors: black, red, green, yellow, blue, magenta, cyan, white
Features
- Headers (h1-h6) with color coding
- Bold, italic, bold italic
StrikethroughInline 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)draculaone-darkgruvbox-darknordgithub-dark
True Color
By default, mdsyntax 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 rendercode_style: Pygments style name for code blockscode_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())
Style / style()
Style text without markdown parsing:
from mdsyntax import Style, style
# Static (returns string directly)
Style.bold_text("text")
Style.color("text", fg="red", bg="white")
# Chainable (call str() or print directly)
style("text").bold().fg("blue")
Ansi
Direct access to ANSI escape codes:
from mdsyntax import Ansi
print(f"{Ansi.BOLD}Bold{Ansi.BOLD_OFF}")
print(f"{Ansi.FG_RED}Red{Ansi.FG_DEFAULT}")
print(f"{Ansi.rgb_fg(255, 100, 50)}RGB{Ansi.FG_DEFAULT}")
License
MIT
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
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 mdsyntax-0.2.0.tar.gz.
File metadata
- Download URL: mdsyntax-0.2.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfdf10e1da007453cc9925c1f1c81a0690d2f21a2c3304e3f58c206634b1ab29
|
|
| MD5 |
b2535f477a05eca40d7bb9746b5117fd
|
|
| BLAKE2b-256 |
b390c57956f3182c0898bacab340c8194dd5eeaf79fee8231adf613dff3935be
|
Provenance
The following attestation bundles were made for mdsyntax-0.2.0.tar.gz:
Publisher:
release.yml on Azaias/mdsyntax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdsyntax-0.2.0.tar.gz -
Subject digest:
bfdf10e1da007453cc9925c1f1c81a0690d2f21a2c3304e3f58c206634b1ab29 - Sigstore transparency entry: 783278092
- Sigstore integration time:
-
Permalink:
Azaias/mdsyntax@e32ce7263a0d9762078ac65c3e16b5f2f3e1bb27 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Azaias
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e32ce7263a0d9762078ac65c3e16b5f2f3e1bb27 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mdsyntax-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mdsyntax-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c77ccccc741b6eb97317aa83201b1f3450528ab2b5e10a7e11a9baeb170fa54a
|
|
| MD5 |
e024395237ce3fd6dd216762aa2aa949
|
|
| BLAKE2b-256 |
02e5c4ecaaa0dc4833f414f430e8763ceb12eef5dae4cbdf78d9110d0f28634b
|
Provenance
The following attestation bundles were made for mdsyntax-0.2.0-py3-none-any.whl:
Publisher:
release.yml on Azaias/mdsyntax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdsyntax-0.2.0-py3-none-any.whl -
Subject digest:
c77ccccc741b6eb97317aa83201b1f3450528ab2b5e10a7e11a9baeb170fa54a - Sigstore transparency entry: 783278162
- Sigstore integration time:
-
Permalink:
Azaias/mdsyntax@e32ce7263a0d9762078ac65c3e16b5f2f3e1bb27 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Azaias
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e32ce7263a0d9762078ac65c3e16b5f2f3e1bb27 -
Trigger Event:
push
-
Statement type: