Plugin API¶
Plugins bundle the build-time helpers an IR pass drives — the snippet compiler's nested build, the MkDocs site-side HTML rewriting — so you can extend TeXSmith without patching the core parse → IR → write pipeline.
texsmith.plugins exposes a namespace package populated by the MkDocs hook in
docs/hooks/mkdocs_hooks.py, re-exporting the maintained plugin modules under
texsmith.adapters.plugins.
Loading plugins¶
import texsmith.plugins.snippet # noqa: F401
from texsmith import Document, convert_documents
bundle = convert_documents([Document.from_markdown(Path("intro.md"))])
Authoring your own plugin¶
- Create a module (e.g.,
texsmith.plugins.acme) exposing the build-time helpers your documents need, and an IR pass that calls them. - Declare entry points or instruct consumers to
import texsmith.plugins.acmebefore rendering. - Optionally provide a MkDocs plugin/hook so documentation builds load your plugin automatically.
Keep plugin modules small and focused.
Reference¶
Compatibility layer exposing plugin integrations to documentation.
TeXSmith consolidated its plugin utilities under
texsmith.adapters.plugins. mkdocstrings still references the historical
texsmith.plugins namespace, so we re-export the maintained modules here to
keep the public import path available.
Plugin rendering fenced snippet blocks into standalone PDF assets.
SnippetAssets
dataclass
¶
SnippetAssets(pdf: Path, png: Path)
The rendered pair of a snippet: the PDF (LaTeX) and its PNG preview (web, Typst).
SnippetBlock
dataclass
¶
SnippetBlock(
content: str | None,
front_matter: dict[str, Any],
sources: list[Path],
layout: tuple[int, int] | None,
preview_dogear: bool,
template_id: str | None,
cwd: Path | None,
caption: str | None,
label: str | None,
figure_width: str | None,
template_overrides: dict[str, Any],
digest: str,
bibliography_files: list[Path],
promote_title: bool,
drop_title: bool,
suppress_title_metadata: bool,
)
Parsed representation of a snippet fence.
asset_filename ¶
asset_filename(digest: str, suffix: str) -> str
Return the deterministic filename for a snippet artefact.
Source code in src/texsmith/adapters/plugins/snippet.py
418 419 420 | |
build_snippet_block ¶
build_snippet_block(
raw_content: str,
*,
language: str | None,
attributes: Mapping[str, Any] | None = None,
meta: Mapping[str, str] | None = None,
host_path: Path | None = None,
) -> SnippetBlock | None
Parse a snippet fence into a :class:SnippetBlock; the pure half of the fence handling.
raw_content is the fence body, language its info-string language,
attributes the :data:FENCE_ATTRIBUTES the host element carried
(caption, label, width, layout, config) and meta
the parsed data-meta tokens of the HTML reader. The HTML path
(:func:_extract_snippet_block) and the tmark snippet pass both end
here. None when the fence has neither inline content nor sources.
The body is taken without its trailing newlines, so that the readers
agree on one text and therefore on one digest: the IR gives a fence body
that stops at the closing fence, while the HTML of the same fence ends
with the newline the renderer put before </code>, and a file spliced
into a fence by include= ends with its own.
Source code in src/texsmith/adapters/plugins/snippet.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
ensure_snippet_assets ¶
ensure_snippet_assets(
block: SnippetBlock,
*,
output_dir: Path,
source_path: Path | str | None = None,
emitter: DiagnosticEmitter | None = None,
) -> SnippetAssets
Render snippet assets into the provided directory when missing.
Source code in src/texsmith/adapters/plugins/snippet.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 | |
rewrite_html_snippets ¶
rewrite_html_snippets(
html: str,
resolver: Callable[[SnippetBlock], tuple[str, str]],
*,
source_path: Path | str | None = None,
) -> str
Replace snippet fences in an HTML fragment with linked previews.
Source code in src/texsmith/adapters/plugins/snippet.py
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 | |