Skip to content

Support for Chart Rendering via Vega Lite #317

@zhengyufanevan-spec

Description

@zhengyufanevan-spec

Problem Statement

I'm always frustrated when I want to render charts directly from Vega-Lite JSON inside Streamdown messages.

Currently, Streamdown treats all code blocks the same, so I cannot display interactive charts inline while keeping all the built-in features like copy/download buttons and syntax highlighting for other code blocks.

Proposed Solution

I would like Streamdown to support rendering vega-lite fenced code blocks using Vega-Lite.

When a code block is marked as vega-lite (i.e., ```vega-lite), Streamdown should parse the JSON and render it as an interactive Vega-Lite chart.

All other code blocks should continue to render with Streamdown's default behavior, preserving syntax highlighting, copy/download actions, and language badges.

Invalid JSON should gracefully fall back to default code rendering or show an error placeholder.

Alternatives Considered

I've also considered:

  • Using custom React components to intercept code blocks before rendering. While this works, it requires manual overrides and breaks Streamdown’s built-in features for non-chart code blocks.

  • Using Markdown extensions outside of Streamdown, but that would prevent streaming-friendly rendering and incremental updates.

Use Case

import { Streamdown } from 'streamdown';
import { VegaLiteChart } from './VegaLiteChart';

const markdown = `
Here is a chart:

\`\`\`vega-lite
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      { "a": "A", "b": 28 },
      { "a": "B", "b": 55 },
      { "a": "C", "b": 43 }
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": { "field": "a", "type": "nominal" },
    "y": { "field": "b", "type": "quantitative" }
  }
}
\`\`\`

And some code:

\`\`\`ts
console.log("Hello Streamdown");
\`\`\`
`;

<Streamdown content={markdown} />;

Priority

Critical

Contribution

  • I am willing to help implement this feature

Additional Context

  • This would enable LLM-driven chart generation directly in Streamdown streams.
  • Could also support multiple charts per message and incremental updates while streaming.
  • Would make Streamdown a full-featured interactive Markdown + chart rendering solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions