Pure function over (str)→str. Reuses combine.parse_combined to peel off the YAML frontmatter, runs the body through markdown-it-py with table support enabled (CMS comments lean on tabular data). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
"""rex.comments.render — combined.md → Zotero-edible HTML."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from rex.comments.render import render_combined_md
|
|
|
|
|
|
def test_strips_frontmatter():
|
|
md = "---\ncomment_id: CMS-2024-0001-0001\nstatus: ok\n---\n\n# Heading\n\nbody\n"
|
|
html = render_combined_md(md)
|
|
assert "comment_id" not in html
|
|
assert "status: ok" not in html
|
|
assert "<h1>Heading</h1>" in html
|
|
assert "<p>body</p>" in html
|
|
|
|
|
|
def test_renders_basic_markdown():
|
|
md = "---\nstatus: ok\n---\n\n## Section\n\nText with **bold** and *italic*.\n"
|
|
html = render_combined_md(md)
|
|
assert "<h2>Section</h2>" in html
|
|
assert "<strong>bold</strong>" in html
|
|
assert "<em>italic</em>" in html
|
|
|
|
|
|
def test_renders_tables():
|
|
md = (
|
|
"---\nstatus: ok\n---\n\n"
|
|
"| Col A | Col B |\n"
|
|
"| --- | --- |\n"
|
|
"| a1 | b1 |\n"
|
|
"| a2 | b2 |\n"
|
|
)
|
|
html = render_combined_md(md)
|
|
assert "<table>" in html
|
|
assert "<th>Col A</th>" in html
|
|
assert "<td>a1</td>" in html
|
|
|
|
|
|
def test_handles_empty_body():
|
|
md = "---\nstatus: ok\n---\n\n"
|
|
html = render_combined_md(md)
|
|
assert html == "" or html.strip() == ""
|
|
|
|
|
|
def test_raises_on_missing_frontmatter():
|
|
"""combined.md is always written with frontmatter — guard against
|
|
silently ingesting malformed input."""
|
|
import pytest
|
|
|
|
with pytest.raises(ValueError, match="frontmatter"):
|
|
render_combined_md("# No frontmatter here\n")
|