fix(chart): convert markdown to HTML for TipTap insertion

- Convert chart markdown to <pre><code class="language-chart"> HTML format
- Fix parseHTML to store code content in node attrs
- Fix renderHTML to output actual code content instead of placeholder

This fixes charts rendering as raw markdown text instead of visual charts.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antigravity
2026-05-23 09:51:30 +00:00
parent 10e529deff
commit 835e1872bb
2 changed files with 23 additions and 6 deletions

View File

@@ -295,7 +295,17 @@ export const RichTextEditor = forwardRef<RichTextEditorHandle, RichTextEditorPro
if (!editor || !editor.isEditable) return
try {
// Insert the chart markdown at current position
// Convert markdown chart to HTML format for TipTap
// Input: ```chart\nbar\nTitle\nlabel: value\n```
// Output: <pre><code class="language-chart">bar\nTitle\nlabel: value</code></pre>
const chartContent = markdown
.replace(/```chart\n?/gi, '')
.replace(/```$/gi, '')
.trim()
const htmlContent = `<pre><code class="language-chart">${chartContent}</code></pre>`
// Insert the chart HTML at current position
const { from } = editor.state.selection
// Check if we're in the middle of text, if so create a new paragraph
@@ -311,8 +321,8 @@ export const RichTextEditor = forwardRef<RichTextEditorHandle, RichTextEditorPro
}
}
// Insert the chart
editor.chain().focus().insertContent(markdown).run()
// Insert the chart as HTML (not markdown)
editor.chain().focus().insertContent(htmlContent).run()
} catch (error) {
console.error('[handleSelectChart] Failed to insert chart:', error)
toast.error('Failed to insert chart. Please try again.')