Skip to content

Commit 226c802

Browse files
cboosclaude
andcommitted
Escape <summary> tags in quoted content to fix rendering
When quoted markdown content contains <summary> or </summary> tags on their own lines (e.g., from compacted conversation summaries), these interfere with <details>/<summary> HTML rendering in VS Code and other markdown viewers. Fix: escape standalone <summary> tags with backslash prefix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fce80f3 commit 226c802

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎claude_code_log/markdown/renderer.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ def __init__(self, image_export_mode: str = "referenced"):
8585
# -------------------------------------------------------------------------
8686

8787
def _quote(self, text: str) -> str:
88-
"""Prefix each line with '> ' to create a blockquote."""
88+
"""Prefix each line with '> ' to create a blockquote.
89+
90+
Also escapes <summary> tags that would interfere with <details> rendering.
91+
"""
92+
# Escape <summary> and </summary> tags on their own lines
93+
text = re.sub(r"^(</?summary>)$", r"\\\1", text, flags=re.MULTILINE)
8994
return "\n".join(f"> {line}" for line in text.split("\n"))
9095

9196
def _code_fence(self, text: str, lang: str = "") -> str:

‎test/test_markdown_helpers.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ def test_empty_text(self, renderer):
191191
result = renderer._quote("")
192192
assert result == "> "
193193

194+
def test_escapes_summary_tags(self, renderer):
195+
"""Escapes <summary> tags that would interfere with <details> rendering."""
196+
text = "Some text\n<summary>\nMore text\n</summary>\nEnd"
197+
result = renderer._quote(text)
198+
# Tags on their own lines get escaped with backslash
199+
assert "> \\<summary>" in result
200+
assert "> \\</summary>" in result
201+
202+
def test_preserves_inline_summary_tags(self, renderer):
203+
"""Does not escape <summary> tags that are inline with other content."""
204+
text = "The <summary> tag is used in HTML"
205+
result = renderer._quote(text)
206+
# Inline tags are not escaped
207+
assert result == "> The <summary> tag is used in HTML"
208+
194209

195210
class TestStripErrorTags:
196211
"""Tests for the strip_error_tags() utility function."""

0 commit comments

Comments
 (0)