@@ -46,7 +46,8 @@ class Converter:
|
||||
table_continuation: str = DEFAULT_TABLE_CONTINUATION,
|
||||
listing_continuation: str = DEFAULT_LISTING_CONTINUATION,
|
||||
hr_pagebreak: bool = False,
|
||||
styles_path: str | None = None):
|
||||
styles_path: str | None = None,
|
||||
markdown_text: str | None = None):
|
||||
if heading_numbering not in HEADING_NUMBERING_MODES:
|
||||
raise ValueError(
|
||||
f"heading_numbering must be one of {HEADING_NUMBERING_MODES}, "
|
||||
@@ -79,6 +80,7 @@ class Converter:
|
||||
self._document: Document = docx.Document(template_path)
|
||||
self._document._body.clear_content()
|
||||
md_dir = os.path.dirname(os.path.abspath(input_path)) or "."
|
||||
os.environ["WORKING_DIR"] = md_dir
|
||||
self._style_config = apply_document_styles(
|
||||
self._document,
|
||||
self._profile.style_preset,
|
||||
@@ -86,8 +88,11 @@ class Converter:
|
||||
styles_path=styles_path,
|
||||
)
|
||||
self._debugger = Debugger(self._document) if debug else None
|
||||
with open(input_path, encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
if markdown_text is not None:
|
||||
raw = markdown_text
|
||||
else:
|
||||
with open(input_path, encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
self._raw_markdown = raw
|
||||
self._preprocessed = preprocess_markdown(raw, emdash_to_hyphen=emdash_to_hyphen)
|
||||
self.parser = Parser(self._document, self._preprocessed, hr_pagebreak=hr_pagebreak)
|
||||
|
||||
Reference in New Issue
Block a user