2023-09-06 13:44:00 +01:00
|
|
|
from html5tagger import HTML, E
|
2023-10-25 01:03:35 +01:00
|
|
|
from mistune.directives import Admonition
|
2023-09-06 13:44:00 +01:00
|
|
|
|
2023-10-25 03:02:26 +01:00
|
|
|
|
2023-09-06 13:44:00 +01:00
|
|
|
class Notification(Admonition):
|
|
|
|
SUPPORTED_NAMES = {
|
|
|
|
"success",
|
|
|
|
"info",
|
|
|
|
"warning",
|
|
|
|
"danger",
|
|
|
|
"tip",
|
|
|
|
"new",
|
|
|
|
"note",
|
|
|
|
}
|
|
|
|
|
|
|
|
def __call__(self, directive, md):
|
|
|
|
for name in self.SUPPORTED_NAMES:
|
|
|
|
directive.register(name, self.parse)
|
|
|
|
|
|
|
|
if md.renderer.NAME == "html":
|
|
|
|
md.renderer.register("admonition", self._render_admonition)
|
2023-10-25 04:13:13 +01:00
|
|
|
md.renderer.register("admonition_title", self._render_admonition_title)
|
|
|
|
md.renderer.register("admonition_content", self._render_admonition_content)
|
2023-09-06 13:44:00 +01:00
|
|
|
|
|
|
|
def _render_admonition(self, _, text, name, **attrs) -> str:
|
|
|
|
return str(
|
|
|
|
E.div(
|
|
|
|
HTML(text),
|
|
|
|
class_=f"notification is-{name}",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def _render_admonition_title(self, _, text) -> str:
|
|
|
|
return str(
|
|
|
|
E.p(
|
|
|
|
text,
|
|
|
|
class_="notification-title",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def _render_admonition_content(self, _, text) -> str:
|
|
|
|
return text
|