Fixing Excel login error
This commit is contained in:
@@ -305,6 +305,31 @@ def parse_table(lines: list[str], start: int) -> tuple[list[str], list[list[str]
|
||||
return header, rows, i
|
||||
|
||||
|
||||
def add_image(doc, path: Path, caption: str = ""):
|
||||
if not path.exists():
|
||||
add_quote(doc, f"(عکس پیدا نشد: {path.name})")
|
||||
return
|
||||
p = doc.add_paragraph()
|
||||
set_paragraph_rtl(p, align=WD_ALIGN_PARAGRAPH.CENTER, space_after=4, space_before=8)
|
||||
run = p.add_run()
|
||||
# Keep screenshots readable on A4 without overflowing margins.
|
||||
run.add_picture(str(path), width=Cm(16.5))
|
||||
if caption:
|
||||
cap = doc.add_paragraph()
|
||||
set_paragraph_rtl(cap, align=WD_ALIGN_PARAGRAPH.CENTER, space_after=10)
|
||||
run = cap.add_run(caption)
|
||||
set_run_font(run, 11, color=MUTED)
|
||||
|
||||
|
||||
IMG_RE = re.compile(r"^!\[([^\]]*)\]\(([^)]+)\)$")
|
||||
|
||||
|
||||
def resolve_image_path(md_path: Path, rel: str) -> Path:
|
||||
raw = rel.strip()
|
||||
candidate = (md_path.parent / raw).resolve()
|
||||
return candidate
|
||||
|
||||
|
||||
def convert(md_path: Path, docx_path: Path, header_text: str, footer_text: str):
|
||||
if not md_path.exists():
|
||||
raise FileNotFoundError(md_path)
|
||||
@@ -345,6 +370,12 @@ def convert(md_path: Path, docx_path: Path, header_text: str, footer_text: str):
|
||||
i += 1
|
||||
continue
|
||||
|
||||
img = IMG_RE.match(stripped)
|
||||
if img:
|
||||
add_image(doc, resolve_image_path(md_path, img.group(2)), img.group(1).strip())
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if stripped.startswith("# "):
|
||||
add_heading(doc, stripped[2:], 1)
|
||||
i += 1
|
||||
|
||||
Reference in New Issue
Block a user