# -*- coding: utf-8 -*-
# Copyright 2026 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
from ... import text, util
def to_html(markup):
html = []
data = util.json_loads(markup)
for block in data["content"]:
process_content(html, block)
return "".join(html)
def process_content(html, content):
type = content["type"]
if type == "paragraph":
if children := content.get("content"):
html.append('
')
for block in children:
process_content(html, block)
html.append("
")
else:
html.append("")
elif type == "text":
process_text(html, content)
elif type == "heading":
if attrs := content.get("attrs"):
level = str(attrs.get("level") or "3")
else:
level = "3"
html.append(f"")
process_children(html, content)
html.append(f"")
elif type in {"listItem", "bulletList", "orderedList", "blockquote"}:
c = type[1]
tag = (
"li" if c == "i" else
"ul" if c == "u" else
"ol" if c == "r" else
"blockquote"
)
html.append(f"<{tag}>")
process_children(html, content)
html.append(f"{tag}>")
elif type == "image":
if (attrs := content.get("attrs")) and (src := attrs.get("src")):
html.append('
')
elif type == "video":
if (attrs := content.get("attrs")) and (mid := attrs.get("media_id")):
mid = text.escape(mid)
html.append('