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 +59 -0
- inkmd/__main__.py +4 -0
- inkmd/_kerning_data.py +4659 -0
- inkmd/ast.py +172 -0
- inkmd/cli.py +75 -0
- inkmd/fonts.py +461 -0
- inkmd/layout.py +844 -0
- inkmd/parser.py +1727 -0
- inkmd/pdf.py +557 -0
- inkmd/render.py +800 -0
- inkmd-0.1.0.dist-info/METADATA +293 -0
- inkmd-0.1.0.dist-info/RECORD +16 -0
- inkmd-0.1.0.dist-info/WHEEL +5 -0
- inkmd-0.1.0.dist-info/entry_points.txt +2 -0
- inkmd-0.1.0.dist-info/licenses/LICENSE +21 -0
- inkmd-0.1.0.dist-info/top_level.txt +1 -0
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