"""The block list must count and read exactly like the web reader (static/js/app/44-books.js, 40-epub.js sanitizeEpubHtml): anchors are block indexes shared between all clients. The real-book comparison against the web reader's own code is tools/parity/.""" from diora_tui.blocks import anchor_is_further, format_anchor, load_flat_book, parse_anchor def texts(book): return [(b.tag, b.text) for b in book.blocks] def test_block_selector_and_nesting(epub): book = load_flat_book(epub([ "
Eins
Zitat
Behälter
a
", "b
"])) assert [b.chapter_index for b in book.blocks] == [0, 1] def test_comments_are_not_text(epub): book = load_flat_book(epub(['xy
'])) assert texts(book) == [("h1", "Titel"), ("p", "xy")] def test_whitespace_is_javascripts(epub): # \s in JS: no-break space and BOM collapse like spaces; \x85 does not book = load_flat_book(epub(["a bc
\x85
"])) assert texts(book)[0] == ("p", "a b c") assert texts(book)[1][1] == "\x85" def test_footnote_marker_adds_no_space(epub): book = load_flat_book(epub(['Satz.1Weiter
Fußnote
'])) assert book.blocks[0].text == "Satz.1Weiter" assert book.blocks[0].footnotes[0].marker == "1" assert book.footnote_targets["n1"] == 1 def test_anchor_format_and_order(): assert format_anchor(12, 0.5) == "12:0.500000" assert parse_anchor("12:0.500000") == (12, 0.5) assert parse_anchor("kaputt") is None assert anchor_is_further("5:0.1", "4:0.9") assert anchor_is_further("5:0.5", "5:0.4") assert not anchor_is_further("4:0.9", "5:0.1")