mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
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:
@@ -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'},
|
||||
]
|
||||
}
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user