diff --git a/mknodes/resources/material_css.jinja b/mknodes/resources/material_css.jinja index e90307c4..33c446d0 100644 --- a/mknodes/resources/material_css.jinja +++ b/mknodes/resources/material_css.jinja @@ -2,7 +2,7 @@ content_area_width, classic_admonition_style, show_annotation_numbers, default_icons, color_theme*/ :root { {% for admonition in admonitions %} - --md-admonition-icon--note: url('data:image/svg+xml;charset=utf-8,{{ admonition.svg }}'); + --md-admonition-icon--{{ admonition.name }}: url('data:image/svg+xml;charset=utf-8,{{ admonition.svg }}'); {% endfor %} {% for status_icon in status_icons %} --md-status--encrypted: url('data:image/svg+xml;charset=utf-8,{ {status_icon.svg }}'); @@ -28,26 +28,26 @@ content_area_width, classic_admonition_style, show_annotation_numbers, default_i {% endif %} } {% for admonition in admonitions %} -.md-typeset .admonition.{{ admonition.type }}, -.md-typeset details.{{ admonition.type }} { +.md-typeset .admonition.{{ admonition.name }}, +.md-typeset details.{{ admonition.name }} { border-color: {{ admonition.border_color }}; } -.md-typeset .admonition.{{ admonition.type }}:focus-within, -.md-typeset details.{{ admonition.type }}:focus-within { +.md-typeset .admonition.{{ admonition.name }}:focus-within, +.md-typeset details.{{ admonition.name }}:focus-within { box-shadow: 0 0 0 0.2rem {{ admonition.header_color }}; ## #00c8531a } -.md-typeset .{{ admonition.type }} > .admonition-title, -.md-typeset .{{ admonition.type }} > summary { +.md-typeset .{{ admonition.name }} > .admonition-title, +.md-typeset .{{ admonition.name }} > summary { background-color: {{ admonition.header_color }}; } -.md-typeset .{{ admonition.type }} > .admonition-title:before, -.md-typeset .{{ admonition.type }} > summary:before { +.md-typeset .{{ admonition.name }} > .admonition-title:before, +.md-typeset .{{ admonition.name }} > summary:before { background-color: {{admonition.icon_color}}; - -webkit-mask-image: var(--md-admonition-icon--{{ admonition.type }}); - mask-image: var(--md-admonition-icon--{{ admonition.type }}); + -webkit-mask-image: var(--md-admonition-icon--{{ admonition.name }}); + mask-image: var(--md-admonition-icon--{{ admonition.name }}); } -.md-typeset .{{ admonition.type }} > .admonition-title:after, -.md-typeset .{{ admonition.type }} > summary:after { +.md-typeset .{{ admonition.name }} > .admonition-title:after, +.md-typeset .{{ admonition.name }} > summary:after { color: {{ admonition.icon_color }}; ## #00c853 } diff --git a/mknodes/theme/materialtheme.py b/mknodes/theme/materialtheme.py index 4d8a8dd0..7d7412cc 100644 --- a/mknodes/theme/materialtheme.py +++ b/mknodes/theme/materialtheme.py @@ -11,7 +11,7 @@ from mknodes.data import datatypes from mknodes.theme import mkblog, theme from mknodes.theme.material import palette -from mknodes.utils import helpers, log, reprhelpers +from mknodes.utils import helpers, log, pathhelpers, reprhelpers logger = log.get_logger(__name__) @@ -75,6 +75,7 @@ def build_badge(icon: str, text: str = "", typ: str = ""): @dataclasses.dataclass class AdmonitionType: + name: str svg: str header_color: str icon_color: str @@ -238,15 +239,17 @@ def _text_color(self): def add_admonition_type( self, name: str, - data: str, + material_icon: str, header_color: datatypes.ColorType, icon_color: datatypes.ColorType | None = None, border_color: datatypes.ColorType | None = None, ): - header_color_str = helpers.get_color_str(header_color) - icon_color_str = helpers.get_color_str(icon_color or (255, 255, 255)) - border_color_str = helpers.get_color_str(border_color or (255, 255, 255)) - adm = AdmonitionType(data, header_color_str, icon_color_str, border_color_str) + header_col_str = helpers.get_color_str(header_color) + icon_col_str = helpers.get_color_str(icon_color or (255, 255, 255)) + border_col_str = helpers.get_color_str(border_color or (255, 255, 255)) + icon = pathhelpers.get_material_icon_path(material_icon) + data = icon.read_text() + adm = AdmonitionType(name, data, header_col_str, icon_col_str, border_col_str) self.admonitions.append(adm) def set_primary_foreground_color( @@ -272,7 +275,9 @@ def set_primary_foreground_color( def set_default_icon(self, icon_type: IconTypeStr, data: str): self.default_icons[icon_type] = data - def add_status_icon(self, name: str, data: str): + def add_status_icon(self, name: str, material_icon: str): + icon = pathhelpers.get_material_icon_path(material_icon) + data = icon.read_text() self.status_icons.append(StatusIcon(name, data)) def adapt_extensions(self, extensions: MutableMapping[str, dict]):