1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! Typeset books from Rust with [Postext](https://postext.dev/): a
//! print-ready PDF, HTML pages, an EPUB, page images, a Word document or an
//! InDesign package from a `.postext` book, a book folder or loose Markdown
//! files.
//!
//! ```no_run
//! let report = postext::pdf("book.postext").out("book.pdf").set("page.dpi", 300).run()?;
//! println!("{} pages", report.output().and_then(|o| o.pages).unwrap_or(0));
//! for warning in &report.warnings {
//! eprintln!("{warning}"); // warning missingFont (chapters/02.md:14): …
//! }
//!
//! let pdf: Vec<u8> = postext::pdf(std::fs::read("book.postext")?).bytes()?; // bytes in, bytes out
//! # Ok::<_, Box<dyn std::error::Error>>(())
//! ```
//!
//! The crate drives the self-contained `postext` command line, the same
//! executable as `brew install drnachio/postext/postext`, `npx postext-cli`
//! or `pip install postext`: the layout is the Sandbox's, and the same book
//! breaks into the same pages. The executable of your system (185 to 230 MB,
//! too large for a crate) is downloaded on first use from the GitHub Release
//! of the crate's version, checked against the release's `SHA256SUMS` and
//! kept in the cache (see [`find_binary`]). Nothing is downloaded at build
//! time.
//!
//! | Environment variable | Effect |
//! | --- | --- |
//! | `POSTEXT_BIN` | Run this executable instead (Homebrew, Scoop, a local build); nothing is downloaded |
//! | `POSTEXT_CACHE_DIR` | Cache folder (default `~/.cache/postext`, `%LOCALAPPDATA%\postext\cache` on Windows) |
//! | `POSTEXT_RELEASE_URL` | Download from a mirror: a URL with `{version}` where the release's files are |
//!
//! # Commands
//!
//! Every command of the command line is a builder, made by a function of
//! the same name ([`pdf`], [`html`], [`epub`], [`image`], [`images`],
//! [`docx`], [`idml`], [`pack`], [`unpack`], [`design`], [`info`],
//! [`check`], [`build`], [`import_docx`], [`import_idml`]). Its options are
//! methods; [`Command::run`] runs it with `--json` and returns its report,
//! [`Command::bytes`] returns the file instead.
//!
//! A book is a path (a `.postext` file, a book folder, a Markdown file), a
//! list of Markdown files (the chapters, in order), or the bytes of a
//! `.postext` bundle. The commands that read a book take the book options:
//!
//! ```no_run
//! use serde_json::json;
//!
//! postext::pdf(["01.md", "02.md"])
//! .out("notes.pdf")
//! .name("Notes") // --name
//! .config_json(&json!({"page": {"sizePreset": "A5"}})) // --config (or .config("config.json"))
//! .set("bodyText.fontSize.value", 11) // --set, one per key
//! .locale("es") // --locale
//! .chapters(1..=2) // --chapters 1-2 (also 3, "1,3-5", [1, 3])
//! .resources("img/") // --resources
//! .fonts("fonts/") // --fonts
//! .font_dir("/Library/Fonts") // --font-dir
//! .offline(true) // --offline: never download fonts
//! .design("novel.postext") // --design: a design file (a path or bytes), or another book
//! .design_parts(["page", "text"]) // --design-parts page,text
//! .composition("auto") // --composition
//! .run()?;
//! # Ok::<_, postext::Error>(())
//! ```
//!
//! # Errors
//!
//! A failed run is an [`Error`]: [`Error::Failed`] (exit code 1),
//! [`Error::Usage`] (a wrong option or value, exit code 2),
//! [`Error::ProblemsFound`] (`check` found an error, or `import_docx` could
//! not apply an edit, exit code 3; `allow_problems()` returns the report
//! instead), [`Error::BinaryNotFound`] (no executable for this system, a
//! failed download or checksum, a `POSTEXT_BIN` that is not a file). The
//! report and stderr of a failed run are in [`Error::report`] and
//! [`Failure::stderr`].
//!
//! # One executable, many runs
//!
//! A [`Postext`] client has the same methods with its own executable,
//! folder, environment and timeout. [`Postext::run_inherit`] runs any
//! command as typed, `build … --watch` included. Each call starts the
//! executable again.
//!
//! # Features
//!
//! - `download` (default): download the executable on first use. Without
//! it, the crate runs `POSTEXT_BIN` or an executable already in the cache.
use OsStr;
use Display;
use OnceLock;
pub use ;
pub use Download;
pub use ;
pub use Postext;
pub use ;
pub use kind;
pub use ;
pub use ;
/// The client the functions at the crate's root use.
)*};
}
root!