From c7d0f2518883c5aa73505ba04874f452ae55c470 Mon Sep 17 00:00:00 2001 From: phil65 Date: Mon, 16 Oct 2023 05:51:55 +0200 Subject: [PATCH] chore: icon work --- mknodes/basenodes/mklink.py | 9 ++++----- mknodes/utils/icons.py | 13 +++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mknodes/basenodes/mklink.py b/mknodes/basenodes/mklink.py index c8049447..aa9d2767 100644 --- a/mknodes/basenodes/mklink.py +++ b/mknodes/basenodes/mklink.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any from mknodes.basenodes import mknode -from mknodes.utils import log, reprhelpers +from mknodes.utils import icons, log, reprhelpers if TYPE_CHECKING: @@ -66,10 +66,9 @@ def __repr__(self): @property def icon(self) -> str: - if not self._icon or self._icon.startswith(":"): - return self._icon - icon = self._icon if "/" in self._icon else f"material/{self._icon}" - return f':{icon.replace("/", "-")}:' + if not self._icon: + return "" + return icons.get_emoji_slug(self._icon) @property def url(self) -> str: diff --git a/mknodes/utils/icons.py b/mknodes/utils/icons.py index 01974bec..90bb276e 100644 --- a/mknodes/utils/icons.py +++ b/mknodes/utils/icons.py @@ -124,6 +124,13 @@ def get_icon_svg(icon: str) -> str: get_icon_svg("material/file") # Material-style path get_icon_svg(":material-file:") # material-style emoji slug """ + key = get_pyconify_key(icon) + import pyconify + + return pyconify.svg(key).decode() + + +def get_pyconify_key(icon: str): for k, v in PYCONIFY_TO_PREFIXES.items(): path = f'{v.replace("-", "/")}/' icon = icon.replace(path, f"{k}:") @@ -132,9 +139,11 @@ def get_icon_svg(icon: str) -> str: icon = icon.strip(":") if ":" not in icon: icon = f"mdi:{icon}" - import pyconify + return icon + - return pyconify.svg(icon).decode() +def get_emoji_slug(icon): + return f":{get_pyconify_key(icon).replace(':', '-')}:" def get_icon_xml(icon: str) -> etree.Element: