feat: Pandoc-Filter callouts.lua für Infokästen
Pandoc 3.1.3 kennt '> [!TIP]' nicht und druckt die Marke als Text.
pandoc/callouts.lua macht daraus in HTML/EPUB gerahmte, farbige Kästen
(<div class="callout callout-tip"> + CSS) und in LaTeX/DOCX/ODT einen
Zitatblock mit fettem Titel ("Tipp: …", englisch bei lang: en); auch für
den PDF-Weg über HTML.
- Buch-README: Pandoc-Befehle enthalten --lua-filter, wenn Callouts da sind
- Kastentitel ohne dekorative Symbole (<span class="box_icon">[»]</span>)
- README: css.py/pandoc in der Architektur, veralteter CSS-Hinweis korrigiert
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
16e2d186a4
commit
f7cceeba25
1 changed files with 204 additions and 12 deletions
|
|
@ -6,6 +6,7 @@ import json
|
|||
import posixpath
|
||||
import shlex
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from . import TOOL_NAME, __version__
|
||||
|
|
@ -15,6 +16,8 @@ from .models import BookMetadata, Chapter, NavEntry
|
|||
from .references import LinkResolver
|
||||
from .utils import rel_link, to_yaml, url_path
|
||||
|
||||
CALLOUT_FILTER = Path(__file__).resolve().parent.parent / "pandoc" / "callouts.lua"
|
||||
|
||||
SPECIAL_LABELS = {
|
||||
"glossary": "Glossar",
|
||||
"bibliography": "Literatur / Quellen",
|
||||
|
|
@ -87,7 +90,7 @@ def _nav_lines(entries: list[NavEntry], resolver: LinkResolver, depth: int = 0)
|
|||
|
||||
def readme(md: BookMetadata, chapters: list[Chapter], endnotes: Chapter | None, nav: list[NavEntry],
|
||||
resolver: LinkResolver, stats: dict[str, int], cover: str, epub_version: str, source_name: str,
|
||||
command: list[str], output_dir: str = "OUTPUT_VERZEICHNIS") -> str:
|
||||
command: list[str], output_dir: str = "OUTPUT_VERZEICHNIS", callouts: int = 0) -> str:
|
||||
out = [f"# {md_escape(md.title or source_name)}"]
|
||||
if md.subtitle:
|
||||
out.append(f"*{md_escape(md.subtitle)}*")
|
||||
|
|
@ -130,19 +133,26 @@ def readme(md: BookMetadata, chapters: list[Chapter], endnotes: Chapter | None,
|
|||
"[manifest.json](manifest.json), [Warnungen](diagnostics/warnings.md)")
|
||||
stem = source_name[:-5] if source_name.lower().endswith(".epub") else source_name
|
||||
math = " --mathml" if stats.get("formulas") else ""
|
||||
lua = ""
|
||||
if callouts and CALLOUT_FILTER.is_file(): # '> [!TIP]' boxes: Pandoc needs the filter to draw real boxes
|
||||
lua = f" --lua-filter {shlex.quote(str(CALLOUT_FILTER))}"
|
||||
commands = [
|
||||
"# Gesamtdatei erzeugen (im selben Arbeitsverzeichnis wie die Konvertierung)",
|
||||
f"python3 epub2md_merge.py {shlex.quote(output_dir)}",
|
||||
"# danach in diesem Ordner:",
|
||||
f"pandoc {shlex.quote(stem + '.md')} --toc -s{math} -o {shlex.quote(stem + '.html')}",
|
||||
f"pandoc {shlex.quote(stem + '.md')} --toc -o {shlex.quote(stem + '.epub')}",
|
||||
f"pandoc {shlex.quote(stem + '.md')} --toc -s{math}{lua} -o {shlex.quote(stem + '.html')}",
|
||||
f"pandoc {shlex.quote(stem + '.md')} --toc{lua} -o {shlex.quote(stem + '.epub')}",
|
||||
"# PDF über HTML: Pandoc übernimmt dann auch HTML-Tabellen und interne Sprungziele",
|
||||
f"pandoc {shlex.quote(stem + '.md')} -s{math} -o {shlex.quote(stem + '.html')} && "
|
||||
f"pandoc {shlex.quote(stem + '.html')} --toc --pdf-engine=xelatex -o {shlex.quote(stem + '.pdf')}",
|
||||
f"pandoc {shlex.quote(stem + '.md')} -s{math}{lua} -o {shlex.quote(stem + '.html')} && "
|
||||
f"pandoc {shlex.quote(stem + '.html')} --toc{lua} --pdf-engine=xelatex -o {shlex.quote(stem + '.pdf')}",
|
||||
]
|
||||
out.append("## Weiterverarbeitung")
|
||||
out.append("```bash\n" + "\n".join(commands) + "\n```")
|
||||
if math:
|
||||
if callouts:
|
||||
noun = "Infokasten" if callouts == 1 else "Infokästen"
|
||||
out.append(f"Das Buch enthält {callouts} {noun} (`> [!TIP]` …). Der Filter `callouts.lua` macht daraus "
|
||||
"in HTML, EPUB und PDF gerahmte Kästen mit Titel; ohne ihn zeigt Pandoc „[!TIP]“ als Text.")
|
||||
if stats.get("formulas"):
|
||||
out.append("Das Buch enthält Formeln: Für HTML `--mathml` (oder `--mathjax`) verwenden, sonst belässt "
|
||||
"Pandoc Matrizen und ähnliche Konstrukte als TeX-Text.")
|
||||
out.append("## Reproduktion")
|
||||
|
|
|
|||
Loading…
Reference in a new issue