"""Typography and layout: invisible characters, CSS emphasis, scene breaks, boxes, styles, page markers.""" from conftest import Book, Doc ZW, SHY = "", "" def test_p6_invisible_characters_removed_outside_code(convert): body = (f"
Lese{SHY}rinnen und 1.{ZW}1 sowie{ZW}Wort.
" f"a{ZW}bx{SHY}y
Ein kursives und fettes Wort, ' 'unterstrichen, gestrichen, x2, ' '[»] sichtbar, printf und ' 'zwei Wörter, inline, ' 'example.org.
' 'nicht fett im Listenkopf
Ein ganzer kursiver Absatz mit Betonung.
' 'nur einmal
code')
run = styled(body, convert=convert)
text = run.chapter("001")
assert "Ein *kursives* und **fettes** Wort, unterstrichen, ~~gestrichen~~, x2, sichtbar," in text
assert "`printf` und zwei Wörter, **inline**, [example.org](https://example.org)." in text
assert "[»]" not in text and "\\[»\\]" not in text
assert "- nicht fett im Listenkopf" in text
assert "*Ein ganzer kursiver Absatz mit Betonung.*" in text
assert "## Überschrift bleibt" in text and "*nur einmal*" in text and "**nur einmal**" not in text
assert "```\ncode\n```" in text
assert run.report["css"]["hidden_elements"] == 1
assert run.report["css"]["applied"]["italic"] >= 2
plain = styled(body, "--no-css-emphasis", convert=convert).chapter("001")
assert "Ein kursives und fettes Wort" in plain
def test_p1_css_emphasis_inside_html_tables(convert):
body = ('| kursiv und fett | |
| a | b |
Fläche (A=r2×π) und ' 'xy sowie ab und c d.
') text = styled(body, convert=convert).chapter("001") assert "2*×π*" in text assert "*xy*" in text and "**ab**" in text and "*c* *d*" in text def test_p4_scene_breaks(convert): body = ('
Erster Absatz.
' '
Neue Szene.
Weiter.
***
' 'Nach Ornament.
Text
⁂
Ende.
') text = convert(Book(docs=[Doc("c.xhtml", body)])).chapter("001") body_md = text.split("# K", 1)[1] assert "Erster Absatz.\n\n* * *\n\nNeue Szene." in body_md assert body_md.count("* * *") == 3 # two empties collapse into one; ***, ⁂ are ornaments; none before the heading assert "Weiter.\n\n* * *\n\nNach Ornament." in body_md assert "\\*" not in body_md assert body_md.strip().startswith("Erster Absatz.") # no break at chapter start def test_p4_poems_keep_lines_and_stanzas(convert): body = ('Davor.
»Erste Zeile
zweite Zeile
' '
Zweite Strophe«
Danach.
') text = convert(Book(docs=[Doc("c.xhtml", body)])).chapter("001") assert "> »Erste Zeile\\\n> zweite Zeile\n>\n> Zweite Strophe«" in text assert "* * *" not in text BOX_CSS = b""".rahmen { border: 1px solid #333; padding: 4px } .listing { border: 1px solid #ccc }""" def boxed(body: str, *args: str, convert=None): return convert(Book(docs=[Doc("c.xhtml", body)], media={"box.css": BOX_CSS}), *args) def test_p2_boxes_become_callouts(convert): body = ('Vorher.
' 'Kein Kompendium.
Zweiter Absatz.

Wichtig: Funktionen sind Objekte.
Tipp
Gelb mit Blau mischen.
Mehr Weiß.
' '' 'Achtung, heiß!
code()
Nachher.
') from conftest import PNG run = convert(Book(docs=[Doc("c.xhtml", body)], media={"box.css": BOX_CSS, "tick.png": PNG})) text = run.chapter("001") assert "> [!NOTE]\n> **Erwartungen**\n>\n> Kein Kompendium.\n>\n> Zweiter Absatz." in text assert "> [!IMPORTANT]\n> **Wichtig:** Funktionen sind Objekte." in text and "tick" not in text assert "> [!TIP]\n> Gelb mit Blau mischen.\n>\n> Mehr Weiß." in text # label 'Tipp' = type word, no title assert "> [!NOTE]\n> **Exkurs**\n>\n> Am Rande." in text assert "> [!WARNING]\n> Achtung, heiß!" in text # box recognized via CSS border, type from text assert "```\ncode()\n```" in text and "> ```" not in text # bordered code listing is no box assert "### " not in text # box heading no longer pollutes the outline assert run.report["layout"]["boxes"] == 5 def test_p2_box_modes(convert): body = 'Normal rot, markiert, ' 'groß, Kapitälchen, Zierschrift, ' 'English words und deutsch.
' 'Zweiter Absatz.
Dritter Absatz.
Widmung
') def test_p3_semantic_styles_default(convert): text = styles_book(BODY_STYLES, convert=convert).chapter("001") assert "Normal rot, markiert, groß, Kapitälchen, Zierschrift, English words und deutsch." in text assert "style=" not in text and "lang=" not in text def test_p3_p7_html_styles(convert): run = styles_book(BODY_STYLES, "--styles", "html", convert=convert) text = run.chapter("001") assert 'rot' in text assert 'markiert' in text assert 'groß' in text assert 'Kapitälchen' in text assert "Zierschrift" in text assert 'English words und deutsch.' in text assert 'Ende Seite 89.
' '' 'Absatz mit Absatz-ID.
x
code' '
| 1.2 | Tabellentitel |
Wichtiger Satz.
unterstrichenVERSTECKT.
' 'Immer testen.