mirror of
https://github.com/doocs/md.git
synced 2024-11-28 13:36:32 +08:00
fix: copy of dark theme (#328)
This commit is contained in:
parent
6b49a13148
commit
fb510ed1a3
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user