Skip to content

fix(chart): render chart JSON from json/untagged fences#25

Merged
sagar-develop merged 1 commit into
mainfrom
fix/chart-render-any-fence
Jun 5, 2026
Merged

fix(chart): render chart JSON from json/untagged fences#25
sagar-develop merged 1 commit into
mainfrom
fix/chart-render-any-fence

Conversation

@sagar-develop

Copy link
Copy Markdown
Owner

Why

#23 added inline charts: the model is meant to emit a chart-tagged fenced JSON block, which `MarkdownText` detects via `lang == "chart"`. But on-device verification showed the default **Gemma 4 E2B reliably emits valid chart JSON tagged json (or untagged) — never ```chart**, even when forcefully instructed. So charts never rendered in practice; the block fell back to a code block.

Fix

MarkdownText now also attempts ChartParser.parse on json/untagged fences and renders a chart when it succeeds. This is conservative: ChartParser only returns non-null for JSON with a recognized chart type (donut/bar/progress/line + synonyms) and valid data, so ordinary JSON code samples still render as code. The explicit ```chart path is unchanged.

Verified on-device

Realme CPH2723, release build: historical Gemma answers that had emitted untagged chart JSON now re-render as a donut chart (Monthly Budget) and bar charts (Quarterly Sales, Users) — proper on-brand Canvas charts, not code blocks.

🤖 Generated with Claude Code

…chart

Small on-device models (Gemma E2B, the default) reliably emit valid chart JSON
but tag the fence ```json or leave it untagged — never ```chart — even when
explicitly instructed. So the chart feature from #23 never rendered in practice;
the block fell back to a code block.

Now we also attempt ChartParser.parse on json/untagged fences and render a chart
when it succeeds. ChartParser only returns non-null for JSON with a recognized
chart type (donut/bar/progress/line + synonyms) AND valid data, so ordinary JSON
code samples still render as code. The explicit ```chart path is unchanged.

Verified on-device (Realme CPH2723, release): historical Gemma answers that
emitted untagged chart JSON now re-render as a donut + bar charts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sagar-develop sagar-develop merged commit ac6f2ff into main Jun 5, 2026
@sagar-develop sagar-develop deleted the fix/chart-render-any-fence branch June 5, 2026 08:21
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