mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
refac
This commit is contained in:
parent
d9a3b02e3f
commit
08ff9863d5
3 changed files with 26 additions and 16 deletions
|
|
@ -166,7 +166,7 @@
|
||||||
text = `${text}\n\n${$config?.ui?.response_watermark}`;
|
text = `${text}\n\n${$config?.ui?.response_watermark}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await _copyToClipboard(text, $settings?.copyFormatted ?? false);
|
const res = await _copyToClipboard(text, null, $settings?.copyFormatted ?? false);
|
||||||
if (res) {
|
if (res) {
|
||||||
toast.success($i18n.t('Copying to clipboard was successful!'));
|
toast.success($i18n.t('Copying to clipboard was successful!'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1082,7 +1082,11 @@ Provide the enhanced notes in markdown format. Use markdown syntax for headings,
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onCopyToClipboard={async () => {
|
onCopyToClipboard={async () => {
|
||||||
const res = await copyToClipboard(note.data.content.md).catch((error) => {
|
const res = await copyToClipboard(
|
||||||
|
note.data.content.md,
|
||||||
|
note.data.content.html,
|
||||||
|
true
|
||||||
|
).catch((error) => {
|
||||||
toast.error(`${error}`);
|
toast.error(`${error}`);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
if (formatted) {
|
||||||
const options = {
|
let styledHtml = '';
|
||||||
throwOnError: false,
|
if (!html) {
|
||||||
highlight: function (code, lang) {
|
const options = {
|
||||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
throwOnError: false,
|
||||||
return hljs.highlight(code, { language }).value;
|
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.
|
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
|
// Add basic styling to make the content look better when pasted
|
||||||
const styledHtml = `
|
styledHtml = `
|
||||||
<div>
|
<div>
|
||||||
<style>
|
<style>
|
||||||
pre {
|
pre {
|
||||||
|
|
@ -448,6 +450,10 @@ export const copyToClipboard = async (text, formatted = false) => {
|
||||||
${htmlContent}
|
${htmlContent}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
} else {
|
||||||
|
// If HTML is provided, use it directly
|
||||||
|
styledHtml = html;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a blob with HTML content
|
// Create a blob with HTML content
|
||||||
const blob = new Blob([styledHtml], { type: 'text/html' });
|
const blob = new Blob([styledHtml], { type: 'text/html' });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue