From 66787737c97f93895571c131cb3790db09b8085b Mon Sep 17 00:00:00 2001 From: SteaceP Date: Sat, 27 Dec 2025 05:25:21 -0500 Subject: [PATCH 1/2] fix(code-highlighter): ensure HTML formatted code is correctly copied --- src/tools/code-highlighter/code-highlighter.vue | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/tools/code-highlighter/code-highlighter.vue b/src/tools/code-highlighter/code-highlighter.vue index 21e447ea6d..ec275b4bf5 100644 --- a/src/tools/code-highlighter/code-highlighter.vue +++ b/src/tools/code-highlighter/code-highlighter.vue @@ -1,10 +1,10 @@ From 4f7417ac2c1e1b122ed7701fb0370ab9314c693c Mon Sep 17 00:00:00 2001 From: SteaceP Date: Sat, 27 Dec 2025 06:46:48 -0500 Subject: [PATCH 2/2] feat(code-highlighter): add transparent background option and improve copy functionality --- .../code-highlighter/code-highlighter.vue | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/src/tools/code-highlighter/code-highlighter.vue b/src/tools/code-highlighter/code-highlighter.vue index ec275b4bf5..ebe95b1c21 100644 --- a/src/tools/code-highlighter/code-highlighter.vue +++ b/src/tools/code-highlighter/code-highlighter.vue @@ -3,6 +3,7 @@ import { useI18n } from 'vue-i18n'; import { ref } from 'vue'; import { bundledLanguagesInfo, createHighlighter } from 'shiki/bundle/full'; import { bundledThemesInfo } from 'shiki/themes'; +import { useMessage } from 'naive-ui'; import { useQueryParamOrStorage } from '@/composable/queryParams'; import { useCopy } from '@/composable/copy'; @@ -38,6 +39,7 @@ const currentTheme = useQueryParamOrStorage({ name: 'theme', storageName: 'code- const currentLang = useQueryParamOrStorage({ name: 'lang', storageName: 'code-highlighter:lang', defaultValue: 'typescript' }); const showLineNumbers = ref(false); +const transparentBackground = ref(false); const formattedCodeHtml = computedAsync(async () => { const currentThemeValue = currentTheme.value; @@ -75,8 +77,55 @@ const formattedCodeHtml = computedAsync(async () => { ], }); }); -const { copy: copyHtml } = useCopy({ source: formattedCodeHtml }); const { copy: copyText } = useCopy({ source: code }); + +// Transform HTML to be Outlook-compatible (Outlook ignores styles on pre/code tags) +function makeOutlookCompatible(html: string, useTransparentBg: boolean): string { + return html + // Replace
 with a styled 
(Outlook handles divs better) + .replace(/]*style="([^"]*)"[^>]*>/g, (_, style) => { + // Remove background-color if transparent is requested + const finalStyle = useTransparentBg + ? style.replace(/background-color:\s*[^;]+;?/g, '') + : style; + return `
`; + }) + .replace(/<\/pre>/g, '
') + // Replace with
+ .replace(//g, '
') + .replace(/<\/code>/g, '
') + // Replace line spans with divs and add explicit background + .replace(//g, '
') + .replace(/ for the line wrapper) + .replace(/(
]*>.*?)(<\/span>)(\s*
+ + + Removes the background color for better readability when pasting into Outlook or other email clients + {{ t('tools.code-highlighter.texts.tag-copy-html-formatted') }}