refac
This commit is contained in:
+20
-14
@@ -384,23 +384,25 @@ export const formatDate = (inputDate) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const copyToClipboard = async (text, formatted = false) => {
|
||||
export const copyToClipboard = async (text, html = null, formatted = false) => {
|
||||
if (formatted) {
|
||||
const options = {
|
||||
throwOnError: false,
|
||||
highlight: function (code, lang) {
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
return hljs.highlight(code, { language }).value;
|
||||
}
|
||||
};
|
||||
marked.use(markedKatexExtension(options));
|
||||
marked.use(markedExtension(options));
|
||||
// DEVELOPER NOTE: Go to `$lib/components/chat/Messages/Markdown.svelte` to add extra markdown extensions for rendering.
|
||||
let styledHtml = '';
|
||||
if (!html) {
|
||||
const options = {
|
||||
throwOnError: false,
|
||||
highlight: function (code, lang) {
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
return hljs.highlight(code, { language }).value;
|
||||
}
|
||||
};
|
||||
marked.use(markedKatexExtension(options));
|
||||
marked.use(markedExtension(options));
|
||||
// DEVELOPER NOTE: Go to `$lib/components/chat/Messages/Markdown.svelte` to add extra markdown extensions for rendering.
|
||||
|
||||
const htmlContent = marked.parse(text);
|
||||
const htmlContent = marked.parse(text);
|
||||
|
||||
// Add basic styling to make the content look better when pasted
|
||||
const styledHtml = `
|
||||
// Add basic styling to make the content look better when pasted
|
||||
styledHtml = `
|
||||
<div>
|
||||
<style>
|
||||
pre {
|
||||
@@ -448,6 +450,10 @@ export const copyToClipboard = async (text, formatted = false) => {
|
||||
${htmlContent}
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
// If HTML is provided, use it directly
|
||||
styledHtml = html;
|
||||
}
|
||||
|
||||
// Create a blob with HTML content
|
||||
const blob = new Blob([styledHtml], { type: 'text/html' });
|
||||
|
||||
Reference in New Issue
Block a user