Add syntax highlighting for fenced code blocks in markdown artifacts
Enables codehilite on the markdown renderer (Pygments, 'friendly' style, vendored as static/themes/pygments.css) so fenced code blocks get real syntax highlighting with zero client-side JS - matching the "themes are CSS-only" stance in framework_artifact_rendering.md. Verified live against the running dev instance: a fenced python block renders with highlighted keyword/string/function spans. This was Gap 2 from planning/2026-09-02-artifact_kind_gaps_for_frequent_agent_output.md, picked as the first fix since it needed no new kind or design decision - just enabling an existing markdown extension. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
d9fc28aec0
commit
af9ecf28a9
5 changed files with 102 additions and 2 deletions
|
|
@ -502,7 +502,16 @@ def create_text_artifact(data, request, user):
|
|||
if kind == Artifact.HTML_FULL:
|
||||
rendered = content
|
||||
elif kind == Artifact.MARKDOWN:
|
||||
rendered = wrap_html(markdown.markdown(content, extensions=["extra", "sane_lists"]), title, theme, request)
|
||||
rendered = wrap_html(
|
||||
markdown.markdown(
|
||||
content,
|
||||
extensions=["extra", "sane_lists", "codehilite"],
|
||||
extension_configs={"codehilite": {"guess_lang": False}},
|
||||
),
|
||||
title,
|
||||
theme,
|
||||
request,
|
||||
)
|
||||
(target_dir / f"{artifact_id}.md").write_text(content, encoding="utf-8")
|
||||
elif kind == Artifact.DECK:
|
||||
rendered = wrap_deck(content, title, request)
|
||||
|
|
@ -595,6 +604,7 @@ def create_binary_artifact(data, user):
|
|||
|
||||
def wrap_html(body, title, theme, request):
|
||||
stylesheet = request.build_absolute_uri(f"/static/themes/{theme}.css")
|
||||
pygments_stylesheet = request.build_absolute_uri("/static/themes/pygments.css")
|
||||
return f"""<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -602,6 +612,7 @@ def wrap_html(body, title, theme, request):
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{html.escape(title)}</title>
|
||||
<link rel="stylesheet" href="{stylesheet}">
|
||||
<link rel="stylesheet" href="{pygments_stylesheet}">
|
||||
</head>
|
||||
<body class="artifact">
|
||||
{body}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue