"
''
)
def book() -> Book:
return Book(docs=[Doc("ch.xhtml", CH1), Doc("notes.xhtml", NOTES)])
def test_end_of_chapter(convert):
run = convert(book())
text = run.chapter("001")
body, _, defs = text.partition("[^fn-001]:")
assert "Erste Aussage[^fn-001] und nochmal[^fn-001]." in body
assert "Zweite[^fn-002]." in body
assert "Erster Absatz" not in body # not duplicated as running text
assert "Erster Absatz mit *Betonung* und [Link](https://example.org).\n\n Zweiter Absatz mit `code()`." in defs
assert "[^fn-002]: Endnote mit Formel $e^{x}$." in text
assert text.count("[^fn-001]:") == 1
assert run.report["footnotes"]["rendered"] == 2
def test_end_of_book(convert):
run = convert(book(), "--footnotes", "end-of-book")
text = run.chapter("001")
assert '[1](999-anmerkungen.md#fn-001)' in text
assert '' in text
notes = run.chapter("999")
assert '**1.** Erster Absatz' in notes
assert "[↩](001-kapitel.md#fnref-001)" in notes and "[↩](001-kapitel.md#fnref-001-2)" in notes
assert run.report["output_link_check"]["broken_count"] == 0
def test_inline(convert):
text = convert(book(), "--footnotes", "inline").chapter("001")
assert "Zweite (Anmerkung: Endnote mit Formel $e^{x}$.)." in text
assert "Erste Aussage (Anmerkung: Erster Absatz mit *Betonung* und [Link](https://example.org). Zweiter Absatz" in text
assert "[^fn" not in text
def test_inline_falls_back_for_block_content(convert):
body = ('
'
'')
text = convert(Book(docs=[Doc("c.xhtml", body)]), "--footnotes", "inline").chapter("001")
assert "Text[^fn-001]." in text
assert "[^fn-001]: ```" in text
def test_keep_links(convert):
run = convert(book(), "--footnotes", "keep-links")
text = run.chapter("001")
assert "[1](#fn1)" in text
assert '' in text
assert "Erster Absatz" in text
assert run.report["output_link_check"]["broken_count"] == 0
def test_class_based_footnotes_with_backlinks(convert):
body = ('
')
text = convert(Book(docs=[Doc("c.xhtml", body)])).chapter("001")
assert "Text[^fn-001]." in text
assert re.search(r"^\[\^fn-001\]: Die Fußnote\.$", text, re.M)
def test_unresolvable_noteref_is_warned(convert):
body = '
'
run = convert(Book(docs=[Doc("c.xhtml", body)]))
codes = [w["code"] for w in run.report["warnings"]]
assert "noteref-unresolved" in codes
def test_commonmark_footnotes_use_anchor_links(convert):
run = convert(book(), "--format", "commonmark")
text = run.chapter("001")
assert "[^fn" not in text
assert '1' in text
assert '**1:** Erster Absatz' in text
assert "[↩](#fnref-001)" in text
assert run.report["output_link_check"]["broken_count"] == 0