fix: nur eingebundene Stylesheets auswerten (QA3-01)

Bisher wirkten alle CSS-Dateien des Manifests, auch mitgelieferte Layouts
anderer Buchreihen. Im C-Buch (21 CSS, nur main.css verlinkt) wurden fette
Buchstaben zu Inline-Code und Registerbuchstaben zu <mark>; eine fremde
display:none-Regel konnte Text löschen.

_load_stylesheet wertet jetzt nur per <link rel="stylesheet"> eingebundene
Stylesheets (transitiv inkl. @import) und <style>-Elemente aus; nicht
eingebundene meldet die Info css-unlinked.

Test-Builder: Doc.css, Testdokumente verlinken ihr CSS wie echte EPUBs
(QA3-02). Regressionstests in tests/test_styles.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-10-06 21:07:49 +02:00
commit 568844e8c4

View file

@ -211,3 +211,22 @@ def test_page_marker_in_box_title_goes_before_the_box(convert):
text = convert(Book(docs=[Doc("c.xhtml", body)]), "--page-markers", "visible").chapter("001")
assert "\\[S. 62\\]\n\n> [!NOTE]\n> **Wozu Deklarationen?**" in text
assert "> Weil es \\[S. 63\\]hilft." in text # markers in the box body stay in place
def test_qa3_01_unlinked_stylesheets_are_ignored(convert):
"""Publishers ship layout CSS of other series in the manifest; only linked stylesheets apply (QA3-01)."""
css = {"main.css": b".bold { font-weight: bold; }",
"fremd.css": b"p > span.bold { font-weight: normal; font-family: monospace; } .weg { display: none; }"}
body = ('<h1>K</h1><p>Die (<span class="bold">st</span>an<span class="bold">d</span>ard '
'<span class="bold">in</span>put) und <span class="weg">sichtbarer Text</span>.</p>')
text = convert(Book(docs=[Doc("c.xhtml", body, css=["main.css"])], media=css)).chapter("001")
assert "`" not in text # monospace rule of fremd.css must not turn bold into code
assert "**st**an**d**ard **in**put" in text
assert "sichtbarer Text" in text # display:none of fremd.css must not hide content
def test_qa3_01_imported_stylesheets_still_apply(convert):
css = {"main.css": b'@import url("extra.css");', "extra.css": b".k { font-style: italic; }"}
body = '<h1>K</h1><p><span class="k">kursiv</span> normal.</p>'
text = convert(Book(docs=[Doc("c.xhtml", body, css=["main.css"])], media=css)).chapter("001")
assert "*kursiv* normal." in text