mirror of
https://github.com/iconify/iconify.git
synced 2024-12-13 22:18:24 +00:00
chore: svg on css requires svg and xlink namespaces
This commit is contained in:
parent
85d9c1e8b7
commit
e507252841
@ -1,10 +1,17 @@
|
|||||||
// https://bl.ocks.org/jennyknuth/222825e315d45a738ed9d6e04c7a88d0
|
// https://bl.ocks.org/jennyknuth/222825e315d45a738ed9d6e04c7a88d0
|
||||||
export function encodeSvgForCss(svg: string): string {
|
export function encodeSvgForCss(svg: string): string {
|
||||||
return svg.replace(/"/g, '\'')
|
let useSvg = svg.startsWith('<svg>') ? svg.replace('<svg>', '<svg >') : svg;
|
||||||
|
if (!useSvg.includes(' xmlns:xlink=') && useSvg.includes(' xlink:')) {
|
||||||
|
useSvg = useSvg.replace('<svg ', '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ');
|
||||||
|
}
|
||||||
|
if (!useSvg.includes(' xmlns=')) {
|
||||||
|
useSvg = useSvg.replace('<svg ', '<svg xmlns="http://www.w3.org/2000/svg" ');
|
||||||
|
}
|
||||||
|
return useSvg.replace(/"/g, '\'')
|
||||||
.replace(/%/g, '%25')
|
.replace(/%/g, '%25')
|
||||||
.replace(/#/g, '%23')
|
.replace(/#/g, '%23')
|
||||||
.replace(/{/g, '%7B')
|
.replace(/{/g, '%7B')
|
||||||
.replace(/}/g, '%7D')
|
.replace(/}/g, '%7D')
|
||||||
.replace(/</g, '%3C')
|
.replace(/</g, '%3C')
|
||||||
.replace(/>/g, '%3E')
|
.replace(/>/g, '%3E');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user