Bedienungsanleitung ergänzt, Bildpfade relativ zur Markdown-Datei
- BEDIENUNGSANLEITUNG.md: Installation, Weg A (PDF -> EPUB), Weg B (Markdown
bearbeiten, dann pandoc), Scans, Optionen, Prüfen, häufige Probleme;
Verweis in README.md
- Fix: pymupdf4llm schreibt Bildpfade relativ zum Arbeitsverzeichnis
("Output/x_images/…"), wenn der Bilderordner darunter liegt. Die Links
zeigen jetzt immer relativ zur Markdown-Datei; Regressionstests ergänzt.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9fc620ad55
commit
85a01ac5c7
2 changed files with 285 additions and 8 deletions
|
|
@ -13,12 +13,13 @@ from conftest import ROOT, TITLE, needs_pandoc, needs_tesseract
|
|||
SCRIPT = ROOT / "pdf2md_v5.py"
|
||||
|
||||
|
||||
def run(*args) -> subprocess.CompletedProcess:
|
||||
def run(*args, cwd=None) -> subprocess.CompletedProcess:
|
||||
done = subprocess.run(
|
||||
[sys.executable, str(SCRIPT), *map(str, args)],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=600,
|
||||
cwd=cwd,
|
||||
)
|
||||
assert done.returncode == 0, done.stderr
|
||||
return done
|
||||
|
|
@ -128,3 +129,14 @@ def test_png_on_request(pdfs, tmp_path):
|
|||
run(pdfs["digital"], out, "--images", "--image-format", "png")
|
||||
md = out.read_text(encoding="utf-8")
|
||||
assert re.search(r"!\[\]\(png_images/[^)]+\.png\)", md)
|
||||
|
||||
|
||||
def test_image_links_relative_to_markdown_with_relative_output(pdfs, tmp_path):
|
||||
# Aufruf wie "python3 pdf2md_v5.py --images buch.pdf Output/buch.md" aus dem Projektordner
|
||||
run(pdfs["digital"], "Output/buch.md", "--images", cwd=tmp_path)
|
||||
md = (tmp_path / "Output" / "buch.md").read_text(encoding="utf-8")
|
||||
links = re.findall(r"!\[\]\(([^)]+)\)", md)
|
||||
assert links
|
||||
for link in links:
|
||||
assert link.startswith("buch_images/"), link
|
||||
assert (tmp_path / "Output" / link).is_file()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
"""Unit-Tests für die Markdown-Nachbearbeitung (ohne PDF, schnell)."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pymupdf
|
||||
import pytest
|
||||
|
||||
|
|
@ -263,3 +265,17 @@ def test_split_by_indent_needs_sentence_end():
|
|||
def test_demoted_heading_after_closed_paragraph_starts_new_paragraph():
|
||||
md = "Erster Absatz.\n## Sie verabschiedeten sich.\n"
|
||||
assert norm(md) == "Erster Absatz.\n\nSie verabschiedeten sich.\n"
|
||||
|
||||
|
||||
def test_make_image_links_relative(tmp_path, monkeypatch):
|
||||
image_dir = tmp_path / "Output" / "buch_images"
|
||||
image_dir.mkdir(parents=True)
|
||||
monkeypatch.chdir(tmp_path)
|
||||
md = (
|
||||
f"\n\n\n\n"
|
||||
"\n"
|
||||
)
|
||||
assert p.make_image_links_relative(md, Path("Output/buch_images")) == (
|
||||
"\n\n\n\n"
|
||||
"\n"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue