lib.itmens/journal/renderers.py
Henri Dickson 0ffd47ca96
new style
* new style with picocss
* djlint
* rate distribution
* collection item drag to order
* discover available for guest
* search combine movie tv
2023-05-20 11:01:18 -04:00

48 lines
980 B
Python

from typing import cast
import mistune
import re
from django.utils.html import escape
MARKDOWNX_MARKDOWNIFY_FUNCTION = "journal.renderers.render_md"
_mistune_plugins = [
"url",
"strikethrough",
"footnotes",
"table",
"mark",
"superscript",
"subscript",
"math",
"spoiler",
"ruby",
]
_markdown = mistune.create_markdown(plugins=_mistune_plugins)
def render_md(s) -> str:
# s = "\n".join(
# [
# re.sub(r"^(\u2003+)", lambda s: " " * len(s[0]), line)
# for line in s.split("\n")
# ]
# )
return cast(str, _markdown(s))
def _spolier(s):
l = s.split(">!", 1)
if len(l) == 1:
return escape(s)
r = l[1].split("!<", 1)
return (
escape(l[0])
+ '<span class="spoiler" _="on click toggle .revealed on me">'
+ escape(r[0])
+ "</span>"
+ (_spolier(r[1]) if len(r) == 2 else "")
)
def render_text(s):
return _spolier(s)