Textdiagramme, Ausgabeblöcke und GDScript-Hervorhebung
Stilregel: Strukturdiagramme als diagramm-Block mit Kästen und Pfeilen, Ausgabe des Testlaufs unter jedem Beispiel; Prüfer prüft beides. Frontend: eigene GDScript-Grammatik, gdshader über GLSL, Diagrammblock ohne Umbruch. PDF: Diagramme als pre ohne Umbruch, gdshader über GLSL. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -119,6 +119,7 @@ p{margin:0 0 2.2mm;orphans:2;widows:2}
|
||||
code{font-family:"DejaVu Sans Mono",monospace;font-size:7.9pt;hyphens:none}
|
||||
.codehilite,pre{background:#f5f5f2!important;border:0.4pt solid #ccc;padding:2mm;margin:2mm 0 3mm;border-radius:1mm}
|
||||
pre{white-space:pre-wrap;word-wrap:break-word;font-size:7.3pt;line-height:1.3;margin:0;border:none;padding:0}
|
||||
pre.diagramm{white-space:pre;font-size:6.8pt;line-height:1.15;page-break-inside:avoid;width:max-content;max-width:100%;margin:2mm auto 3mm;padding:2mm;border:0.4pt solid #ccc;border-radius:1mm;background:#f5f5f2}
|
||||
table{border-collapse:collapse;font-size:8pt;margin:3mm 0;width:100%}
|
||||
td,th{border:0.4pt solid #888;padding:1.2mm;vertical-align:top;text-align:left}
|
||||
ul,ol{padding-left:5mm} li{margin-bottom:1.2mm}
|
||||
@@ -133,6 +134,15 @@ a{color:black}
|
||||
"""
|
||||
|
||||
|
||||
DIAGRAMM_RE = re.compile(r"^```diagramm[ \t]*\n(.*?)^```[ \t]*$", re.S | re.M)
|
||||
|
||||
|
||||
def _vorbereiten(text: str) -> str:
|
||||
"""Textdiagramme als unformatierte <pre> durchreichen; gdshader mit dem GLSL-Lexer hervorheben."""
|
||||
text = DIAGRAMM_RE.sub(lambda m: '<pre class="diagramm">' + html.escape(m.group(1).rstrip("\n")) + "</pre>", text)
|
||||
return re.sub(r"^```gdshader[ \t]*$", "```glsl", text, flags=re.M)
|
||||
|
||||
|
||||
def pdf(name: str) -> bool:
|
||||
exe = shutil.which("weasyprint")
|
||||
if not exe:
|
||||
@@ -160,7 +170,7 @@ def pdf(name: str) -> bool:
|
||||
aid = f"k{k['ord']}"
|
||||
t = f"Kapitel {k['ord']} – {k['titel']}"
|
||||
toc.append(f'<li class="tch"><a href="#{aid}">{html.escape(t)}</a></li>')
|
||||
h = md.convert(p.read_text()).replace("<h1>", f'<h1 id="{aid}" class="chap">', 1)
|
||||
h = md.convert(_vorbereiten(p.read_text())).replace("<h1>", f'<h1 id="{aid}" class="chap">', 1)
|
||||
h = h.replace("border: 1px solid #FF0000", "border: none")
|
||||
body.append(f'<section class="chapter">{h}</section>')
|
||||
md.reset()
|
||||
|
||||
Reference in New Issue
Block a user