Skip to content

Commit fb510ed

Browse files
authored
fix: copy of dark theme (#328)
1 parent 6b49a13 commit fb510ed

File tree

1 file changed

+40
-38
lines changed
  • src/components/CodemirrorEditor/EditorHeader

1 file changed

+40
-38
lines changed

src/components/CodemirrorEditor/EditorHeader/index.vue

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -113,48 +113,50 @@ function copy() {
113113
toggleDark()
114114
}
115115
116-
solveWeChatImage()
117-
118-
const clipboardDiv = document.getElementById(`output`)
119-
clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML)
120-
clipboardDiv.innerHTML = modifyHtmlStructure(clipboardDiv.innerHTML)
121-
122-
// 调整 katex 公式元素为行内标签,目的是兼容微信公众号渲染
123-
clipboardDiv.innerHTML = clipboardDiv.innerHTML
124-
.replace(
125-
/class="base"( style="display: inline")*/g,
126-
`class="base" style="display: inline"`,
127-
)
116+
nextTick(() => {
117+
solveWeChatImage()
118+
119+
const clipboardDiv = document.getElementById(`output`)
120+
clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML)
121+
clipboardDiv.innerHTML = modifyHtmlStructure(clipboardDiv.innerHTML)
122+
123+
// 调整 katex 公式元素为行内标签,目的是兼容微信公众号渲染
124+
clipboardDiv.innerHTML = clipboardDiv.innerHTML
125+
.replace(
126+
/class="base"( style="display: inline")*/g,
127+
`class="base" style="display: inline"`,
128+
)
128129
// 公众号不支持 position, 转换为等价的 translateY
129-
.replace(/top:(.*?)em/g, `transform: translateY($1em)`)
130+
.replace(/top:(.*?)em/g, `transform: translateY($1em)`)
130131
// 适配主题中的颜色变量
131-
.replaceAll(`var(--el-text-color-regular)`, `#3f3f3f`)
132-
clipboardDiv.focus()
133-
window.getSelection().removeAllRanges()
134-
const range = document.createRange()
135-
136-
range.setStartBefore(clipboardDiv.firstChild)
137-
range.setEndAfter(clipboardDiv.lastChild)
138-
window.getSelection().addRange(range)
139-
document.execCommand(`copy`)
140-
window.getSelection().removeAllRanges()
141-
clipboardDiv.innerHTML = output.value
142-
143-
if (isBeforeDark) {
144-
toggleDark()
145-
}
132+
.replaceAll(`var(--el-text-color-regular)`, `#3f3f3f`)
133+
clipboardDiv.focus()
134+
window.getSelection().removeAllRanges()
135+
const range = document.createRange()
136+
137+
range.setStartBefore(clipboardDiv.firstChild)
138+
range.setEndAfter(clipboardDiv.lastChild)
139+
window.getSelection().addRange(range)
140+
document.execCommand(`copy`)
141+
window.getSelection().removeAllRanges()
142+
clipboardDiv.innerHTML = output.value
143+
144+
if (isBeforeDark) {
145+
toggleDark()
146+
}
147+
148+
// 输出提示
149+
ElNotification({
150+
showClose: true,
151+
message: `已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴`,
152+
offset: 80,
153+
duration: 1600,
154+
type: `success`,
155+
})
146156
147-
// 输出提示
148-
ElNotification({
149-
showClose: true,
150-
message: `已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴`,
151-
offset: 80,
152-
duration: 1600,
153-
type: `success`,
157+
editorRefresh()
158+
emit(`endCopy`)
154159
})
155-
156-
editorRefresh()
157-
emit(`endCopy`)
158160
}, 350)
159161
}
160162
</script>

0 commit comments

Comments
 (0)