2025-12-08 16:57:25 +03:00
|
|
|
import mistune
|
|
|
|
|
from .style_registry import StyleRegistry
|
|
|
|
|
from ..handlers import get_handler
|
|
|
|
|
|
|
|
|
|
def render_markdown_to_docx(doc, md_content: str, images_dir, style_reg: StyleRegistry):
|
|
|
|
|
markdown = mistune.create_markdown(renderer=None)
|
|
|
|
|
ast = markdown(md_content)
|
|
|
|
|
|
|
|
|
|
def walk(node):
|
2025-12-08 17:18:30 +03:00
|
|
|
if isinstance(node, list):
|
|
|
|
|
for item in node:
|
|
|
|
|
walk(item)
|
|
|
|
|
elif isinstance(node, dict):
|
|
|
|
|
handler = get_handler(node["type"])
|
|
|
|
|
if handler:
|
|
|
|
|
handler(node, doc, images_dir, style_reg)
|
|
|
|
|
elif node.get("children"):
|
|
|
|
|
for child in node["children"]:
|
|
|
|
|
walk(child)
|
2025-12-08 16:57:25 +03:00
|
|
|
|
|
|
|
|
walk(ast)
|