Skip to content

Commit

Permalink
fix: html encode
Browse files Browse the repository at this point in the history
  • Loading branch information
hzsrc committed Nov 15, 2024
1 parent 31a2400 commit 93b5841
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export async function nodeToDataURL(
foreignObject.appendChild(node)
if (usePageCss) {
const style = document.createElementNS(xmlns, 'style')
style.innerHTML = await getStyles()
style.insertAdjacentText('beforeend', await getStyles())
svg.insertBefore(style, foreignObject)
}

Expand Down Expand Up @@ -315,7 +315,9 @@ export function getStyles() {
)
} else {
promises.push(
Promise.resolve(transRelPath(window.location.href, (e as HTMLStyleElement).innerText)),
Promise.resolve(
transRelPath(window.location.href, (e as HTMLStyleElement).innerText),
),
)
}
})
Expand All @@ -324,7 +326,8 @@ export function getStyles() {
})
}

function transRelPath(cssPath: string, cssText: string): Promise<string> {
function transRelPath(cssPath: string, cssTextIn: string): Promise<string> {
const cssText = cssTextIn.replace(/\/\*[\s\S]*?\*\//g, '')
const quotReg = /^\s*(['"])(.+?)\1/
const map: { [url: string]: string } = {}
// css中的图片路径是相对于css文件的,要改为相对于当前html文件
Expand Down

0 comments on commit 93b5841

Please sign in to comment.