mirror of
https://github.com/doocs/md.git
synced 2025-01-22 20:04:39 +08:00
fix: copy svg (#491)
All checks were successful
Build and Deploy / build-and-deploy (push) Has been skipped
All checks were successful
Build and Deploy / build-and-deploy (push) Has been skipped
close #490
This commit is contained in:
parent
8d620bc693
commit
1ab6cbfeb2
@ -64,6 +64,15 @@ const copyMode = useStorage(addPrefix(`copyMode`), `txt`)
|
|||||||
const source = ref(``)
|
const source = ref(``)
|
||||||
const { copy: copyContent } = useClipboard({ source })
|
const { copy: copyContent } = useClipboard({ source })
|
||||||
|
|
||||||
|
const creatEmptyNode = () => {
|
||||||
|
const node = document.createElement(`p`)
|
||||||
|
node.style.fontSize = `0`
|
||||||
|
node.style.lineHeight = `0`
|
||||||
|
node.style.margin = `0`
|
||||||
|
node.innerHTML = ` `
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
// 复制到微信公众号
|
// 复制到微信公众号
|
||||||
function copy() {
|
function copy() {
|
||||||
emit(`startCopy`)
|
emit(`startCopy`)
|
||||||
@ -107,13 +116,11 @@ function copy() {
|
|||||||
|
|
||||||
clipboardDiv.focus()
|
clipboardDiv.focus()
|
||||||
|
|
||||||
// edge case: 由于 svg 无法复制, 在前面插入一个空节点
|
// 由于 svg 无法复制, 在前后各插入一个空白节点
|
||||||
const p = document.createElement(`p`)
|
const beforeNode = creatEmptyNode()
|
||||||
p.style.fontSize = `0` // 设置字体大小为 0
|
const afterNode = creatEmptyNode()
|
||||||
p.style.lineHeight = `0` // 行高也为 0
|
clipboardDiv.insertBefore(beforeNode, clipboardDiv.firstChild)
|
||||||
p.style.margin = `0` // 避免外边距干扰
|
clipboardDiv.appendChild(afterNode)
|
||||||
p.innerHTML = ` `
|
|
||||||
clipboardDiv.insertBefore(p, clipboardDiv.firstChild)
|
|
||||||
|
|
||||||
// 兼容 Mermaid
|
// 兼容 Mermaid
|
||||||
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)
|
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)
|
||||||
|
Loading…
Reference in New Issue
Block a user