Feat:导出svg时替换svg中存在的 字符,防止导出的svg报错
This commit is contained in:
parent
839c79405f
commit
8c79ffd723
@ -1,4 +1,4 @@
|
|||||||
import { imgToDataUrl, downloadFile, readBlob } from '../utils'
|
import { imgToDataUrl, downloadFile, readBlob, removeHTMLEntities } from '../utils'
|
||||||
import { SVG } from '@svgdotjs/svg.js'
|
import { SVG } from '@svgdotjs/svg.js'
|
||||||
import drawBackgroundImageToCanvas from '../utils/simulateCSSBackgroundInCanvas'
|
import drawBackgroundImageToCanvas from '../utils/simulateCSSBackgroundInCanvas'
|
||||||
import { transformToMarkdown } from '../parse/toMarkdown'
|
import { transformToMarkdown } from '../parse/toMarkdown'
|
||||||
@ -154,6 +154,7 @@ class Export {
|
|||||||
*/
|
*/
|
||||||
async png(name, transparent = false) {
|
async png(name, transparent = false) {
|
||||||
let { node, str } = await this.getSvgData()
|
let { node, str } = await this.getSvgData()
|
||||||
|
str = removeHTMLEntities(str)
|
||||||
// 如果开启了富文本,则使用htmltocanvas转换为图片
|
// 如果开启了富文本,则使用htmltocanvas转换为图片
|
||||||
if (this.mindMap.richText) {
|
if (this.mindMap.richText) {
|
||||||
let res = await this.mindMap.richText.handleExportPng(node.node)
|
let res = await this.mindMap.richText.handleExportPng(node.node)
|
||||||
@ -207,6 +208,7 @@ class Export {
|
|||||||
node.first().before(SVG(`<title>${name}</title>`))
|
node.first().before(SVG(`<title>${name}</title>`))
|
||||||
await this.drawBackgroundToSvg(node)
|
await this.drawBackgroundToSvg(node)
|
||||||
let str = node.svg()
|
let str = node.svg()
|
||||||
|
str = removeHTMLEntities(str)
|
||||||
// 转换成blob数据
|
// 转换成blob数据
|
||||||
let blob = new Blob([str], {
|
let blob = new Blob([str], {
|
||||||
type: 'image/svg+xml'
|
type: 'image/svg+xml'
|
||||||
|
|||||||
@ -453,3 +453,11 @@ export const loadImage = imgFile => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 移除字符串中的html实体
|
||||||
|
export const removeHTMLEntities = (str) => {
|
||||||
|
[[' ', ' ']].forEach((item) => {
|
||||||
|
str = str.replaceAll(item[0], item[1])
|
||||||
|
})
|
||||||
|
return str
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user