18 lines
478 B
Python
18 lines
478 B
Python
import re
|
|
from html import escape, unescape
|
|
|
|
BOLD_TAGS = ("<b>", "</b>")
|
|
TAG_RE = re.compile(r"(</?b>)")
|
|
|
|
|
|
def to_matrix(text: str) -> tuple[str, str]:
|
|
plain, formatted = [], []
|
|
for part in TAG_RE.split(text):
|
|
if part in BOLD_TAGS:
|
|
formatted.append(part)
|
|
continue
|
|
raw = unescape(part)
|
|
plain.append(raw)
|
|
formatted.append(escape(raw, quote=False).replace("\n", "<br>"))
|
|
return "".join(plain), "".join(formatted)
|