refac
This commit is contained in:
1 parent
dcc7fb1e8e
commit
4856afcef8
2 files changed
+21
-6
No files matched your search
@@ -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