Fix markdown rendering in tool results with Python list content#14
Open
ShlomoStept wants to merge 3 commits intomainfrom
Open
Fix markdown rendering in tool results with Python list content#14ShlomoStept wants to merge 3 commits intomainfrom
ShlomoStept wants to merge 3 commits intomainfrom
Conversation
## Investigation Plan
### Problem Statement
Tool results that are JSON arrays of objects (e.g., `[{"type": "text", "text": "## Heading\n\nParagraph"}]`)
are NOT rendering the markdown content properly. The text values within the JSON objects should be
parsed and displayed as formatted markdown (headers, paragraphs, lists, etc.).
### Current Behavior
- JSON arrays are detected
- But the text content within is shown as raw text, not rendered markdown
### Expected Behavior
- Each "text" value in content blocks should be rendered as proper markdown
- Headers should display as `<h2>`, `<h3>`, etc.
- Lists should display as `<ul>/<li>`
- Code blocks should have syntax highlighting
### Tasks
1. Review PR comments for relevant feedback
2. Analyze current `render_content_block_array()` implementation
3. Fix markdown parsing within JSON text values
4. Fix subagent functionality issues
5. Add/update tests
6. Verify on ShlomoStept/claude-code-transcripts fork ONLY
IMPORTANT: All work on ShlomoStept fork only. NO pushes to simonw/upstream.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When tool_result content is a Python list of content blocks (not a JSON string), the content was incorrectly rendered as raw JSON instead of markdown. This fix adds is_content_block_list() helper function and updates the tool_result handling to properly render markdown when content is a list containing content blocks with a "type" field. - Add is_content_block_list() function to detect Python list content blocks - Fix render_content_block() to call render_content_block_array() for list content - Add 10 new tests (8 for is_content_block_list, 2 for tool_result list rendering) - All 119 tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where tool results containing Python lists of content blocks were displaying as raw JSON instead of rendered markdown. The issue occurred when content was provided as a native Python list rather than a JSON string.
Key Changes:
- Added
is_content_block_list()helper function to detect Python lists containing content blocks - Modified
render_content_block()to properly handle Python list content by rendering markdown for content block lists - Added comprehensive test coverage with 10 new tests
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/claude_code_transcripts/init.py | Added is_content_block_list() helper function and updated tool result rendering logic to handle Python lists |
| tests/test_generate_html.py | Added 8 tests for is_content_block_list() function and 2 integration tests for tool result rendering |
| tests/snapshots/test_generate_html/TestRenderContentBlock.test_tool_result_content_block_list_renders_markdown.html | Snapshot for single content block list test |
| tests/snapshots/test_generate_html/TestRenderContentBlock.test_tool_result_content_block_list_with_multiple_blocks.html | Snapshot for multiple content blocks list test |
| walkthrough.md | Documentation explaining the fix implementation and verification |
| task.md | Task tracking document showing completed work |
| implementation_plan.md | Detailed implementation plan and changes documentation |
| GRADING_REPORT.md | Grading report for the completed work |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the bug where tool results containing Python lists of content blocks were not rendering markdown properly.
Problem
When a tool result was a Python list like:
[ {"type": "text", "text": "## Report\n\n- Item 1\n- Item 2"} ]The markdown content was shown as raw text instead of rendered HTML.
Solution
is_content_block_list()helper function to detect Python lists containing content block dictsrender_content_block()to check for content block lists and render them as markdownChanges
src/claude_code_transcripts/__init__.py- Added helper function and fixed list handlingtests/test_generate_html.py- Added 10 new teststests/__snapshots__/*- Added 2 new snapshot filesTest Results
Before/After
## Report<h2>Report</h2>🤖 Generated with Claude Code