BigUpdate
Python application / build (push) Has been cancelled

This commit is contained in:
Igor20264
2026-09-03 10:44:08 +03:00
parent d2da20fdb2
commit 516abe7b83
177 changed files with 40178 additions and 2 deletions
+36
View File
@@ -0,0 +1,36 @@
from collections.abc import Generator
from docx import Document
from marko.block import BlankLine
from .extended_markdown import markdown, Caption
from .renderable.caption import CaptionInfo
from .renderable.renderable import Renderable
from .renderable_factory import RenderableFactory
class Parser:
"""Parses given markdown string and returns Renderable elements"""
def __init__(self, document: Document, text: str):
self._document = document
self._parsed = markdown.parse(text)
self._caption_info: CaptionInfo | None = None
def parse(self) -> Generator[Renderable, None, None]:
factory = RenderableFactory(self._document._body)
for marko_element in self._parsed.children:
if isinstance(marko_element, BlankLine):
continue
if isinstance(marko_element, Caption):
self._caption_info = CaptionInfo(
marko_element.unique_name,
marko_element.text,
getattr(marko_element, "with_listing", False),
)
continue
yield factory.create(marko_element, self._caption_info)
self._caption_info = None