"""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"

Kapitel 1.{ZW}1

Lese{SHY}rinnen und 1.{ZW}1 sowie{ZW}Wort.

" f"
a{ZW}b

x{SHY}y

") run = convert(Book(docs=[Doc("c.xhtml", body)])) text = run.chapter("001") assert "Leserinnen und 1.1 sowieWort." in text assert "# Kapitel 1.1" in text and 'chapter_title: "Kapitel 1.1"' in text assert f"a{ZW}b" in text and f"x{SHY}y" in text # code stays verbatim assert run.report["text_cleanup"]["invisible_chars_removed"] == 4 kept = convert(Book(docs=[Doc("c.xhtml", body)]), "--keep-invisible-chars").chapter("001") assert f"Lese{SHY}rinnen" in kept CSS = b""".i { font-style: italic } .b { font-weight: bold } span.u { text-decoration: underline } .s { text-decoration: line-through } .hoch { vertical-align: super } .weg { display: none } li p.first > span.b { font-weight: normal; font-family: monospace } .schrift-c { font-family: "Courier New", monospace } p.zitat { font-style: italic } h2.t { font-weight: bold; font-style: italic } .url { text-decoration: underline } @media amzn-kf8 { .i { font-style: normal } }""" def styled(body: str, *args: str, convert=None): return convert(Book(docs=[Doc("c.xhtml", body)], media={"style.css": CSS}), *args) def test_p1_css_classes_become_markdown_emphasis(convert): body = ('

K

Ein kursives und fettes Wort, ' 'unterstrichen, gestrichen, x2, ' '[»] sichtbar, printf und ' 'zwei Wörter, inline, ' 'example.org.

' '' '

Ein ganzer kursiver Absatz mit Betonung.

' '

Überschrift bleibt

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 = ('

T

' '
kursiv und fett
ab
') text = styled(body, convert=convert).chapter("001") assert "kursiv und fett" in text def test_adjacent_emphasis_is_merged(convert): body = ('

K

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