This commit is contained in:
Timothy Jaeryang Baek 2025-07-19 19:15:05 +04:00
parent d9a3b02e3f
commit 08ff9863d5
3 changed files with 26 additions and 16 deletions

View file

@ -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!'));
} }

View file

@ -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;
}); });

View file

@ -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) { if (formatted) {
let styledHtml = '';
if (!html) {
const options = { const options = {
throwOnError: false, throwOnError: false,
highlight: function (code, lang) { highlight: function (code, lang) {
@ -400,7 +402,7 @@ export const copyToClipboard = async (text, formatted = false) => {
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' });