mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +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}`;
|
||||
}
|
||||
|
||||
const res = await _copyToClipboard(text, $settings?.copyFormatted ?? false);
|
||||
const res = await _copyToClipboard(text, null, $settings?.copyFormatted ?? false);
|
||||
if (res) {
|
||||
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 () => {
|
||||
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}`);
|
||||
return null;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -384,8 +384,10 @@ export const formatDate = (inputDate) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const copyToClipboard = async (text, formatted = false) => {
|
||||
export const copyToClipboard = async (text, html = null, formatted = false) => {
|
||||
if (formatted) {
|
||||
let styledHtml = '';
|
||||
if (!html) {
|
||||
const options = {
|
||||
throwOnError: false,
|
||||
highlight: function (code, lang) {
|
||||
|
|
@ -400,7 +402,7 @@ export const copyToClipboard = async (text, formatted = false) => {
|
|||
const htmlContent = marked.parse(text);
|
||||
|
||||
// Add basic styling to make the content look better when pasted
|
||||
const styledHtml = `
|
||||
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' });
|
||||
|
|
|
|||
Loading…
Reference in a new issue