inkmd 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
inkmd/__init__.py ADDED
@@ -0,0 +1,59 @@
1
+ """inkmd — pure-Python markdown to PDF compiler.
2
+
3
+ Public API:
4
+
5
+ inkmd.compile(md_text: str, page_size: str = "letter", family: str = "helvetica") -> bytes
6
+ Parse markdown into PDF bytes.
7
+
8
+ inkmd.render_file(in_path, out_path, page_size: str = "letter", family: str = "helvetica") -> None
9
+ Read a markdown file, write a PDF file.
10
+
11
+ Font family choices: 'helvetica' (default, sans-serif) or 'times' (serif).
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from pathlib import Path
17
+
18
+ from inkmd.parser import parse
19
+ from inkmd.pdf import styled_pdf
20
+ from inkmd.render import FAMILIES, render_document
21
+
22
+
23
+ __version__ = "0.1.0"
24
+
25
+
26
+ def compile(
27
+ md_text: str,
28
+ page_size: str = "letter",
29
+ family: str = "helvetica",
30
+ *,
31
+ autolinks: bool = True,
32
+ ) -> bytes:
33
+ """Compile markdown text into PDF bytes.
34
+
35
+ ``autolinks`` controls GFM-style detection of bare URLs and email
36
+ addresses (default True). Set False for strict CommonMark — bare
37
+ URLs render as plain text and only `<url>` / `[text](url)` produce
38
+ links.
39
+ """
40
+ if family not in FAMILIES:
41
+ raise ValueError(f"unknown family {family!r}; available: {tuple(FAMILIES)}")
42
+ doc = parse(md_text, autolinks=autolinks)
43
+ paragraphs = render_document(doc, family=FAMILIES[family])
44
+ return styled_pdf(paragraphs, page_size=page_size)
45
+
46
+
47
+ def render_file(
48
+ in_path: str | Path,
49
+ out_path: str | Path,
50
+ page_size: str = "letter",
51
+ family: str = "helvetica",
52
+ *,
53
+ autolinks: bool = True,
54
+ ) -> None:
55
+ """Read markdown from ``in_path``; write PDF to ``out_path``."""
56
+ md = Path(in_path).read_text(encoding="utf-8")
57
+ Path(out_path).write_bytes(
58
+ compile(md, page_size=page_size, family=family, autolinks=autolinks)
59
+ )
inkmd/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from inkmd.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())