feat: Farben, Schriften, Größen und Sprache per --styles (P3, P7)
--styles semantic (Standard): Hintergrundmarkierung wird zu <mark>, sonst nur bedeutungstragende Gestaltung. --styles html: Farbe, Hintergrund, Schriftgröße/-art, Kapitälchen und Ausrichtung bleiben als <span style>/<div style> erhalten, fremdsprachige Passagen als <span lang>. Übernommen wird nur, was vom Grundstil abweicht (häufigste Werte aller Absätze, Schriftgröße ab ±15 %); Formel- und Bildabsätze bekommen keine Ausrichtung; unsichere Werte werden verworfen. Gilt im Fließtext, für Absätze und in HTML-Tabellen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4992672ca6
commit
5cef9d7885
1 changed files with 227 additions and 8 deletions
|
|
@ -127,3 +127,38 @@ def test_p2_box_modes(convert):
|
|||
assert '<div class="box box-tip">\n\n**Hinweis zum Pinsel**\n\nSauber halten.\n\n</div>' in htm
|
||||
plain = boxed(body, "--boxes", "plain", convert=convert).chapter("001")
|
||||
assert "## Hinweis zum Pinsel" in plain and "Sauber halten." in plain and ">" not in plain.split("---")[-1]
|
||||
|
||||
|
||||
STYLE_CSS = b"""p { font-family: "Aldus", serif; font-size: 0.9em; color: #000 }
|
||||
.rot { color: #942f6a } .gelb { background-color: #ffff00 } .gross { font-size: 1.5em }
|
||||
.kap { font-variant: small-caps } p.mitte { text-align: center } .script { font-family: "Mulled Wine", cursive }"""
|
||||
|
||||
|
||||
def styles_book(body: str, *args: str, convert=None):
|
||||
return convert(Book(docs=[Doc("c.xhtml", body)], media={"s.css": STYLE_CSS}), *args)
|
||||
|
||||
|
||||
BODY_STYLES = ('<h1>S</h1><p>Normal <span class="rot">rot</span>, <span class="gelb">markiert</span>, '
|
||||
'<span class="gross">groß</span>, <span class="kap">Kapitälchen</span>, <span class="script">Zierschrift</span>, '
|
||||
'<span lang="en">English words</span> und <span lang="de">deutsch</span>.</p>'
|
||||
'<p>Zweiter Absatz.</p><p>Dritter Absatz.</p><p class="mitte">Widmung</p>')
|
||||
|
||||
|
||||
def test_p3_semantic_styles_default(convert):
|
||||
text = styles_book(BODY_STYLES, convert=convert).chapter("001")
|
||||
assert "Normal rot, <mark>markiert</mark>, 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 '<span style="color: #942f6a">rot</span>' in text
|
||||
assert '<span style="background-color: #ffff00">markiert</span>' in text
|
||||
assert '<span style="font-size: 1.5em">groß</span>' in text
|
||||
assert '<span style="font-variant: small-caps">Kapitälchen</span>' in text
|
||||
assert "<span style=\"font-family: 'Mulled Wine', cursive\">Zierschrift</span>" in text
|
||||
assert '<span lang="en">English words</span> und deutsch.' in text
|
||||
assert '<div style="text-align: center">\n\nWidmung\n\n</div>' in text
|
||||
assert "Zweiter Absatz." in text and "Aldus" not in text # base paragraph style is not repeated
|
||||
assert run.report["css"]["applied"]["style"] >= 5
|
||||
|
|
|
|||
Loading…
Reference in a new issue