refac: chat navbar menu
This commit is contained in:
+61
-1
@@ -348,7 +348,7 @@ export const compressImage = async (imageUrl, maxWidth, maxHeight) => {
|
||||
context.drawImage(img, 0, 0, width, height);
|
||||
|
||||
// Get compressed image URL
|
||||
const mimeType = imageUrl.match(/^data:([^;]+);/)?.[1];
|
||||
const mimeType = imageUrl.match(/^data:([^;]+);/)?.[1];
|
||||
const compressedUrl = canvas.toDataURL(mimeType);
|
||||
resolve(compressedUrl);
|
||||
};
|
||||
@@ -1625,3 +1625,63 @@ export const renderVegaVisualization = async (spec: string, i18n?: any) => {
|
||||
const svg = await view.toSVG();
|
||||
return svg;
|
||||
};
|
||||
|
||||
export const getCodeBlockContents = (content: string): object => {
|
||||
const codeBlockContents = content.match(/```[\s\S]*?```/g);
|
||||
|
||||
let codeBlocks = [];
|
||||
|
||||
let htmlContent = '';
|
||||
let cssContent = '';
|
||||
let jsContent = '';
|
||||
|
||||
if (codeBlockContents) {
|
||||
codeBlockContents.forEach((block) => {
|
||||
const lang = block.split('\n')[0].replace('```', '').trim().toLowerCase();
|
||||
const code = block.replace(/```[\s\S]*?\n/, '').replace(/```$/, '');
|
||||
codeBlocks.push({ lang, code });
|
||||
});
|
||||
|
||||
codeBlocks.forEach((block) => {
|
||||
const { lang, code } = block;
|
||||
|
||||
if (lang === 'html') {
|
||||
htmlContent += code + '\n';
|
||||
} else if (lang === 'css') {
|
||||
cssContent += code + '\n';
|
||||
} else if (lang === 'javascript' || lang === 'js') {
|
||||
jsContent += code + '\n';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const inlineHtml = content.match(/<html>[\s\S]*?<\/html>/gi);
|
||||
const inlineCss = content.match(/<style>[\s\S]*?<\/style>/gi);
|
||||
const inlineJs = 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';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
codeBlocks: codeBlocks,
|
||||
html: htmlContent.trim(),
|
||||
css: cssContent.trim(),
|
||||
js: jsContent.trim()
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user