mdsyntax 0.1.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/.github/workflows/ci.yml +3 -1
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/.gitignore +3 -0
- mdsyntax-0.3.0/CHANGELOG.md +81 -0
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/CONTRIBUTING.md +2 -2
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/LICENSE +1 -1
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/PKG-INFO +61 -6
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/README.md +59 -4
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/pyproject.toml +4 -1
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/src/mdsyntax/__init__.py +12 -1
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/src/mdsyntax/cli.py +31 -8
- mdsyntax-0.3.0/src/mdsyntax/renderer.py +731 -0
- mdsyntax-0.3.0/tests/test_renderer.py +478 -0
- mdsyntax-0.1.1/CHANGELOG.md +0 -23
- mdsyntax-0.1.1/src/mdsyntax/renderer.py +0 -368
- mdsyntax-0.1.1/tests/test_renderer.py +0 -185
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/.github/workflows/release.yml +0 -0
- {mdsyntax-0.1.1 → mdsyntax-0.3.0}/src/mdsyntax/py.typed +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.3.0] - 2026-09-06
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Links following bold, italic, or strikethrough text on the same line no longer
|
|
15
|
+
produce corrupted escape sequences; links are now isolated before emphasis
|
|
16
|
+
processing
|
|
17
|
+
- URLs containing `__` or `*` (for example `#object.__init__`) are no longer
|
|
18
|
+
mangled by emphasis rules
|
|
19
|
+
- Code block background no longer disappears mid-line for styles with bold or
|
|
20
|
+
italic tokens (dracula, one-dark, nord, github-dark, default, ...)
|
|
21
|
+
- CLI reads files and stdin as UTF-8 and writes UTF-8 to stdout, fixing
|
|
22
|
+
mojibake and `UnicodeEncodeError` on Windows when output is piped
|
|
23
|
+
- CLI reports an unknown `--style` as a one-line error (exit code 2) instead of
|
|
24
|
+
a traceback; `SyntaxHighlighter` and `MarkdownRenderer` raise `ValueError`
|
|
25
|
+
- 256-color mode (`true_color=False`) no longer emits 24-bit escapes for the
|
|
26
|
+
code block background, blockquotes, or link URLs
|
|
27
|
+
- Code block padding accounts for wide (CJK, emoji) and combining characters;
|
|
28
|
+
tabs are expanded to four spaces
|
|
29
|
+
- Spaced asterisks such as `2 * 3 * 4` are no longer rendered as italic
|
|
30
|
+
- Fenced code blocks honour fence length, so a four-backtick fence can contain
|
|
31
|
+
a three-backtick fence; `~~~` fences are supported
|
|
32
|
+
- Header and blockquote colors are restored after inline code and links
|
|
33
|
+
- Link URLs use a muted color instead of dim, so a link inside bold text no
|
|
34
|
+
longer switches bold off early
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- Package version is read from `mdsyntax.__version__` at build time
|
|
39
|
+
- Project metadata (author, URLs) now points at the real repository
|
|
40
|
+
|
|
41
|
+
## [0.2.0] - 2025-12-31
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- New `Style` class for styling arbitrary text
|
|
46
|
+
- Static methods: `Style.bold_text()`, `Style.italic_text()`, `Style.color()`, etc.
|
|
47
|
+
- Chainable API: `style("text").bold().italic().fg("red")`
|
|
48
|
+
- RGB color support via `Style.color(text, fg=(255, 0, 0))`
|
|
49
|
+
- `Ansi` class now exported for direct access to ANSI codes
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
- Switched from `colorama.init(autoreset=True)` to `colorama.just_fix_windows_console()` for better compatibility
|
|
54
|
+
- Code blocks now expand width to fit long lines instead of truncating
|
|
55
|
+
- Use targeted ANSI resets instead of full reset for better style preservation
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- Inline code in blockquotes no longer breaks italic styling for subsequent text
|
|
60
|
+
- Code block width now properly constrains content
|
|
61
|
+
|
|
62
|
+
## [0.1.1] - 2025-12-24
|
|
63
|
+
|
|
64
|
+
### Changed
|
|
65
|
+
|
|
66
|
+
- Version bump; no functional changes
|
|
67
|
+
|
|
68
|
+
## [0.1.0] - 2025-12-24
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
|
|
72
|
+
- Initial release
|
|
73
|
+
- Markdown rendering with ANSI formatting
|
|
74
|
+
- Syntax highlighting for code blocks (powered by Pygments)
|
|
75
|
+
- Support for headers, bold, italic, strikethrough, inline code
|
|
76
|
+
- Support for lists (ordered, unordered, task lists)
|
|
77
|
+
- Support for blockquotes and horizontal rules
|
|
78
|
+
- Support for links
|
|
79
|
+
- CLI tool (`mdsyntax`)
|
|
80
|
+
- Auto-detection of 24-bit true color support
|
|
81
|
+
- Configurable code block styling and width
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: mdsyntax
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Render markdown with syntax highlighting in the terminal
|
|
5
5
|
Project-URL: Homepage, https://github.com/Azaias/mdsyntax
|
|
6
6
|
Project-URL: Repository, https://github.com/Azaias/mdsyntax
|
|
@@ -51,7 +51,7 @@ pip install mdsyntax
|
|
|
51
51
|
|
|
52
52
|
### Python API
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
````python
|
|
55
55
|
from mdsyntax import md_print, md_render
|
|
56
56
|
|
|
57
57
|
# Print directly to terminal
|
|
@@ -68,7 +68,7 @@ def greet(name):
|
|
|
68
68
|
|
|
69
69
|
# Get ANSI string for further processing
|
|
70
70
|
output = md_render("Some `inline code` here")
|
|
71
|
-
|
|
71
|
+
````
|
|
72
72
|
|
|
73
73
|
### Command Line
|
|
74
74
|
|
|
@@ -86,6 +86,35 @@ mdsyntax --style dracula document.md
|
|
|
86
86
|
mdsyntax --list-styles
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
## Styling API
|
|
90
|
+
|
|
91
|
+
Style arbitrary text without markdown:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from mdsyntax import Style, style
|
|
95
|
+
|
|
96
|
+
# Static methods
|
|
97
|
+
print(Style.bold_text("important"))
|
|
98
|
+
print(Style.italic_text("emphasis"))
|
|
99
|
+
print(Style.color("warning", fg="red"))
|
|
100
|
+
print(Style.color("highlight", fg="white", bg="blue"))
|
|
101
|
+
|
|
102
|
+
# Chainable API
|
|
103
|
+
print(style("hello").bold().italic())
|
|
104
|
+
print(style("fancy").fg("cyan").underline())
|
|
105
|
+
print(style("rgb").fg((255, 100, 50))) # RGB colors
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Available styles:
|
|
109
|
+
- `bold()` / `Style.bold_text()`
|
|
110
|
+
- `dim()` / `Style.dim_text()`
|
|
111
|
+
- `italic()` / `Style.italic_text()`
|
|
112
|
+
- `underline()` / `Style.underline_text()`
|
|
113
|
+
- `strikethrough()` / `Style.strike_text()`
|
|
114
|
+
- `fg(color)` / `bg(color)` - named colors or RGB tuples
|
|
115
|
+
|
|
116
|
+
Named colors: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
|
|
117
|
+
|
|
89
118
|
## Features
|
|
90
119
|
|
|
91
120
|
- Headers (h1-h6) with color coding
|
|
@@ -114,7 +143,7 @@ Any [Pygments style](https://pygments.org/styles/) is supported. Popular options
|
|
|
114
143
|
|
|
115
144
|
### True Color
|
|
116
145
|
|
|
117
|
-
By default,
|
|
146
|
+
By default, mdsyntax auto-detects 24-bit color support via the `COLORTERM` environment variable. You can override this:
|
|
118
147
|
|
|
119
148
|
```python
|
|
120
149
|
# Force 256-color mode
|
|
@@ -166,11 +195,37 @@ print(hl.highlight("print('hello')", "python"))
|
|
|
166
195
|
print(SyntaxHighlighter.available_styles())
|
|
167
196
|
```
|
|
168
197
|
|
|
198
|
+
### `Style` / `style()`
|
|
199
|
+
|
|
200
|
+
Style text without markdown parsing:
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from mdsyntax import Style, style
|
|
204
|
+
|
|
205
|
+
# Static (returns string directly)
|
|
206
|
+
Style.bold_text("text")
|
|
207
|
+
Style.color("text", fg="red", bg="white")
|
|
208
|
+
|
|
209
|
+
# Chainable (call str() or print directly)
|
|
210
|
+
style("text").bold().fg("blue")
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### `Ansi`
|
|
214
|
+
|
|
215
|
+
Direct access to ANSI escape codes:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from mdsyntax import Ansi
|
|
219
|
+
|
|
220
|
+
print(f"{Ansi.BOLD}Bold{Ansi.BOLD_OFF}")
|
|
221
|
+
print(f"{Ansi.FG_RED}Red{Ansi.FG_DEFAULT}")
|
|
222
|
+
print(f"{Ansi.rgb_fg(255, 100, 50)}RGB{Ansi.FG_DEFAULT}")
|
|
223
|
+
```
|
|
224
|
+
|
|
169
225
|
## License
|
|
170
226
|
|
|
171
227
|
MIT
|
|
172
228
|
|
|
173
|
-
|
|
174
229
|
## Contributing
|
|
175
230
|
|
|
176
231
|
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
@@ -17,7 +17,7 @@ pip install mdsyntax
|
|
|
17
17
|
|
|
18
18
|
### Python API
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
````python
|
|
21
21
|
from mdsyntax import md_print, md_render
|
|
22
22
|
|
|
23
23
|
# Print directly to terminal
|
|
@@ -34,7 +34,7 @@ def greet(name):
|
|
|
34
34
|
|
|
35
35
|
# Get ANSI string for further processing
|
|
36
36
|
output = md_render("Some `inline code` here")
|
|
37
|
-
|
|
37
|
+
````
|
|
38
38
|
|
|
39
39
|
### Command Line
|
|
40
40
|
|
|
@@ -52,6 +52,35 @@ mdsyntax --style dracula document.md
|
|
|
52
52
|
mdsyntax --list-styles
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Styling API
|
|
56
|
+
|
|
57
|
+
Style arbitrary text without markdown:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from mdsyntax import Style, style
|
|
61
|
+
|
|
62
|
+
# Static methods
|
|
63
|
+
print(Style.bold_text("important"))
|
|
64
|
+
print(Style.italic_text("emphasis"))
|
|
65
|
+
print(Style.color("warning", fg="red"))
|
|
66
|
+
print(Style.color("highlight", fg="white", bg="blue"))
|
|
67
|
+
|
|
68
|
+
# Chainable API
|
|
69
|
+
print(style("hello").bold().italic())
|
|
70
|
+
print(style("fancy").fg("cyan").underline())
|
|
71
|
+
print(style("rgb").fg((255, 100, 50))) # RGB colors
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Available styles:
|
|
75
|
+
- `bold()` / `Style.bold_text()`
|
|
76
|
+
- `dim()` / `Style.dim_text()`
|
|
77
|
+
- `italic()` / `Style.italic_text()`
|
|
78
|
+
- `underline()` / `Style.underline_text()`
|
|
79
|
+
- `strikethrough()` / `Style.strike_text()`
|
|
80
|
+
- `fg(color)` / `bg(color)` - named colors or RGB tuples
|
|
81
|
+
|
|
82
|
+
Named colors: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
|
|
83
|
+
|
|
55
84
|
## Features
|
|
56
85
|
|
|
57
86
|
- Headers (h1-h6) with color coding
|
|
@@ -80,7 +109,7 @@ Any [Pygments style](https://pygments.org/styles/) is supported. Popular options
|
|
|
80
109
|
|
|
81
110
|
### True Color
|
|
82
111
|
|
|
83
|
-
By default,
|
|
112
|
+
By default, mdsyntax auto-detects 24-bit color support via the `COLORTERM` environment variable. You can override this:
|
|
84
113
|
|
|
85
114
|
```python
|
|
86
115
|
# Force 256-color mode
|
|
@@ -132,11 +161,37 @@ print(hl.highlight("print('hello')", "python"))
|
|
|
132
161
|
print(SyntaxHighlighter.available_styles())
|
|
133
162
|
```
|
|
134
163
|
|
|
164
|
+
### `Style` / `style()`
|
|
165
|
+
|
|
166
|
+
Style text without markdown parsing:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from mdsyntax import Style, style
|
|
170
|
+
|
|
171
|
+
# Static (returns string directly)
|
|
172
|
+
Style.bold_text("text")
|
|
173
|
+
Style.color("text", fg="red", bg="white")
|
|
174
|
+
|
|
175
|
+
# Chainable (call str() or print directly)
|
|
176
|
+
style("text").bold().fg("blue")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `Ansi`
|
|
180
|
+
|
|
181
|
+
Direct access to ANSI escape codes:
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from mdsyntax import Ansi
|
|
185
|
+
|
|
186
|
+
print(f"{Ansi.BOLD}Bold{Ansi.BOLD_OFF}")
|
|
187
|
+
print(f"{Ansi.FG_RED}Red{Ansi.FG_DEFAULT}")
|
|
188
|
+
print(f"{Ansi.rgb_fg(255, 100, 50)}RGB{Ansi.FG_DEFAULT}")
|
|
189
|
+
```
|
|
190
|
+
|
|
135
191
|
## License
|
|
136
192
|
|
|
137
193
|
MIT
|
|
138
194
|
|
|
139
|
-
|
|
140
195
|
## Contributing
|
|
141
196
|
|
|
142
197
|
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mdsyntax"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
8
|
description = "Render markdown with syntax highlighting in the terminal"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -56,6 +56,9 @@ Issues = "https://github.com/Azaias/mdsyntax/issues"
|
|
|
56
56
|
[project.scripts]
|
|
57
57
|
mdsyntax = "mdsyntax.cli:main"
|
|
58
58
|
|
|
59
|
+
[tool.hatch.version]
|
|
60
|
+
path = "src/mdsyntax/__init__.py"
|
|
61
|
+
|
|
59
62
|
[tool.hatch.build.targets.wheel]
|
|
60
63
|
packages = ["src/mdsyntax"]
|
|
61
64
|
|
|
@@ -5,22 +5,33 @@ Usage:
|
|
|
5
5
|
>>> from mdsyntax import md_print, md_render
|
|
6
6
|
>>> md_print("# Hello **world**")
|
|
7
7
|
>>> output = md_render("Some `code` here")
|
|
8
|
+
|
|
9
|
+
# Styling API
|
|
10
|
+
>>> from mdsyntax import Style, style
|
|
11
|
+
>>> print(Style.bold_text("important"))
|
|
12
|
+
>>> print(style("hello").italic().fg("red"))
|
|
8
13
|
"""
|
|
9
14
|
|
|
10
15
|
from mdsyntax.renderer import (
|
|
11
16
|
LANG_ALIASES,
|
|
17
|
+
Ansi,
|
|
12
18
|
MarkdownRenderer,
|
|
19
|
+
Style,
|
|
13
20
|
SyntaxHighlighter,
|
|
14
21
|
md_print,
|
|
15
22
|
md_render,
|
|
23
|
+
style,
|
|
16
24
|
)
|
|
17
25
|
|
|
18
|
-
__version__ = "0.
|
|
26
|
+
__version__ = "0.3.0"
|
|
19
27
|
__all__ = [
|
|
20
28
|
"md_print",
|
|
21
29
|
"md_render",
|
|
22
30
|
"MarkdownRenderer",
|
|
23
31
|
"SyntaxHighlighter",
|
|
24
32
|
"LANG_ALIASES",
|
|
33
|
+
"Style",
|
|
34
|
+
"style",
|
|
35
|
+
"Ansi",
|
|
25
36
|
"__version__",
|
|
26
37
|
]
|
|
@@ -1,16 +1,34 @@
|
|
|
1
|
-
"""Command-line interface for
|
|
1
|
+
"""Command-line interface for mdsyntax."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
6
6
|
import sys
|
|
7
|
+
from typing import IO
|
|
7
8
|
|
|
8
9
|
from mdsyntax import __version__, md_print
|
|
9
10
|
from mdsyntax.renderer import SyntaxHighlighter
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
def _use_utf8(stream: IO[str]) -> None:
|
|
14
|
+
"""Switch a text stream to UTF-8 regardless of the platform locale.
|
|
15
|
+
|
|
16
|
+
On Windows the default encoding for redirected or piped streams is the
|
|
17
|
+
legacy code page, which cannot represent the box-drawing and bullet
|
|
18
|
+
characters this tool emits. Markdown is UTF-8 in practice, so read it
|
|
19
|
+
that way too.
|
|
20
|
+
"""
|
|
21
|
+
try:
|
|
22
|
+
stream.reconfigure(encoding="utf-8", errors="replace") # type: ignore[attr-defined]
|
|
23
|
+
except (AttributeError, ValueError, OSError):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
12
27
|
def main(argv: list[str] | None = None) -> int:
|
|
13
28
|
"""Main CLI entry point."""
|
|
29
|
+
_use_utf8(sys.stdin)
|
|
30
|
+
_use_utf8(sys.stdout)
|
|
31
|
+
|
|
14
32
|
parser = argparse.ArgumentParser(
|
|
15
33
|
prog="mdsyntax",
|
|
16
34
|
description="Render markdown with syntax highlighting in the terminal.",
|
|
@@ -18,7 +36,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
18
36
|
parser.add_argument(
|
|
19
37
|
"file",
|
|
20
38
|
nargs="?",
|
|
21
|
-
type=argparse.FileType("r"),
|
|
39
|
+
type=argparse.FileType("r", encoding="utf-8", errors="replace"),
|
|
22
40
|
default=sys.stdin,
|
|
23
41
|
help="Markdown file to render (default: stdin)",
|
|
24
42
|
)
|
|
@@ -68,12 +86,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
68
86
|
|
|
69
87
|
true_color = None if not args.no_true_color else False
|
|
70
88
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
try:
|
|
90
|
+
md_print(
|
|
91
|
+
text,
|
|
92
|
+
code_style=args.style,
|
|
93
|
+
code_width=args.width,
|
|
94
|
+
true_color=true_color,
|
|
95
|
+
)
|
|
96
|
+
except ValueError as exc:
|
|
97
|
+
print(f"mdsyntax: error: {exc}", file=sys.stderr)
|
|
98
|
+
print("Run 'mdsyntax --list-styles' to see valid style names.", file=sys.stderr)
|
|
99
|
+
return 2
|
|
77
100
|
|
|
78
101
|
return 0
|
|
79
102
|
|