mirror of
https://github.com/zebrajr/ollama-webui.git
synced 2025-12-06 12:19:46 +01:00
Merge pull request #18195 from EventHorizon-AI/fix/artifacts-duplicate-match
fix: Artifacts duplicate matching
This commit is contained in:
commit
b93e9b1698
|
|
@ -39,51 +39,51 @@
|
||||||
const codeBlockContents = message.content.match(/```[\s\S]*?```/g);
|
const codeBlockContents = message.content.match(/```[\s\S]*?```/g);
|
||||||
let codeBlocks = [];
|
let codeBlocks = [];
|
||||||
|
|
||||||
|
let htmlContent = '';
|
||||||
|
let cssContent = '';
|
||||||
|
let jsContent = '';
|
||||||
|
|
||||||
if (codeBlockContents) {
|
if (codeBlockContents) {
|
||||||
codeBlockContents.forEach((block) => {
|
codeBlockContents.forEach((block) => {
|
||||||
const lang = block.split('\n')[0].replace('```', '').trim().toLowerCase();
|
const lang = block.split('\n')[0].replace('```', '').trim().toLowerCase();
|
||||||
const code = block.replace(/```[\s\S]*?\n/, '').replace(/```$/, '');
|
const code = block.replace(/```[\s\S]*?\n/, '').replace(/```$/, '');
|
||||||
codeBlocks.push({ lang, code });
|
codeBlocks.push({ lang, code });
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
let htmlContent = '';
|
codeBlocks.forEach((block) => {
|
||||||
let cssContent = '';
|
const { lang, code } = block;
|
||||||
let jsContent = '';
|
|
||||||
|
|
||||||
codeBlocks.forEach((block) => {
|
if (lang === 'html') {
|
||||||
const { lang, code } = block;
|
htmlContent += code + '\n';
|
||||||
|
} else if (lang === 'css') {
|
||||||
|
cssContent += code + '\n';
|
||||||
|
} else if (lang === 'javascript' || lang === 'js') {
|
||||||
|
jsContent += code + '\n';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const inlineHtml = message.content.match(/<html>[\s\S]*?<\/html>/gi);
|
||||||
|
const inlineCss = message.content.match(/<style>[\s\S]*?<\/style>/gi);
|
||||||
|
const inlineJs = message.content.match(/<script>[\s\S]*?<\/script>/gi);
|
||||||
|
|
||||||
if (lang === 'html') {
|
if (inlineHtml) {
|
||||||
htmlContent += code + '\n';
|
inlineHtml.forEach((block) => {
|
||||||
} else if (lang === 'css') {
|
const content = block.replace(/<\/?html>/gi, ''); // Remove <html> tags
|
||||||
cssContent += code + '\n';
|
htmlContent += content + '\n';
|
||||||
} else if (lang === 'javascript' || lang === 'js') {
|
});
|
||||||
jsContent += code + '\n';
|
}
|
||||||
|
if (inlineCss) {
|
||||||
|
inlineCss.forEach((block) => {
|
||||||
|
const content = block.replace(/<\/?style>/gi, ''); // Remove <style> tags
|
||||||
|
cssContent += content + '\n';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (inlineJs) {
|
||||||
|
inlineJs.forEach((block) => {
|
||||||
|
const content = block.replace(/<\/?script>/gi, ''); // Remove <script> tags
|
||||||
|
jsContent += content + '\n';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const inlineHtml = message.content.match(/<html>[\s\S]*?<\/html>/gi);
|
|
||||||
const inlineCss = message.content.match(/<style>[\s\S]*?<\/style>/gi);
|
|
||||||
const inlineJs = message.content.match(/<script>[\s\S]*?<\/script>/gi);
|
|
||||||
|
|
||||||
if (inlineHtml) {
|
|
||||||
inlineHtml.forEach((block) => {
|
|
||||||
const content = block.replace(/<\/?html>/gi, ''); // Remove <html> tags
|
|
||||||
htmlContent += content + '\n';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (inlineCss) {
|
|
||||||
inlineCss.forEach((block) => {
|
|
||||||
const content = block.replace(/<\/?style>/gi, ''); // Remove <style> tags
|
|
||||||
cssContent += content + '\n';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (inlineJs) {
|
|
||||||
inlineJs.forEach((block) => {
|
|
||||||
const content = block.replace(/<\/?script>/gi, ''); // Remove <script> tags
|
|
||||||
jsContent += content + '\n';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (htmlContent || cssContent || jsContent) {
|
if (htmlContent || cssContent || jsContent) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user