initial MVP

This commit is contained in:
Mikan
2025-12-08 16:57:25 +03:00
commit 848eb462b5
20 changed files with 398 additions and 0 deletions

30
src/core/converter.py Normal file
View File

@@ -0,0 +1,30 @@
from pathlib import Path
from docx import Document
from .style_registry import StyleRegistry
from .renderer import render_markdown_to_docx
def process_document(input_dir: Path, output_dir: Path, style_config_path: Path):
style_reg = StyleRegistry(style_config_path)
for doc_dir in input_dir.iterdir():
if not doc_dir.is_dir():
continue
doc_name = doc_dir.name
md_path = doc_dir / "document.md"
images_dir = doc_dir / "images"
if not md_path.exists():
print(f"⚠️ Пропущено: {doc_name} — нет document.md")
continue
with open(md_path, encoding="utf-8") as f:
md_content = f.read()
doc = Document()
style_reg.ensure_styles_in_doc(doc) # добавляем стили
render_markdown_to_docx(doc, md_content, images_dir, style_reg)
output_path = output_dir / f"{doc_name}.docx"
output_path.parent.mkdir(parents=True, exist_ok=True)
doc.save(output_path)
print(f"{doc_name}{output_path}")