template: fix name handling for icons.

This commit is contained in:
Goffi 2025-04-11 18:18:50 +02:00
commit ce5ba7123b

View file

@ -1012,13 +1012,15 @@ class Renderer(object):
if "/" in name: if "/" in name:
raise ValueError("SVG name must not have a `/` in it.") raise ValueError("SVG name must not have a `/` in it.")
if name.startswith("regular "): if name.startswith("regular "):
name = name[8:] filename = name[8:]
path = self.fa_svgs_path / f"regular/{name}.svg" path = self.fa_svgs_path / f"regular/{filename}.svg"
else: else:
if name.startswith("solid "): if name.startswith("solid "):
# "solid" can be explicitely specified, and it's the default value. # "solid" can be explicitely specified, and it's the default value.
name = name[6:] filename = name[6:]
path = self.fa_svgs_path / f"solid/{name}.svg" else:
filename = name
path = self.fa_svgs_path / f"solid/{filename}.svg"
# Parse the source SVG # Parse the source SVG
try: try:
@ -1038,7 +1040,7 @@ class Renderer(object):
symbol = etree.SubElement( symbol = etree.SubElement(
defs_elt, defs_elt,
"symbol", "symbol",
id=name, id=name.replace(" ", "_"),
viewBox=viewbox, viewBox=viewbox,
) )
@ -1060,7 +1062,7 @@ class Renderer(object):
'width="1em" height="1em" fill="currentColor" >\n' 'width="1em" height="1em" fill="currentColor" >\n'
' <use href="#{name}"/>' ' <use href="#{name}"/>'
"</svg>\n".format( "</svg>\n".format(
name=name, name=name.replace(" ", "_"),
cls=(" " + cls) if cls else "", cls=(" " + cls) if cls else "",
extra_attrs=" " + extra_attrs if extra_attrs else "", extra_attrs=" " + extra_attrs if extra_attrs else "",
) )