Transformers¶
Conversion registry exposing high-level helpers for assets.
ConverterRegistry ¶
ConverterRegistry()
Registry storing converter strategies.
Source code in src/texsmith/adapters/transformers/__init__.py
23 24 | |
convert ¶
convert(
name: str,
source: Path | str,
*,
output_dir: Path,
**options: Any,
) -> Any
Execute a converter strategy with the provided arguments.
Source code in src/texsmith/adapters/transformers/__init__.py
41 42 43 44 45 46 47 48 49 50 51 | |
get ¶
get(name: str) -> ConverterStrategy
Return a registered converter strategy or raise an execution error.
Source code in src/texsmith/adapters/transformers/__init__.py
30 31 32 33 34 35 | |
is_registered ¶
is_registered(name: str) -> bool
Return True when a converter has been registered under the given name.
Source code in src/texsmith/adapters/transformers/__init__.py
37 38 39 | |
register ¶
register(name: str, strategy: ConverterStrategy) -> None
Register a converter strategy under a unique name.
Source code in src/texsmith/adapters/transformers/__init__.py
26 27 28 | |
ConverterStrategy ¶
Bases: Protocol
Protocol implemented by concrete converter strategies.
DrawioStrategy ¶
DrawioStrategy(
image: str = "rlespinasse/drawio-desktop-headless",
)
Bases: CachedConversionStrategy
Convert draw.io diagrams using selectable backends (playwright, local, docker).
format (default pdf) is draw.io's own --format: the PDF a
document embeds, the png a Typst document takes, the svg a web
page shows. It is the suffix of the target too — nothing else in the code
path depends on it, because all three backends take the format as a flag
and the CLI and the container take the very same one.
crop (default True) trims the export to the drawing itself. Setting
it to False exports the page(s) the drawing sits on instead — draw.io's
Size: Page Size — so the canvas margins the author laid out survive into
the document. All three backends honour it identically.
Source code in src/texsmith/adapters/transformers/strategies.py
1177 1178 1179 1180 1181 1182 1183 | |
MermaidToPdfStrategy ¶
MermaidToPdfStrategy(
image: str = "minlag/mermaid-cli",
*,
default_theme: str = "neutral",
)
Bases: CachedConversionStrategy
Render Mermaid diagrams to PDF using the official CLI image.
Source code in src/texsmith/adapters/transformers/strategies.py
884 885 886 887 888 889 890 891 892 | |
drawio_export ¶
drawio_export(
source: Path | str, output_dir: Path, **options: Any
) -> Path
Export a draw.io diagram in the format asked of it (pdf by default).
Source code in src/texsmith/adapters/transformers/__init__.py
84 85 86 | |
fetch_image ¶
fetch_image(
url: str, output_dir: Path, **options: Any
) -> Path
Fetch a remote image and normalise it to PDF.
Source code in src/texsmith/adapters/transformers/__init__.py
94 95 96 | |
has_converter ¶
has_converter(name: str) -> bool
Return True when a converter strategy is currently registered.
Source code in src/texsmith/adapters/transformers/__init__.py
69 70 71 | |
image2pdf ¶
image2pdf(
source: Path | str, output_dir: Path, **options: Any
) -> Path
Convert bitmap images to PDF.
Source code in src/texsmith/adapters/transformers/__init__.py
79 80 81 | |
mermaid2pdf ¶
mermaid2pdf(
source: Path | str, output_dir: Path, **options: Any
) -> Path
Convert Mermaid diagrams to PDF.
Source code in src/texsmith/adapters/transformers/__init__.py
89 90 91 | |
register_converter ¶
register_converter(
name: str, strategy: ConverterStrategy
) -> None
Expose a helper to register external strategies.
Source code in src/texsmith/adapters/transformers/__init__.py
64 65 66 | |
svg2pdf ¶
svg2pdf(
source: Path | str, output_dir: Path, **options: Any
) -> Path
Convert SVG assets to PDF.
Source code in src/texsmith/adapters/transformers/__init__.py
74 75 76 | |
Primitives used by asset converter strategies.
CachedConversionStrategy ¶
CachedConversionStrategy(
namespace: str,
*,
max_attempts: int = 3,
backoff: Callable[[int], float] | None = None,
)
Base class that adds caching and retry/backoff policies.
Source code in src/texsmith/adapters/transformers/base.py
38 39 40 41 42 43 44 45 46 47 | |
output_suffix ¶
output_suffix(source: Any, options: dict[str, Any]) -> str
Allow subclasses to customise the output suffix.
Source code in src/texsmith/adapters/transformers/base.py
110 111 112 | |
ConverterStrategy ¶
Bases: Protocol
Protocol implemented by concrete converter strategies.
exponential_backoff ¶
exponential_backoff(
base_delay: float = 0.5,
factor: float = 2.0,
max_delay: float = 5.0,
) -> Callable[[int], float]
Return a simple exponential backoff policy.
Source code in src/texsmith/adapters/transformers/base.py
21 22 23 24 25 26 27 28 29 30 | |
Concrete converter strategies with caching and error handling.
DrawioStrategy ¶
DrawioStrategy(
image: str = "rlespinasse/drawio-desktop-headless",
)
Bases: CachedConversionStrategy
Convert draw.io diagrams using selectable backends (playwright, local, docker).
format (default pdf) is draw.io's own --format: the PDF a
document embeds, the png a Typst document takes, the svg a web
page shows. It is the suffix of the target too — nothing else in the code
path depends on it, because all three backends take the format as a flag
and the CLI and the container take the very same one.
crop (default True) trims the export to the drawing itself. Setting
it to False exports the page(s) the drawing sits on instead — draw.io's
Size: Page Size — so the canvas margins the author laid out survive into
the document. All three backends honour it identically.
Source code in src/texsmith/adapters/transformers/strategies.py
1177 1178 1179 1180 1181 1182 1183 | |
FetchImageStrategy ¶
FetchImageStrategy(timeout: float = 10.0)
Bases: CachedConversionStrategy
Fetch a remote image, normalise it to PDF, and cache the result.
Source code in src/texsmith/adapters/transformers/strategies.py
413 414 415 | |
ImageToPdfStrategy ¶
ImageToPdfStrategy()
Bases: CachedConversionStrategy
Convert bitmap images to PDF using Pillow.
Source code in src/texsmith/adapters/transformers/strategies.py
362 363 | |
MermaidToPdfStrategy ¶
MermaidToPdfStrategy(
image: str = "minlag/mermaid-cli",
*,
default_theme: str = "neutral",
)
Bases: CachedConversionStrategy
Render Mermaid diagrams to PDF using the official CLI image.
Source code in src/texsmith/adapters/transformers/strategies.py
884 885 886 887 888 889 890 891 892 | |
SvgToPdfStrategy ¶
SvgToPdfStrategy()
Bases: CachedConversionStrategy
Convert inline SVG payloads or files to PDF using CairoSVG.
Source code in src/texsmith/adapters/transformers/strategies.py
270 271 | |
drawio_format ¶
drawio_format(value: Any) -> str
The export format of a draw.io conversion, pdf when it is unnamed.
Source code in src/texsmith/adapters/transformers/strategies.py
112 113 114 115 | |
drawio_suffix ¶
drawio_suffix(value: Any) -> str
The suffix a draw.io export lands under: its format, and nothing else.
Source code in src/texsmith/adapters/transformers/strategies.py
118 119 120 | |
option_flag ¶
option_flag(value: Any, *, default: bool = False) -> bool
Read a boolean option that may reach us as a string from a document attribute.
Source code in src/texsmith/adapters/transformers/strategies.py
102 103 104 105 | |
Utility helpers shared across transformer strategies.
normalise_pdf_version ¶
normalise_pdf_version(
pdf_path: Path, *, target_version: str = "1.5"
) -> None
Re-write a PDF so its header advertises the requested version.
Source code in src/texsmith/adapters/transformers/utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
points_to_mm ¶
points_to_mm(points: float) -> float
Convert PDF points to millimetres.
Source code in src/texsmith/adapters/transformers/utils.py
10 11 12 | |