- Add\Rework UI - Add Split Table and Listing - Add Support Customazeble schems
This commit is contained in:
+8
-3
@@ -1,7 +1,7 @@
|
||||
from collections.abc import Generator
|
||||
|
||||
from docx import Document
|
||||
from marko.block import BlankLine
|
||||
from marko.block import BlankLine, ThematicBreak
|
||||
|
||||
from .extended_markdown import markdown, Caption
|
||||
from .renderable.caption import CaptionInfo
|
||||
@@ -12,13 +12,14 @@ from .renderable_factory import RenderableFactory
|
||||
class Parser:
|
||||
"""Parses given markdown string and returns Renderable elements"""
|
||||
|
||||
def __init__(self, document: Document, text: str):
|
||||
def __init__(self, document: Document, text: str, hr_pagebreak: bool = False):
|
||||
self._document = document
|
||||
self._parsed = markdown.parse(text)
|
||||
self._caption_info: CaptionInfo | None = None
|
||||
self._hr_pagebreak = hr_pagebreak
|
||||
|
||||
def parse(self) -> Generator[Renderable, None, None]:
|
||||
factory = RenderableFactory(self._document._body)
|
||||
factory = RenderableFactory(self._document._body, hr_pagebreak=self._hr_pagebreak)
|
||||
|
||||
for marko_element in self._parsed.children:
|
||||
if isinstance(marko_element, BlankLine):
|
||||
@@ -29,8 +30,12 @@ class Parser:
|
||||
marko_element.unique_name,
|
||||
marko_element.text,
|
||||
getattr(marko_element, "with_listing", False),
|
||||
getattr(marko_element, "landscape", False),
|
||||
)
|
||||
continue
|
||||
|
||||
if isinstance(marko_element, ThematicBreak) and not self._hr_pagebreak:
|
||||
continue
|
||||
|
||||
yield factory.create(marko_element, self._caption_info)
|
||||
self._caption_info = None
|
||||
|
||||
Reference in New Issue
Block a user