Skip to content

Comments

Fix markdown rendering in tool results with Python list content#14

Open
ShlomoStept wants to merge 3 commits intomainfrom
fix/tool-result-markdown-rendering
Open

Fix markdown rendering in tool results with Python list content#14
ShlomoStept wants to merge 3 commits intomainfrom
fix/tool-result-markdown-rendering

Conversation

@ShlomoStept
Copy link
Owner

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

  1. Added is_content_block_list() helper function to detect Python lists containing content block dicts
  2. Fixed render_content_block() to check for content block lists and render them as markdown

Changes

  • src/claude_code_transcripts/__init__.py - Added helper function and fixed list handling
  • tests/test_generate_html.py - Added 10 new tests
  • tests/__snapshots__/* - Added 2 new snapshot files

Test Results

  • 119 tests passing
  • 10 new tests added for content block list detection and rendering

Before/After

View Before (Bug) After (Fixed)
Markdown Raw text: ## Report Rendered: <h2>Report</h2>
JSON Formatted JSON Formatted JSON

🤖 Generated with Claude Code

ShlomoStept and others added 3 commits January 8, 2026 23:50
## 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>
Copilot AI review requested due to automatic review settings January 9, 2026 07:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant