fix: copy of dark theme (#328)

This commit is contained in:
YangFong 2024-08-19 09:54:19 +08:00 committed by GitHub
parent 6b49a13148
commit fb510ed1a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -113,48 +113,50 @@ function copy() {
toggleDark() toggleDark()
} }
solveWeChatImage() nextTick(() => {
solveWeChatImage()
const clipboardDiv = document.getElementById(`output`) const clipboardDiv = document.getElementById(`output`)
clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML) clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML)
clipboardDiv.innerHTML = modifyHtmlStructure(clipboardDiv.innerHTML) clipboardDiv.innerHTML = modifyHtmlStructure(clipboardDiv.innerHTML)
// katex // katex
clipboardDiv.innerHTML = clipboardDiv.innerHTML clipboardDiv.innerHTML = clipboardDiv.innerHTML
.replace( .replace(
/class="base"( style="display: inline")*/g, /class="base"( style="display: inline")*/g,
`class="base" style="display: inline"`, `class="base" style="display: inline"`,
) )
// position translateY // position translateY
.replace(/top:(.*?)em/g, `transform: translateY($1em)`) .replace(/top:(.*?)em/g, `transform: translateY($1em)`)
// //
.replaceAll(`var(--el-text-color-regular)`, `#3f3f3f`) .replaceAll(`var(--el-text-color-regular)`, `#3f3f3f`)
clipboardDiv.focus() clipboardDiv.focus()
window.getSelection().removeAllRanges() window.getSelection().removeAllRanges()
const range = document.createRange() const range = document.createRange()
range.setStartBefore(clipboardDiv.firstChild) range.setStartBefore(clipboardDiv.firstChild)
range.setEndAfter(clipboardDiv.lastChild) range.setEndAfter(clipboardDiv.lastChild)
window.getSelection().addRange(range) window.getSelection().addRange(range)
document.execCommand(`copy`) document.execCommand(`copy`)
window.getSelection().removeAllRanges() window.getSelection().removeAllRanges()
clipboardDiv.innerHTML = output.value clipboardDiv.innerHTML = output.value
if (isBeforeDark) { if (isBeforeDark) {
toggleDark() toggleDark()
} }
// //
ElNotification({ ElNotification({
showClose: true, showClose: true,
message: `已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴`, message: `已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴`,
offset: 80, offset: 80,
duration: 1600, duration: 1600,
type: `success`, type: `success`,
})
editorRefresh()
emit(`endCopy`)
}) })
editorRefresh()
emit(`endCopy`)
}, 350) }, 350)
} }
</script> </script>