mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-02 03:59:45 +02:00
refac
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
export let edit = true;
|
||||
|
||||
export let onSave = (e) => {};
|
||||
export let onUpdate = (e) => {};
|
||||
export let onUpdate = (e, codeBlockId = '') => {};
|
||||
export let onPreview = (e) => {};
|
||||
|
||||
export let save = false;
|
||||
@@ -364,7 +364,7 @@
|
||||
};
|
||||
|
||||
const render = async () => {
|
||||
onUpdate(token);
|
||||
onUpdate(token, id);
|
||||
if (lang === 'mermaid' && (token?.raw ?? '').slice(-4).includes('```')) {
|
||||
try {
|
||||
renderHTML = await renderMermaid(code);
|
||||
@@ -420,7 +420,7 @@
|
||||
|
||||
onMount(async () => {
|
||||
if (token) {
|
||||
onUpdate(token);
|
||||
onUpdate(token, id);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -130,16 +130,31 @@
|
||||
)
|
||||
: messageContent;
|
||||
|
||||
let autoOpenedArtifactIds = new Set();
|
||||
|
||||
const hasClosingCodeFence = (raw = '') => /(?:^|\n)```[ \t]*$/.test(raw.trimEnd());
|
||||
|
||||
const markdownUpdateHandler = /** @type {any} */ (
|
||||
async (/** @type {{ lang?: string; text?: string }} */ token) => {
|
||||
const { lang = '', text: code = '' } = token;
|
||||
async (
|
||||
/** @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 (
|
||||
($settings?.detectArtifacts ?? true) &&
|
||||
(['html', 'svg'].includes(lang) || (lang === 'xml' && code.includes('svg'))) &&
|
||||
isArtifact &&
|
||||
hasClosingCodeFence(raw) &&
|
||||
!autoOpenedArtifactIds.has(artifactId) &&
|
||||
!$mobile &&
|
||||
$chatId
|
||||
) {
|
||||
autoOpenedArtifactIds.add(artifactId);
|
||||
await tick();
|
||||
showArtifacts.set(true);
|
||||
showControls.set(true);
|
||||
|
||||
Reference in New Issue
Block a user