@@ -0,0 +1,37 @@
|
||||
"""Assemble .fodt from markdown."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from .emitter import emit_fodt
|
||||
|
||||
|
||||
def convert_md_to_fodt(
|
||||
md_path: str | Path,
|
||||
out_path: str | Path | None = None,
|
||||
*,
|
||||
emdash_to_hyphen: bool = False,
|
||||
) -> Path:
|
||||
"""
|
||||
Convert markdown to Flat ODF Text (.fodt).
|
||||
|
||||
Returns path to written .fodt file.
|
||||
"""
|
||||
md_path = Path(md_path).resolve()
|
||||
if out_path is None:
|
||||
out_path = md_path.with_suffix(".fodt")
|
||||
else:
|
||||
out_path = Path(out_path)
|
||||
if out_path.suffix.lower() != ".fodt":
|
||||
out_path = out_path.with_suffix(".fodt")
|
||||
|
||||
md_text = md_path.read_text(encoding="utf-8")
|
||||
xml = emit_fodt(
|
||||
md_text,
|
||||
work_dir=md_path.parent,
|
||||
emdash_to_hyphen=emdash_to_hyphen,
|
||||
)
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
out_path.write_text(xml, encoding="utf-8")
|
||||
return out_path.resolve()
|
||||
Reference in New Issue
Block a user