Keep (add if not existing) xmlns attribute for generated SVG images (#23410)
Fix #23409 Developers could browse & preview the local SVG images files directly. It still has clear output.   --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: delvh <leon@kske.dev>
This commit is contained in:
parent
34a2cf5079
commit
a797b8458e
343 changed files with 357 additions and 343 deletions
|
@ -25,14 +25,22 @@ async function processFile(file, {prefix, fullName} = {}) {
|
|||
if (prefix === 'octicon') name = name.replace(/-[0-9]+$/, ''); // chop of '-16' on octicons
|
||||
}
|
||||
|
||||
// Set the `xmlns` attribute so that the files are displayable in standalone documents
|
||||
// The svg backend module will strip the attribute during startup for inline display
|
||||
const {data} = optimize(await readFile(file, 'utf8'), {
|
||||
plugins: [
|
||||
{name: 'preset-default'},
|
||||
{name: 'removeXMLNS'},
|
||||
{name: 'removeDimensions'},
|
||||
{name: 'prefixIds', params: {prefix: () => name}},
|
||||
{name: 'addClassesToSVGElement', params: {classNames: ['svg', name]}},
|
||||
{name: 'addAttributesToSVGElement', params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]}},
|
||||
{
|
||||
name: 'addAttributesToSVGElement', params: {
|
||||
attributes: [
|
||||
{'xmlns': 'http://www.w3.org/2000/svg'},
|
||||
{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'},
|
||||
]
|
||||
}
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue