Skip to content

Commit 2b9543c

Browse files
tschmclaude
andcommitted
fix: bump pygments to >=2.20 and fix Markdown rendering regression
- Bump pygments minimum version to 2.20 to avoid a bug in 2.19 where HtmlFormatter raises AttributeError when filename option is None - Fix PyconDetectorPreprocessor fence regex to use a backreference so the closing fence matches the opening marker, preventing greedy over-consumption of adjacent fenced blocks - Support both backtick and tilde fence styles in the detector - Raise preprocessor priority (30 → 175) to run before pymdownx - Guard against None return from markdown.markdown() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3d9d536 commit 2b9543c

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ py-snapshots:
138138
uv run --group test pytest \
139139
tests/_server/templates/test_templates.py \
140140
tests/_server/api/endpoints/test_export.py \
141-
tests/test_api.py
141+
tests/test_api.py \
142+
tests/test_project_dependencies.py
142143

143144
##############
144145
# Packaging #

marimo/_output/md.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PyconDetectorExtension(markdown.Extension):
3535
def extendMarkdown(self, md: markdown.Markdown) -> None:
3636
"""Add the preprocessor to the markdown instance."""
3737
processor = PyconDetectorPreprocessor(md)
38-
md.preprocessors.register(processor, "pycon_detector", 30)
38+
md.preprocessors.register(processor, "pycon_detector", 175)
3939

4040

4141
class PyconDetectorPreprocessor(markdown.preprocessors.Preprocessor):
@@ -53,9 +53,12 @@ class PyconDetectorPreprocessor(markdown.preprocessors.Preprocessor):
5353

5454
def __init__(self, md: markdown.Markdown) -> None:
5555
super().__init__(md)
56-
# Pattern to match fenced code blocks
56+
# Pattern to match fenced code blocks (backreference \2 ensures the
57+
# closing fence matches the opening fence marker, preventing greedy
58+
# over-consumption of adjacent fenced blocks)
5759
self.fence_pattern = re.compile(
58-
r"^(\s*)```(\w*)\s*\n(.*?)^(\s*)```\s*$", re.MULTILINE | re.DOTALL
60+
r"^(\s*)(```+|~~~+)(\w*)\s*\n(.*?)^\s*\2\s*$",
61+
re.MULTILINE | re.DOTALL,
5962
)
6063

6164
def run(self, lines: list[str]) -> list[str]:
@@ -64,14 +67,14 @@ def run(self, lines: list[str]) -> list[str]:
6467

6568
def replace_fence(match: re.Match[str]) -> str:
6669
indent = match.group(1)
67-
language = match.group(2) or ""
68-
code = match.group(3)
70+
fence = match.group(2)
71+
language = match.group(3) or ""
72+
code = match.group(4)
6973

7074
# Only process if no language is specified
71-
if not language:
72-
if self._detect_pycon(code):
73-
# Replace with pycon language
74-
return f"{indent}```pycon\n{code}{indent}```"
75+
if not language and self._detect_pycon(code):
76+
# Replace with pycon language
77+
return f"{indent}{fence}pycon\n{code}{indent}{fence}"
7578

7679
# Return original
7780
return match.group(0)
@@ -250,7 +253,10 @@ def __init__(
250253
text,
251254
extensions=_get_extensions(),
252255
extension_configs=_get_extension_configs(),
253-
).strip()
256+
)
257+
if html_text is None:
258+
html_text = ""
259+
html_text = html_text.strip()
254260
# replace <p> tags with <span> as HTML doesn't allow nested <div>s in <p>s
255261
html_text = html_text.replace(
256262
"<p>", '<span class="paragraph">'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
# Pinned to specific version for introduction of codeblock handling.
2121
"pymdown-extensions>=10.15,<11",
2222
# syntax highlighting of code in markdown
23-
"pygments>=2.19,<3",
23+
"pygments>=2.20,<3",
2424
# for reading, writing configs
2525
"tomlkit>=0.12.0",
2626
# for managing frontmatter headers in markdown

tests/snapshots/dependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgspec>=0.20.0
88
narwhals>=2.0.0
99
packaging
1010
psutil>=5.0
11-
pygments>=2.19,<3
11+
pygments>=2.20,<3
1212
pymdown-extensions>=10.15,<11
1313
pyyaml>=6.0.1
1414
pyzmq>=27.1.0; python_version < '3.15'

0 commit comments

Comments
 (0)