'
return Book(docs=[Doc("a.xhtml", a), Doc("b.xhtml", b)])
def test_internal_links_are_rewritten(convert):
run = convert(link_book())
names = [p.name for p in run.chapters()]
assert names == ["001-a.md", "002-zweites-h1.md", "003-b.md"]
a = run.chapter("001")
assert "[Kapitel B](003-b.md)" in a
assert "[Ziel in B](003-b.md#ziel)" in a
assert "[unten](002-zweites-h1.md#unten)" in a # anchor ended up in the split-off chapter
assert "kaputt" in a and "gibtsnicht" not in a # unresolved: text kept, no broken link
assert 'Ziel' in run.chapter("003")
assert "[zurück](001-a.md#start)" in run.chapter("003")
assert run.report["unresolved_links"][0]["href"] == "gibtsnicht.xhtml#x"
assert any(w["code"] == "unresolved-link" for w in run.report["warnings"])
assert run.report["output_link_check"]["broken_count"] == 0
readme = (run.out / "README.md").read_text(encoding="utf-8")
assert "[A](chapters/001-a.md)" in readme
def test_images_are_extracted_once_with_relative_links(convert):
body = ('
Bilder
'
'Abbildung 1: Ein Foto.'
'
'
'Nur Unterschrift')
book = Book(docs=[Doc("c.xhtml", body)], media={"img/foto eins.png": PNG, "img/grafik.svg": SVG})
run = convert(book)
text = run.chapter("001")
assert '' in text
assert "*Abbildung 1: Ein Foto.*" in text
assert "" in text
assert "" in text
images = sorted(p.name for p in (run.out / "media" / "images").iterdir())
assert images == ["0001-foto.png", "0002-grafik.svg"]
assert (run.out / "media/images/0002-grafik.svg").read_bytes() == SVG
assert run.report["output_link_check"]["broken_count"] == 0
def test_image_strategies(convert):
book = Book(docs=[Doc("c.xhtml", '