This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-26 18:30:58 -04:00
1 parent dcc7fb1e8e
commit 4856afcef8
2 files changed
+21 -6

No files matched your search

@@ -32,7 +32,7 @@
export let edit = true; export let edit = true;
export let onSave = (e) => {}; export let onSave = (e) => {};
export let onUpdate = (e) => {}; export let onUpdate = (e, codeBlockId = '') => {};
export let onPreview = (e) => {}; export let onPreview = (e) => {};
export let save = false; export let save = false;
@@ -364,7 +364,7 @@
}; };
const render = async () => { const render = async () => {
onUpdate(token); onUpdate(token, id);
if (lang === 'mermaid' && (token?.raw ?? '').slice(-4).includes('```')) { if (lang === 'mermaid' && (token?.raw ?? '').slice(-4).includes('```')) {
try { try {
renderHTML = await renderMermaid(code); renderHTML = await renderMermaid(code);
@@ -420,7 +420,7 @@
onMount(async () => { onMount(async () => {
if (token) { if (token) {
onUpdate(token); onUpdate(token, id);
} }
}); });
@@ -130,16 +130,31 @@
) )
: messageContent; : messageContent;
let autoOpenedArtifactIds = new Set();
const hasClosingCodeFence = (raw = '') => /(?:^|\n)```[ \t]*$/.test(raw.trimEnd());
const markdownUpdateHandler = /** @type {any} */ ( const markdownUpdateHandler = /** @type {any} */ (
async (/** @type {{ lang?: string; text?: string }} */ token) => { async (
const { lang = '', text: code = '' } = token; /** @type {{ lang?: string; raw?: string; text?: string }} */ token,
codeBlockId = ''
) => {
const { lang = '', raw = '', text: code = '' } = token;
const normalizedLang = lang.toLowerCase();
const isArtifact =
['html', 'svg'].includes(normalizedLang) ||
(normalizedLang === 'xml' && code.toLowerCase().includes('<svg'));
const artifactId = codeBlockId || `${normalizedLang}:${raw}`;
if ( if (
($settings?.detectArtifacts ?? true) && ($settings?.detectArtifacts ?? true) &&
(['html', 'svg'].includes(lang) || (lang === 'xml' && code.includes('svg'))) && isArtifact &&
hasClosingCodeFence(raw) &&
!autoOpenedArtifactIds.has(artifactId) &&
!$mobile && !$mobile &&
$chatId $chatId
) { ) {
autoOpenedArtifactIds.add(artifactId);
await tick(); await tick();
showArtifacts.set(true); showArtifacts.set(true);
showControls.set(true); showControls.set(true);