Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy svg #491

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/components/CodemirrorEditor/EditorHeader/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ const copyMode = useStorage(addPrefix(`copyMode`), `txt`)
const source = ref(``)
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() {
emit(`startCopy`)
Expand Down Expand Up @@ -107,13 +116,11 @@ function copy() {

clipboardDiv.focus()

// edge case: 由于 svg 无法复制, 在前面插入一个空节点
const p = document.createElement(`p`)
p.style.fontSize = `0` // 设置字体大小为 0
p.style.lineHeight = `0` // 行高也为 0
p.style.margin = `0` // 避免外边距干扰
p.innerHTML = ` `
clipboardDiv.insertBefore(p, clipboardDiv.firstChild)
// 由于 svg 无法复制, 在前后各插入一个空白节点
const beforeNode = creatEmptyNode()
const afterNode = creatEmptyNode()
clipboardDiv.insertBefore(beforeNode, clipboardDiv.firstChild)
clipboardDiv.appendChild(afterNode)

// 兼容 Mermaid
const nodes = clipboardDiv.querySelectorAll(`.nodeLabel`)
Expand Down
Loading