added renderer selection (py-gfm as alternative)

This commit is contained in:
2026-02-08 17:47:35 -05:00
parent 122b7ea348
commit 02bc0ce81d
11 changed files with 115 additions and 17 deletions

View File

@@ -54,9 +54,32 @@ def _promote_headings(text: str) -> str:
return "\n".join(promoted_lines)
def convert_markdown(markdown_text: str, context: str, issues: list[ValidationIssue]) -> str | None:
try:
return md_lib.markdown(markdown_text, extensions=["extra"], output_format="html5")
except Exception as exc: # pragma: no cover - depends on markdown internals
issues.append(ValidationIssue(f"Markdown conversion failed: {exc}", context=context))
return None
def convert_markdown(
markdown_text: str,
context: str,
issues: list[ValidationIssue],
renderer: str = "default",
) -> str | None:
if renderer == "default":
try:
return md_lib.markdown(markdown_text, extensions=["extra"], output_format="html5")
except Exception as exc: # pragma: no cover - depends on markdown internals
issues.append(ValidationIssue(f"Markdown conversion failed: {exc}", context=context))
return None
if renderer == "py-gfm":
try:
import mdx_gfm
except Exception as exc: # pragma: no cover - dependency missing
issues.append(ValidationIssue(f"py-gfm is not available: {exc}", context=context))
return None
extension_class = getattr(mdx_gfm, "GithubFlavoredMarkdownExtension", None)
if extension_class is None:
issues.append(ValidationIssue("py-gfm extension not found: GithubFlavoredMarkdownExtension", context=context))
return None
try:
return md_lib.markdown(markdown_text, extensions=[extension_class()], output_format="html5")
except Exception as exc: # pragma: no cover - depends on markdown internals
issues.append(ValidationIssue(f"Markdown conversion failed: {exc}", context=context))
return None
issues.append(ValidationIssue(f"Unknown renderer: {renderer}", context=context))
return None