Skip to content

Commit e0ba1f2

Browse files
committed
Fix markdown list rendering without blank lines
Add mdx-breakless-lists extension to handle bullet points and numbered lists that immediately follow text without a blank line separator. This is a common pattern in Claude's responses. - Add mdx-breakless-lists dependency to pyproject.toml - Update render_markdown_text to use mdx_breakless_lists extension - Add test for list rendering without blank lines - Update snapshot for improved list formatting
1 parent 854a4f8 commit e0ba1f2

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
"httpx",
1515
"jinja2",
1616
"markdown",
17+
"mdx-breakless-lists",
1718
"questionary",
1819
]
1920

src/claude_code_transcripts/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,11 @@ def format_json(obj):
632632
def render_markdown_text(text):
633633
if not text:
634634
return ""
635-
return markdown.markdown(text, extensions=["fenced_code", "tables"])
635+
# Use mdx_breakless_lists extension to handle lists without blank lines
636+
# This allows GitHub-flavored markdown style lists
637+
return markdown.markdown(
638+
text, extensions=["fenced_code", "tables", "mdx_breakless_lists"]
639+
)
636640

637641

638642
def is_json_like(text):

tests/__snapshots__/test_generate_html/TestGenerateHtml.test_generates_page_001_html.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ <h1><a href="index.html" style="color: inherit; text-decoration: none;">Claude C
160160
<div class="message user" id="msg-2025-12-24T10-00-00-000Z"><div class="message-header"><span class="role-label">User</span><a href="#msg-2025-12-24T10-00-00-000Z" class="timestamp-link"><time datetime="2025-12-24T10:00:00.000Z" data-timestamp="2025-12-24T10:00:00.000Z">2025-12-24T10:00:00.000Z</time></a></div><div class="message-content">
161161
<div class="user-content"><p>Create a simple Python function to add two numbers</p></div></div></div>
162162
<div class="message assistant" id="msg-2025-12-24T10-00-05-000Z"><div class="message-header"><span class="role-label">Assistant</span><a href="#msg-2025-12-24T10-00-05-000Z" class="timestamp-link"><time datetime="2025-12-24T10:00:05.000Z" data-timestamp="2025-12-24T10:00:05.000Z">2025-12-24T10:00:05.000Z</time></a></div><div class="message-content">
163-
<div class="thinking"><div class="thinking-label">Thinking</div><p>The user wants a simple addition function. I should:
164-
1. Create the function
165-
2. Add a basic test</p>
163+
<div class="thinking"><div class="thinking-label">Thinking</div><p>The user wants a simple addition function. I should:</p>
164+
<ol>
165+
<li>Create the function</li>
166+
<li>Add a basic test</li>
167+
</ol>
166168
<p>This is straightforward.</p></div>
167169
<div class="assistant-text"><p>I'll create a simple Python function for you. Let me write it now.</p></div><div class="file-tool write-tool" data-tool-id="toolu_write_001">
168170
<div class="file-tool-header write-header"><span class="file-tool-icon">📝</span> Write <span class="file-tool-path">math_utils.py</span></div>
@@ -252,10 +254,12 @@ <h1><a href="index.html" style="color: inherit; text-decoration: none;">Claude C
252254
test_subtract - AssertionError: expected 5 but got None</pre></div><button class="expand-btn">Show more</button></div></div></div></div>
253255
<div class="message assistant" id="msg-2025-12-24T10-02-15-000Z"><div class="message-header"><span class="role-label">Assistant</span><a href="#msg-2025-12-24T10-02-15-000Z" class="timestamp-link"><time datetime="2025-12-24T10:02:15.000Z" data-timestamp="2025-12-24T10:02:15.000Z">2025-12-24T10:02:15.000Z</time></a></div><div class="message-content">
254256
<div class="assistant-text"><p>There's a test failure. I need to check the test file and fix it.</p>
255-
<p>Here's some <strong>markdown</strong> content with:
256-
- A bullet list
257-
- <code>inline code</code>
258-
- A <a href="https://example.com">link</a></p>
257+
<p>Here's some <strong>markdown</strong> content with:</p>
258+
<ul>
259+
<li>A bullet list</li>
260+
<li><code>inline code</code></li>
261+
<li>A <a href="https://example.com">link</a></li>
262+
</ul>
259263
<pre><code class="language-python">def example():
260264
return 42
261265
</code></pre></div></div></div>

tests/test_generate_html.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ def test_render_markdown_text_empty(self):
131131
assert render_markdown_text("") == ""
132132
assert render_markdown_text(None) == ""
133133

134+
def test_render_markdown_text_bullets_without_blank_line(self):
135+
"""Test that bullet points work even without a blank line before them.
136+
137+
This is a common pattern in Claude's responses where lists immediately
138+
follow text without a blank line separator.
139+
"""
140+
text = "Here's a list:\n- Item 1\n- Item 2\n- Item 3"
141+
result = render_markdown_text(text)
142+
# Should render as a proper list, not as plain text
143+
assert "<ul>" in result
144+
assert "<li>Item 1</li>" in result
145+
assert "<li>Item 2</li>" in result
146+
assert "<li>Item 3</li>" in result
147+
# Should NOT render the dashes as literal text
148+
assert "- Item 1" not in result
149+
134150
def test_format_json(self, snapshot_html):
135151
"""Test JSON formatting."""
136152
result = format_json({"key": "value", "number": 42, "nested": {"a": 1}})

0 commit comments

Comments
 (0)