@threepenny/md2pdf 2.3.0 → 2.4.0
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.
- package/README.md +13 -9
- package/bin/md2pdf.js +71 -8
- package/lib/math.js +15 -8
- package/lib/render.js +24 -3
- package/package.json +2 -2
- package/styles/academic.css +18 -1
- package/styles/classic.css +18 -1
- package/styles/cyberpunk.css +16 -0
- package/styles/elvish.css +16 -0
- package/styles/github.css +30 -0
- package/styles/gothic.css +34 -5
- package/styles/modern.css +18 -1
- package/styles/print/academic.css +9 -0
- package/styles/print/classic.css +9 -0
- package/styles/print/cyberpunk.css +9 -0
- package/styles/print/elvish.css +9 -0
- package/styles/print/github.css +9 -0
- package/styles/print/gothic.css +9 -0
- package/styles/print/modern.css +9 -0
- package/styles/print/report.css +9 -0
- package/styles/print/resume.css +9 -0
- package/styles/print/sandwake.css +9 -0
- package/styles/print/worksheet.css +9 -0
- package/styles/report.css +18 -1
- package/styles/resume.css +18 -1
- package/styles/sandwake.css +18 -2
- package/styles/worksheet.css +18 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Supports GitHub-flavored Markdown: tables, task lists, footnotes, emoji shortcod
|
|
|
10
10
|
|
|
11
11
|
# Command-line tool (macOS)
|
|
12
12
|
|
|
13
|
-
Markdown is rendered to HTML with [markdown-it](https://github.com/markdown-it/markdown-it) and printed to PDF by headless Chrome.
|
|
13
|
+
Markdown is rendered to HTML with [markdown-it](https://github.com/markdown-it/markdown-it) and printed to PDF by headless Chrome. Formulas (`$…$`, `$$…$$`, `\(…\)`, `\[…\]`, and environments such as `\begin{aligned}…\end{aligned}` or `\begin{align*}…\end{align*}` that start a block) are drawn with [KaTeX](https://katex.org), as on md2pdf.me; the HTML that `--html` writes also carries MathML for screen readers, which the PDF doesn't. Prices such as $5 and $10 stay text, even beside a formula.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ This installs:
|
|
|
26
26
|
- **Convert to PDF** Quick Action — right-click any `.md` file in Finder → **Quick Actions → Convert to PDF**
|
|
27
27
|
- **⌃⌥⌘P** keyboard shortcut — select `.md` files in Finder and press it
|
|
28
28
|
|
|
29
|
-
Re-run `install.sh` if you move this folder
|
|
29
|
+
Re-run `install.sh` if you move this folder, remove the Node version it was installed with, or pull a version that adds a dependency (md2pdf says so when KaTeX, which draws formulas, is missing). `./uninstall.sh` removes all of it.
|
|
30
30
|
|
|
31
31
|
To use a different shortcut, pass it when installing (`@` ⌘, `~` ⌥, `^` ⌃, `$` ⇧), or set it to empty to skip:
|
|
32
32
|
|
|
@@ -63,7 +63,7 @@ From Finder, a single file opens in Preview when done; multiple files show a not
|
|
|
63
63
|
| `report` | Business or technical report: title block from the first heading, running header with the title, "Page N of M" footers, gridded tables |
|
|
64
64
|
| `resume` | Compact and one-page friendly: the first heading is your name, the paragraph after it your contact line, `##` headings are ruled section dividers |
|
|
65
65
|
| `worksheet` | For worksheets, stories and class handouts: Andika body text and rounded Fredoka headings (both bundled), larger type, bright headings that change color each section, outlined rounded boxes and big tick boxes for task lists |
|
|
66
|
-
| `gothic` | An old book of dread: blackletter Grenze Gotisch headings and IM Fell English body text (both bundled), oxblood red titles, main headings and table rules, a drop cap after the title, leaf ornaments for rules, page numbers between dashes |
|
|
66
|
+
| `gothic` | An old book of dread: blackletter Grenze Gotisch headings and IM Fell English body text (both bundled), oxblood red titles, main headings, bold text and table rules, a drop cap after the title, leaf ornaments for rules, page numbers between dashes |
|
|
67
67
|
| `sandwake` | A space-opera codex: wide Michroma capitals for titles and sections, Spectral text and Space Mono labels (all bundled), rust section numbers and drop cap, later titles numbered as books ("Liber II"), a setting-sun rule, outlined code and callouts, a running title and folio numbers |
|
|
68
68
|
| `elvish` | A quiet manuscript from under the trees: Cormorant Unicase titles and sections and Cormorant Garamond text (both bundled) at a larger size, a gold star between leafed sprigs above the title, leaves for bullets and beside `##` headings, a drop cap after each `#` heading, verse-like quotes between stars, double-ruled callouts, italic Roman numerals for lists and page numbers |
|
|
69
69
|
| `cyberpunk` | A job file leaked off somebody's terminal: squared Chakra Petch text and JetBrains Mono labels (both bundled), teal and hot magenta on white, the title in a gridded panel with corner brackets and a cyan and magenta offset, numbered sections ("01 //"), `###` headings as terminal prompts, intercept boxes for quotes, pale terminal panels for code, boxed two-digit list numbers, a running title and page numbers out of the total |
|
|
@@ -82,10 +82,12 @@ The choice is saved in `~/.config/md2pdf/config.json`. Use `md2pdf -s <style>` t
|
|
|
82
82
|
Styles are registered in the `STYLES` map in `bin/md2pdf.js`; each is a list of CSS files inlined into the page in order. A style has two files:
|
|
83
83
|
|
|
84
84
|
- `styles/<name>.css`, the on-screen look. The content is wrapped in `<article class="markdown-body">`, and every rule must be scoped to it: no `:root`, `html`, `body` or `@page` rules, so the style can be embedded in other pages.
|
|
85
|
-
- `styles/print/<name>.css`, the print-only rules: `@page` margins, running headers and page numbers,
|
|
85
|
+
- `styles/print/<name>.css`, the print-only rules: `@page` margins, running headers and page numbers, `html, body` margins, and `margin-trim: block-end` on `.markdown-body` in Safari, so it doesn't print a blank last page.
|
|
86
86
|
|
|
87
87
|
Register it in `STYLES` and add its page margin to `pageMargins` in `lib/styles.js`, and it's available to `-s` and `set-style.sh`. Use `md2pdf --html` to get the intermediate HTML for tweaking in a browser. For one-off tweaks, `--css` is enough.
|
|
88
88
|
|
|
89
|
+
`test/fixtures/sample.md` has the elements a style needs to handle: headings, lists, tables, code, block quotes, footnotes, images, math and a diagram; `test/fixtures/callouts.md` has the callouts. Check a style against them with `bin/md2pdf.js -s <name> test/fixtures/sample.md` (each PDF lands beside its Markdown; `*.pdf` is ignored). Its `mermaid` block prints as code here; md2pdf.me draws it as a diagram, so check diagrams there.
|
|
90
|
+
|
|
89
91
|
A style can bundle fonts, so it looks the same on every computer:
|
|
90
92
|
|
|
91
93
|
- Put each family in `styles/fonts/<family>/`: its `.woff2` files (the smallest format, and every current browser reads it) and its `OFL.txt`, and nothing else. Only fonts under the SIL Open Font License, which allows bundling. Fonts are the only files a style bundles.
|
|
@@ -95,7 +97,9 @@ A style can bundle fonts, so it looks the same on every computer:
|
|
|
95
97
|
|
|
96
98
|
The CLI resolves a stylesheet's relative `url()`s against the stylesheet, and loads every declared font before printing, including one used only in a page header. `npm test` checks the file layout, the licence, the family names, `local()` and `font-display`.
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
End the on-screen file with the rule the other styles end with, which turns off ligatures when Safari prints: Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e"), while Chrome's, the CLI's and on-screen text are unaffected. It belongs in the on-screen file, not the print file, because a page that embeds a style prints without the print file. On a Mac with `swiftc`, `npm test` prints every style through WebKit and checks the copied text.
|
|
101
|
+
|
|
102
|
+
The text of the document's first `#` heading (empty if there is none, and a formula in it as its TeX, `$e^{i\pi}$`) is available to page margin boxes as `var(--document-title)`, e.g. `@top-left { content: var(--document-title); }`, as the `report` style does.
|
|
99
103
|
|
|
100
104
|
A style declares the [shared variables](#variables) in its first rule, `:where(.markdown-body) { … }`, with a comment saying what each one does there, and uses them for every size, gap, color and font they name. Spacing follows two patterns: `line-height: calc(1 + 0.55 * var(--md2pdf-leading))` and `margin: calc(1.8em * var(--md2pdf-space)) 0 …`. `npm test` checks that each variable is declared and changes the document. Page margins aren't included: they stay in the style's `@page` rule, in `styles/print/<name>.css`.
|
|
101
105
|
|
|
@@ -129,9 +133,9 @@ A style that [bundles fonts](#adding-a-style) loads them relative to its stylesh
|
|
|
129
133
|
| `@threepenny/md2pdf/render` | `createRenderer({ hljs, math?, html?, idPrefix?, highlightBudget? })`, `buildDocument(...)`, `titleOf(markdown, fallback)` (the first `#` heading's text as it renders, without Markdown syntax, else the front matter's `title:`, else the fallback), `escapeHtml(s)`, `cssString(s)`, `headingText(html)` |
|
|
130
134
|
| `@threepenny/md2pdf/styles` | `pageMargins`: each style's `@page` margin at default spacing, e.g. `pageMargins.classic` is `'1in 1.1in 0.9in'` |
|
|
131
135
|
| `@threepenny/md2pdf/styles/<name>.css` | Each style's on-screen look, scoped to `.markdown-body`. For `github`, load `github-markdown-css/github-markdown-light.css` first |
|
|
132
|
-
| `@threepenny/md2pdf/styles/print/<name>.css` | Each style's print rules: page margins, running headers and page numbers. Load it after the on-screen file, only in a page that holds nothing but the document |
|
|
136
|
+
| `@threepenny/md2pdf/styles/print/<name>.css` | Each style's print rules: page margins, running headers and page numbers, and, in Safari, no space below the document's last block. Load it after the on-screen file, only in a page that holds nothing but the document |
|
|
133
137
|
|
|
134
|
-
`createRenderer` takes the highlight.js instance to use (so you can pass a smaller bundle such as `highlight.js/lib/common`) and, optionally, `math: { katex }` to render `\( \)`, `\[ \]`, `$` and `$$` formulas with KaTeX; formulas also need KaTeX's stylesheet, `katex/dist/katex.min.css
|
|
138
|
+
`createRenderer` takes the highlight.js instance to use (so you can pass a smaller bundle such as `highlight.js/lib/common`) and, optionally, `math: { katex }` to render `\( \)`, `\[ \]`, `$` and `$$` formulas with KaTeX; formulas also need KaTeX's stylesheet, `katex/dist/katex.min.css`, which hides the MathML each formula carries for screen readers; without it, that MathML shows beside the formula and can draw far outside it. (Before 2.2 it also took markdown-it-texmath, as `math: { texmath, katex }`; that still works, and texmath is ignored.) A formula over 8,000 characters, one with braces nested over 100 levels deep, or one that defines a macro (`\def`, `\newcommand`), shows as its source in red. So does a formula that would take the HTML of a document's formulas, their MathML included, past 10,000,000 characters, and every formula after it, so that a short document can't make a page hundreds of megabytes; `math: { katex, maxHtml }` changes that budget, and `maxHtml: Infinity` removes it. Sizes such as `\rule` and `\raisebox` are capped at 30em, before a size command such as `\Huge` scales them. Raw HTML in the Markdown is passed through unless you pass `html: false`, which escapes it; page breaks (`<div class="page-break"></div>`) are raw HTML, so they then print as text. `idPrefix` starts the document's ids, as [Embedding in a web page](#embedding-in-a-web-page) describes. `highlightBudget` is how many milliseconds each render may spend highlighting code, after which the rest of the code shows without colour: 100 with `html: false`, unlimited otherwise. Under a budget, a block over 4 KB is highlighted in pieces split at line breaks where it can, so a comment or string that spans a split can be coloured wrongly.
|
|
135
139
|
|
|
136
140
|
### Variables
|
|
137
141
|
|
|
@@ -203,9 +207,9 @@ A style that bundles fonts loads them from `fonts/` beside its stylesheet, so se
|
|
|
203
207
|
|
|
204
208
|
Set the [variables](#variables) on the `.markdown-body` element itself, with any selector or inline (`<article class="markdown-body" style="--md2pdf-font-size: 10pt">`). The style declares its defaults with no specificity, so your rule wins wherever it appears. A value set on `:root` or another element around the document doesn't reach it. One page can hold several documents in the same style, each with its own overrides, but not two different styles.
|
|
205
209
|
|
|
206
|
-
The document paints its own background, so on a page that isn't white, give it some padding. Your page's own CSS still applies inside the document, for whatever the style doesn't set: a global `
|
|
210
|
+
The document paints its own background, so on a page that isn't white, give it some padding. Your page's own CSS still applies inside the document, for whatever the style doesn't set: a global `em { color: #c00 }` reddens italic text in the document too. A highlight.js theme on your page is the exception: the styles keep it out of the document's code blocks. Headings get ids from their text (`# Notes` becomes `id="notes"`) so `[[#Notes]]` links work. Pass `idPrefix`, letters, digits, `_` and `-` starting with a letter and ending in `-`, to start every heading and footnote id with it, and every link to a `#` in the document: with `idPrefix: 'notes-'`, `# Notes` becomes `id="notes-notes"` and `[see](#notes)` links to it. Then no heading takes an id your page uses, as long as none of your page's ids start with the prefix, and two documents on one page don't share ids, as long as neither's prefix starts the other's (`a-` and `a-b-` would). Without it, give your own elements ids that a heading won't produce. Links in raw HTML, which only `html: true` lets through, aren't rewritten.
|
|
207
211
|
|
|
208
|
-
For Markdown you didn't write, render with `html: false` and an `idPrefix`, as in the example above. `html: false` escapes raw HTML, so the output has no scripts, event handlers, forms or style elements of the author's, and markdown-it refuses `javascript:`, `vbscript:`, `file:` and non-image `data:` URLs in links and images. The prefix keeps the document's ids from shadowing your page's globals (`# config` would otherwise give `id="config"`, which a browser exposes as `window.config`) or its own ids. Documents built to be slow to parse, such as thousands of identical headings, unclosed `[[` or unclosed formulas, render in about the time markdown-it itself takes. Code built to be slow to highlight is cut off by `highlightBudget`, which `html: false` sets to 100 ms: a render spends about that long highlighting, plus the 4 KB piece in progress, and shows the rest of the code without colour. A sanitizer such as DOMPurify is still worth running as a second line of defence. What's left to your page:
|
|
212
|
+
For Markdown you didn't write, render with `html: false` and an `idPrefix`, as in the example above. `html: false` escapes raw HTML, so the output has no scripts, event handlers, forms or style elements of the author's, and markdown-it refuses `javascript:`, `vbscript:`, `file:` and non-image `data:` URLs in links and images. The prefix keeps the document's ids from shadowing your page's globals (`# config` would otherwise give `id="config"`, which a browser exposes as `window.config`) or its own ids. Documents built to be slow to parse, such as thousands of identical headings, unclosed `[[` or unclosed formulas, render in about the time markdown-it itself takes. Code built to be slow to highlight is cut off by `highlightBudget`, which `html: false` sets to 100 ms: a render spends about that long highlighting, plus the 4 KB piece in progress, and shows the rest of the code without colour. A sanitizer such as DOMPurify is still worth running as a second line of defence; with math, pass DOMPurify `ADD_TAGS: ['semantics', 'annotation']`, or it unwraps the MathML's annotation and screen readers read each formula's TeX after it. What's left to your page:
|
|
209
213
|
|
|
210
214
|
- Limit the size of documents you accept. Without math the HTML can be about 23 times the size of the Markdown, for a document of nothing but callouts (only a document's first 200 callouts draw an icon, and only its first 1,000 inline footnotes `^[…]` become footnotes; the rest print as text). With math, the formulas' HTML stops at 10,000,000 characters (`maxHtml`), and the formulas after that show as their source.
|
|
211
215
|
- Images load from any URL the author chooses. A Content Security Policy's `img-src` limits that.
|
package/bin/md2pdf.js
CHANGED
|
@@ -34,6 +34,23 @@ const STYLES = {
|
|
|
34
34
|
cyberpunk: styleFiles('cyberpunk'),
|
|
35
35
|
};
|
|
36
36
|
const FALLBACK_STYLE = 'github';
|
|
37
|
+
// A checkout installed before KaTeX was a dependency has none until install.sh runs again; it still converts.
|
|
38
|
+
const katex = await import('katex').then(
|
|
39
|
+
(m) => m.default,
|
|
40
|
+
(err) => {
|
|
41
|
+
if (err.code === 'ERR_MODULE_NOT_FOUND') return null;
|
|
42
|
+
throw err;
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
// Added after the style only when the document has a formula, so a document without math prints as before.
|
|
46
|
+
// The rules after KaTeX's keep a displayed formula on one page and put a $$ … $$ (1) equation number at the
|
|
47
|
+
// right margin, as md2pdf.me does.
|
|
48
|
+
const MATH_CSS = katex && require.resolve('katex/dist/katex.min.css');
|
|
49
|
+
const EQUATION_NUMBERS = `
|
|
50
|
+
.markdown-body eqn { display: block; break-inside: avoid; }
|
|
51
|
+
.markdown-body section.eqno { display: flex; align-items: center; }
|
|
52
|
+
.markdown-body section.eqno > eqn { flex: 1; margin-left: 3em; }
|
|
53
|
+
.markdown-body section.eqno > span { width: 3em; text-align: right; }`;
|
|
37
54
|
|
|
38
55
|
// Settings shared by the CLI, Finder Quick Action and keyboard shortcut.
|
|
39
56
|
const CONFIG_PATH =
|
|
@@ -119,9 +136,11 @@ function readCss(file) {
|
|
|
119
136
|
}
|
|
120
137
|
|
|
121
138
|
function buildHtml({ markdown, title, baseDir, style, extraCss, pageSize }) {
|
|
122
|
-
const
|
|
139
|
+
const bodyHtml = createRenderer({ hljs, ...(katex && { math: { katex } }) }).render(markdown);
|
|
140
|
+
const math = /<eqn?>/.test(bodyHtml) ? [readCss(MATH_CSS) + EQUATION_NUMBERS] : [];
|
|
141
|
+
const css = [...STYLES[style].map(readCss), ...math, ...(extraCss ? [readCss(extraCss)] : [])].join('\n');
|
|
123
142
|
return buildDocument({
|
|
124
|
-
bodyHtml
|
|
143
|
+
bodyHtml,
|
|
125
144
|
title,
|
|
126
145
|
css,
|
|
127
146
|
pageSize,
|
|
@@ -133,9 +152,46 @@ function buildHtml({ markdown, title, baseDir, style, extraCss, pageSize }) {
|
|
|
133
152
|
});
|
|
134
153
|
}
|
|
135
154
|
|
|
155
|
+
// The temp folders that exist right now, and the Chrome printing, so an interrupt can clean up.
|
|
156
|
+
const tempDirs = new Set();
|
|
157
|
+
let chromeProc = null;
|
|
158
|
+
|
|
159
|
+
function makeTempDir(prefix) {
|
|
160
|
+
const dir = mkdtempSync(join(tmpdir(), prefix));
|
|
161
|
+
tempDirs.add(dir);
|
|
162
|
+
return dir;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function removeTempDir(dir) {
|
|
166
|
+
rmSync(dir, { recursive: true, force: true });
|
|
167
|
+
tempDirs.delete(dir);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// On an interrupt, stop Chrome, wait for it to let go of its profile, remove the temp folders, then
|
|
171
|
+
// die of the same signal so the shell sees it. Chrome gets SIGKILL: a Control + C reaches it too, and
|
|
172
|
+
// headless Chrome that has had a SIGINT hangs and ignores SIGTERM, outliving md2pdf.
|
|
173
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
174
|
+
process.once(signal, () => {
|
|
175
|
+
const die = () => {
|
|
176
|
+
for (const dir of tempDirs) {
|
|
177
|
+
try {
|
|
178
|
+
removeTempDir(dir);
|
|
179
|
+
} catch {
|
|
180
|
+
// Leave a folder that can't be removed rather than miss the others or the signal.
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
process.kill(process.pid, signal);
|
|
184
|
+
};
|
|
185
|
+
if (!chromeProc) return die();
|
|
186
|
+
chromeProc.once('close', die);
|
|
187
|
+
chromeProc.kill('SIGKILL');
|
|
188
|
+
setTimeout(die, 5000).unref();
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
136
192
|
function runChrome(chrome, htmlPath, pdfPath) {
|
|
137
193
|
// A throwaway profile keeps headless Chrome separate from any Chrome you have open.
|
|
138
|
-
const profile =
|
|
194
|
+
const profile = makeTempDir('md2pdf-chrome-');
|
|
139
195
|
const args = [
|
|
140
196
|
'--headless',
|
|
141
197
|
'--disable-gpu',
|
|
@@ -149,12 +205,18 @@ function runChrome(chrome, htmlPath, pdfPath) {
|
|
|
149
205
|
pathToFileURL(htmlPath).href,
|
|
150
206
|
];
|
|
151
207
|
return new Promise((resolvePromise, reject) => {
|
|
152
|
-
const proc = spawn(chrome, args, { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
208
|
+
const proc = (chromeProc = spawn(chrome, args, { stdio: ['ignore', 'ignore', 'pipe'] }));
|
|
153
209
|
let stderr = '';
|
|
154
210
|
proc.stderr.on('data', (d) => (stderr += d));
|
|
155
|
-
|
|
211
|
+
// A Chrome that fails to start emits 'error' first, and main() may exit before its 'close' arrives.
|
|
212
|
+
proc.on('error', (err) => {
|
|
213
|
+
if (chromeProc === proc) chromeProc = null;
|
|
214
|
+
removeTempDir(profile);
|
|
215
|
+
reject(err);
|
|
216
|
+
});
|
|
156
217
|
proc.on('close', (code) => {
|
|
157
|
-
|
|
218
|
+
if (chromeProc === proc) chromeProc = null;
|
|
219
|
+
removeTempDir(profile);
|
|
158
220
|
if (code === 0 && existsSync(pdfPath)) resolvePromise();
|
|
159
221
|
else reject(new Error(`Chrome failed (exit ${code}):\n${stderr.trim()}`));
|
|
160
222
|
});
|
|
@@ -178,14 +240,14 @@ async function convert(input, opts, chrome) {
|
|
|
178
240
|
pageSize: opts['page-size'],
|
|
179
241
|
});
|
|
180
242
|
|
|
181
|
-
const workDir =
|
|
243
|
+
const workDir = makeTempDir('md2pdf-');
|
|
182
244
|
try {
|
|
183
245
|
const htmlPath = join(workDir, `${stem}.html`);
|
|
184
246
|
writeFileSync(htmlPath, html);
|
|
185
247
|
if (opts.html) writeFileSync(pdfPath.replace(/\.pdf$/i, '') + '.html', html);
|
|
186
248
|
await runChrome(chrome, htmlPath, pdfPath);
|
|
187
249
|
} finally {
|
|
188
|
-
|
|
250
|
+
removeTempDir(workDir);
|
|
189
251
|
}
|
|
190
252
|
return pdfPath;
|
|
191
253
|
}
|
|
@@ -240,6 +302,7 @@ async function main() {
|
|
|
240
302
|
}
|
|
241
303
|
|
|
242
304
|
const chrome = findChrome();
|
|
305
|
+
if (!katex) console.error(`md2pdf: KaTeX isn't installed, so formulas print as their source; run ${join(ROOT, 'install.sh')} again`);
|
|
243
306
|
let failed = 0;
|
|
244
307
|
for (const file of files) {
|
|
245
308
|
try {
|
package/lib/math.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// TeX math, rendered by KaTeX: $…$ and \(…\) inline, $$…$$, \[…\] and \begin{env}…\end{env} displayed,
|
|
2
2
|
// and a number in parentheses after a displayed formula, `$$E = mc^2$$ (1)`. The syntax is that of
|
|
3
3
|
// markdown-it-texmath 1.0.0 with its brackets, dollars and beg_end delimiters and outerSpace, except that
|
|
4
|
-
// a $ formula may also start or end beside a line break
|
|
5
|
-
//
|
|
4
|
+
// a $ formula may also start or end beside a line break and can't hold an unescaped $, and that starred
|
|
5
|
+
// environments such as align* start a block too. texmath searches for the closing delimiter from every
|
|
6
|
+
// opening one, which takes quadratic time on a line of openers, so these rules find closers through
|
|
6
7
|
// tables built in one pass over the source. A displayed formula also ends inside the blockquote it starts
|
|
7
8
|
// in; texmath's could run on past it, so that each of a run of quotes echoed the rest of the document.
|
|
8
9
|
|
|
@@ -19,8 +20,9 @@ const DEFINITION = /\\(?:[egx]?def|let|futurelet|global|long|(?:re|provide)?newc
|
|
|
19
20
|
// Caps how far a formula can reach (\rule, \raisebox, \hspace). Negative sizes aren't capped.
|
|
20
21
|
const MAX_SIZE = 30;
|
|
21
22
|
// The HTML a document's formulas may add up to, in characters, by default. KaTeX's HTML is about 50 to 250 times
|
|
22
|
-
// its TeX for ordinary formulas and over 500 times for a matrix of empty cells
|
|
23
|
-
//
|
|
23
|
+
// its TeX for ordinary formulas and over 500 times for a matrix of empty cells, and the MathML adds 10% to
|
|
24
|
+
// 30% to that, or nearly doubles a one-letter formula. A formula that would take the HTML past the budget,
|
|
25
|
+
// and every one after it, shows as its source.
|
|
24
26
|
const MAX_HTML = 10_000_000;
|
|
25
27
|
|
|
26
28
|
// How deeply {…} nest in `tex`, not counting a brace after a backslash.
|
|
@@ -48,6 +50,7 @@ const closeBracket = (s, i) => s.startsWith('\\]', i);
|
|
|
48
50
|
const dollar = (s, i) => s[i] === '$';
|
|
49
51
|
// A $ that can close an inline formula: not after a space or a backslash.
|
|
50
52
|
const dollarCloser = (s, i) => s[i] === '$' && i > 0 && !SPACE.test(s[i - 1]) && s[i - 1] !== '\\';
|
|
53
|
+
const bareDollar = (s, i) => s[i] === '$' && s[i - 1] !== '\\';
|
|
51
54
|
const lineBreak = (s, i) => isBreak(s[i]);
|
|
52
55
|
const nonSpace = (s, i) => !SPACE.test(s[i]);
|
|
53
56
|
const bracketNumberStop = (s, i) => ')$\r\n'.includes(s[i]);
|
|
@@ -72,7 +75,8 @@ function* doubleDollar(state, at) {
|
|
|
72
75
|
if (src[d + 1] === '$' && src[d + 2] === '$') yield { content: src.slice(at + 2, d + 1), end: d + 3 };
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
// $…$ from `at`, as texmath's \$((?:[^\s\\])|(?:\S.*?[^\s\\]))\$ matches it, or null.
|
|
78
|
+
// $…$ from `at`, as texmath's \$((?:[^\s\\])|(?:\S.*?[^\s\\]))\$ matches it, or null. Unlike texmath's,
|
|
79
|
+
// a formula can't hold an unescaped $ of its own, so in `From $5 to $10, $x$` only $x$ is a formula.
|
|
76
80
|
function singleDollar(state, at) {
|
|
77
81
|
const { src } = state;
|
|
78
82
|
const c = src[at + 1];
|
|
@@ -82,6 +86,8 @@ function singleDollar(state, at) {
|
|
|
82
86
|
if (close < 0) return null;
|
|
83
87
|
const br = first(state, lineBreak, at + 2);
|
|
84
88
|
if (br >= 0 && br < close) return null;
|
|
89
|
+
const inner = first(state, bareDollar, at + 1);
|
|
90
|
+
if (inner >= 0 && inner < close) return null;
|
|
85
91
|
return { content: src.slice(at + 1, close), end: close + 1 };
|
|
86
92
|
}
|
|
87
93
|
|
|
@@ -138,7 +144,7 @@ function equationNumber(state, from, stop) {
|
|
|
138
144
|
function environmentEnd(state, name, from) {
|
|
139
145
|
if (!state.md2pdfEnds) {
|
|
140
146
|
state.md2pdfEnds = new Map();
|
|
141
|
-
for (const m of state.src.matchAll(/\\end\{([a-z]
|
|
147
|
+
for (const m of state.src.matchAll(/\\end\{([a-z]+\*?)\}/g)) {
|
|
142
148
|
if (!state.md2pdfEnds.has(m[1])) state.md2pdfEnds.set(m[1], []);
|
|
143
149
|
state.md2pdfEnds.get(m[1]).push(m.index);
|
|
144
150
|
}
|
|
@@ -154,7 +160,7 @@ function environmentEnd(state, name, from) {
|
|
|
154
160
|
return lo < ends.length ? ends[lo] : -1;
|
|
155
161
|
}
|
|
156
162
|
|
|
157
|
-
const BEGIN = /\\begin\{([a-z]
|
|
163
|
+
const BEGIN = /\\begin\{([a-z]+\*?)\}/y;
|
|
158
164
|
|
|
159
165
|
// The displayed formula starting at `at`, trying texmath's block rules in their order, or null.
|
|
160
166
|
function displayed(state, at) {
|
|
@@ -256,7 +262,8 @@ export default function math(md, { katex, maxHtml = MAX_HTML }) {
|
|
|
256
262
|
try {
|
|
257
263
|
return katex.renderToString(tex, {
|
|
258
264
|
displayMode,
|
|
259
|
-
|
|
265
|
+
// MathML, which KaTeX's stylesheet hides, gives screen readers the formula; KaTeX hides its HTML from them.
|
|
266
|
+
output: 'htmlAndMathml',
|
|
260
267
|
throwOnError: false,
|
|
261
268
|
trust: false,
|
|
262
269
|
maxSize: MAX_SIZE,
|
package/lib/render.js
CHANGED
|
@@ -150,11 +150,32 @@ export function titleOf(markdown, fallback) {
|
|
|
150
150
|
export const cssString = (s) =>
|
|
151
151
|
`"${s.replace(/[\\"]/g, '\\$&').replace(/[\0-\x1f\x7f<]/g, (c) => `\\${c.charCodeAt(0).toString(16)} `)}"`;
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
const TEX = /<annotation encoding="application\/x-tex">([^<]*)<\/annotation>/;
|
|
154
|
+
|
|
155
|
+
// `html` with each formula in <eq> or <eqn> as its TeX between $ or $$, taken from KaTeX's MathML. A
|
|
156
|
+
// formula without it, such as one that failed to render, is left as it is.
|
|
157
|
+
function formulasAsTex(html) {
|
|
158
|
+
for (const [tag, dollars] of [['eq', '$'], ['eqn', '$$']]) {
|
|
159
|
+
const parts = html.split(`</${tag}>`);
|
|
160
|
+
html = parts
|
|
161
|
+
.map((part, i) => {
|
|
162
|
+
if (i === parts.length - 1) return part;
|
|
163
|
+
const at = part.lastIndexOf(`<${tag}>`);
|
|
164
|
+
const tex = at < 0 ? undefined : part.slice(at).match(TEX)?.[1];
|
|
165
|
+
return tex === undefined ? `${part}</${tag}>` : `${part.slice(0, at)}${dollars}${tex}${dollars}`;
|
|
166
|
+
})
|
|
167
|
+
.join('');
|
|
168
|
+
}
|
|
169
|
+
return html;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const ENTITIES = { lt: '<', gt: '>', quot: '"', amp: '&', '#x27': "'", '#039': "'" };
|
|
173
|
+
|
|
174
|
+
// The text of the first <h1> in rendered HTML, or '' if there is none. A formula in it shows as its TeX.
|
|
154
175
|
export function headingText(html) {
|
|
155
176
|
const inner = html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/)?.[1] ?? '';
|
|
156
|
-
const text = inner.replace(/<[^>]*>/g, '');
|
|
157
|
-
return text.replace(/&(lt|gt|quot|amp);/g, (_, e) =>
|
|
177
|
+
const text = formulasAsTex(inner).replace(/<[^>]*>/g, '');
|
|
178
|
+
return text.replace(/&(lt|gt|quot|amp|#x27|#039);/g, (_, e) => ENTITIES[e]).trim();
|
|
158
179
|
}
|
|
159
180
|
|
|
160
181
|
// A complete printable HTML document. `css` is the style's on-screen stylesheet followed by its print
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threepenny/md2pdf",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Markdown to beautifully styled PDF: the renderer and macOS CLI behind md2pdf.me",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"github-markdown-css": "5.9.0",
|
|
37
37
|
"highlight.js": "^11.12.0",
|
|
38
|
+
"katex": "^0.19.1",
|
|
38
39
|
"markdown-it": "^15.0.2",
|
|
39
40
|
"markdown-it-emoji": "^3.1.0",
|
|
40
41
|
"markdown-it-footnote": "^4.0.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"katex": "^0.19.1",
|
|
44
44
|
"markdown-it-task-lists": "^2.1.1",
|
|
45
45
|
"markdown-it-texmath": "^1.0.0"
|
|
46
46
|
}
|
package/styles/academic.css
CHANGED
|
@@ -383,7 +383,8 @@
|
|
|
383
383
|
break-after: avoid;
|
|
384
384
|
}
|
|
385
385
|
.markdown-body .footnotes ol {
|
|
386
|
-
|
|
386
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
387
|
+
padding-left: 2em;
|
|
387
388
|
}
|
|
388
389
|
.markdown-body .footnotes p + p {
|
|
389
390
|
text-indent: 0;
|
|
@@ -397,6 +398,11 @@
|
|
|
397
398
|
display: none;
|
|
398
399
|
}
|
|
399
400
|
|
|
401
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
402
|
+
.markdown-body .footnote-ref::before {
|
|
403
|
+
content: "\2060";
|
|
404
|
+
}
|
|
405
|
+
|
|
400
406
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
401
407
|
.markdown-body .markdown-embed {
|
|
402
408
|
color: var(--md2pdf-muted);
|
|
@@ -407,3 +413,14 @@
|
|
|
407
413
|
.markdown-body .page-break {
|
|
408
414
|
break-after: page;
|
|
409
415
|
}
|
|
416
|
+
|
|
417
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
418
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
419
|
+
its features with font-variant-* instead. */
|
|
420
|
+
@media print {
|
|
421
|
+
@supports (font: -apple-system-body) {
|
|
422
|
+
.markdown-body {
|
|
423
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
package/styles/classic.css
CHANGED
|
@@ -375,13 +375,19 @@
|
|
|
375
375
|
break-after: avoid;
|
|
376
376
|
}
|
|
377
377
|
.markdown-body .footnotes ol {
|
|
378
|
-
|
|
378
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
379
|
+
padding-left: 2.2em;
|
|
379
380
|
}
|
|
380
381
|
.markdown-body .footnote-ref a,
|
|
381
382
|
.markdown-body .footnote-backref {
|
|
382
383
|
color: var(--md2pdf-accent);
|
|
383
384
|
}
|
|
384
385
|
|
|
386
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
387
|
+
.markdown-body .footnote-ref::before {
|
|
388
|
+
content: "\2060";
|
|
389
|
+
}
|
|
390
|
+
|
|
385
391
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
386
392
|
.markdown-body .markdown-embed {
|
|
387
393
|
color: var(--md2pdf-muted);
|
|
@@ -392,3 +398,14 @@
|
|
|
392
398
|
.markdown-body .page-break {
|
|
393
399
|
break-after: page;
|
|
394
400
|
}
|
|
401
|
+
|
|
402
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
403
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
404
|
+
its features with font-variant-* instead. */
|
|
405
|
+
@media print {
|
|
406
|
+
@supports (font: -apple-system-body) {
|
|
407
|
+
.markdown-body {
|
|
408
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
package/styles/cyberpunk.css
CHANGED
|
@@ -682,6 +682,11 @@
|
|
|
682
682
|
text-decoration: none;
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
686
|
+
.markdown-body .footnote-ref::before {
|
|
687
|
+
content: "\2060";
|
|
688
|
+
}
|
|
689
|
+
|
|
685
690
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
686
691
|
.markdown-body .markdown-embed {
|
|
687
692
|
color: var(--md2pdf-muted);
|
|
@@ -692,3 +697,14 @@
|
|
|
692
697
|
.markdown-body .page-break {
|
|
693
698
|
break-after: page;
|
|
694
699
|
}
|
|
700
|
+
|
|
701
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
702
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
703
|
+
its features with font-variant-* instead. */
|
|
704
|
+
@media print {
|
|
705
|
+
@supports (font: -apple-system-body) {
|
|
706
|
+
.markdown-body {
|
|
707
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
package/styles/elvish.css
CHANGED
|
@@ -631,6 +631,11 @@
|
|
|
631
631
|
text-decoration: none;
|
|
632
632
|
}
|
|
633
633
|
|
|
634
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
635
|
+
.markdown-body .footnote-ref::before {
|
|
636
|
+
content: "\2060";
|
|
637
|
+
}
|
|
638
|
+
|
|
634
639
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
635
640
|
.markdown-body .markdown-embed {
|
|
636
641
|
color: var(--md2pdf-muted);
|
|
@@ -641,3 +646,14 @@
|
|
|
641
646
|
.markdown-body .page-break {
|
|
642
647
|
break-after: page;
|
|
643
648
|
}
|
|
649
|
+
|
|
650
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
651
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
652
|
+
its features with font-variant-* instead. */
|
|
653
|
+
@media print {
|
|
654
|
+
@supports (font: -apple-system-body) {
|
|
655
|
+
.markdown-body {
|
|
656
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
package/styles/github.css
CHANGED
|
@@ -188,6 +188,16 @@
|
|
|
188
188
|
font-family: var(--md2pdf-code-font);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
/* github-markdown-css sets footnotes and keys in px, so they're restated as their share of the text
|
|
192
|
+
size, the same at 11pt. */
|
|
193
|
+
.markdown-body .footnotes {
|
|
194
|
+
font-size: calc(9 / 11 * var(--md2pdf-font-size));
|
|
195
|
+
}
|
|
196
|
+
.markdown-body kbd {
|
|
197
|
+
font-size: calc(8.25 / 11 * var(--md2pdf-font-size));
|
|
198
|
+
line-height: calc(7.5 / 11 * var(--md2pdf-font-size));
|
|
199
|
+
}
|
|
200
|
+
|
|
191
201
|
/* github-markdown-css sets line heights in px and gaps in rem (12pt here), so they're restated with the
|
|
192
202
|
spacing variables applied, and the gaps as multiples of the text size so they follow it rather than
|
|
193
203
|
the page's root font size. */
|
|
@@ -319,6 +329,15 @@
|
|
|
319
329
|
.markdown-body hr.footnotes-sep {
|
|
320
330
|
display: none;
|
|
321
331
|
}
|
|
332
|
+
.markdown-body .footnotes ol {
|
|
333
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
334
|
+
padding-left: 2.4em;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
338
|
+
.markdown-body .footnote-ref::before {
|
|
339
|
+
content: "\2060";
|
|
340
|
+
}
|
|
322
341
|
|
|
323
342
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
324
343
|
.markdown-body .markdown-embed {
|
|
@@ -330,3 +349,14 @@
|
|
|
330
349
|
.markdown-body .page-break {
|
|
331
350
|
break-after: page;
|
|
332
351
|
}
|
|
352
|
+
|
|
353
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
354
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
355
|
+
its features with font-variant-* instead. */
|
|
356
|
+
@media print {
|
|
357
|
+
@supports (font: -apple-system-body) {
|
|
358
|
+
.markdown-body {
|
|
359
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
package/styles/gothic.css
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
--md2pdf-leading: 1;
|
|
16
16
|
--md2pdf-space: 1;
|
|
17
17
|
/* Colors: --md2pdf-background the document's background; --md2pdf-text body text; --md2pdf-muted
|
|
18
|
-
secondary text; --md2pdf-accent h1, h2 and h4, the drop cap, links,
|
|
19
|
-
tick boxes, caution callouts, table headings and rules, and the footnote rule (the
|
|
20
|
-
stay oxblood); --md2pdf-rule thin rules and borders;
|
|
18
|
+
secondary text; --md2pdf-accent h1, h2 and h4, the drop cap, links, bold text, list markers,
|
|
19
|
+
quote bars, tick boxes, caution callouts, table headings and rules, and the footnote rule (the
|
|
20
|
+
leaf ornaments stay oxblood); --md2pdf-rule thin rules and borders;
|
|
21
21
|
--md2pdf-surface code and callout backgrounds. */
|
|
22
22
|
--md2pdf-background: #fff;
|
|
23
23
|
--md2pdf-text: #1c1916;
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
/* IM Fell English (Igino Marini) and Grenze Gotisch (Omnibus-Type), both under the SIL Open Font
|
|
36
36
|
License; the licences are in fonts/im-fell-english/OFL.txt and fonts/grenze-gotisch/OFL.txt. Their
|
|
37
37
|
latin subsets cover English and Western European languages (Basic Latin and Latin-1, plus œ and
|
|
38
|
-
€); other letters come from the fallbacks. IM Fell has no bold, so bold text is
|
|
39
|
-
|
|
38
|
+
€); other letters come from the fallbacks. IM Fell has no bold, so bold text is set in color
|
|
39
|
+
instead (see Bold below). */
|
|
40
40
|
@font-face {
|
|
41
41
|
font-family: "md2pdf IM Fell English";
|
|
42
42
|
font-weight: 400;
|
|
@@ -199,6 +199,19 @@
|
|
|
199
199
|
display: none;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
/* Bold: oxblood at the weight around it, and body-text color inside text that's already oxblood or a
|
|
203
|
+
callout's color. IM Fell has no bold, and Safari fakes one by drawing each letter three times,
|
|
204
|
+
which puts every bold word in the PDF's text three times. */
|
|
205
|
+
|
|
206
|
+
.markdown-body strong,
|
|
207
|
+
.markdown-body b {
|
|
208
|
+
font-weight: inherit;
|
|
209
|
+
color: var(--md2pdf-accent);
|
|
210
|
+
}
|
|
211
|
+
.markdown-body :is(h1, h2, h4, a, th, .markdown-alert-title) :is(strong, b) {
|
|
212
|
+
color: var(--md2pdf-text);
|
|
213
|
+
}
|
|
214
|
+
|
|
202
215
|
/* Lists */
|
|
203
216
|
|
|
204
217
|
.markdown-body ul,
|
|
@@ -462,6 +475,11 @@
|
|
|
462
475
|
color: var(--md2pdf-accent);
|
|
463
476
|
}
|
|
464
477
|
|
|
478
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
479
|
+
.markdown-body .footnote-ref::before {
|
|
480
|
+
content: "\2060";
|
|
481
|
+
}
|
|
482
|
+
|
|
465
483
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
466
484
|
.markdown-body .markdown-embed {
|
|
467
485
|
color: var(--md2pdf-muted);
|
|
@@ -472,3 +490,14 @@
|
|
|
472
490
|
.markdown-body .page-break {
|
|
473
491
|
break-after: page;
|
|
474
492
|
}
|
|
493
|
+
|
|
494
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
495
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
496
|
+
its features with font-variant-* instead. */
|
|
497
|
+
@media print {
|
|
498
|
+
@supports (font: -apple-system-body) {
|
|
499
|
+
.markdown-body {
|
|
500
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
package/styles/modern.css
CHANGED
|
@@ -357,7 +357,8 @@
|
|
|
357
357
|
color: var(--md2pdf-muted);
|
|
358
358
|
}
|
|
359
359
|
.markdown-body .footnotes ol {
|
|
360
|
-
|
|
360
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
361
|
+
padding-left: 2.2em;
|
|
361
362
|
}
|
|
362
363
|
.markdown-body .footnotes li {
|
|
363
364
|
margin: calc(0.2em * var(--md2pdf-space)) 0;
|
|
@@ -366,6 +367,11 @@
|
|
|
366
367
|
margin: 0;
|
|
367
368
|
}
|
|
368
369
|
|
|
370
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
371
|
+
.markdown-body .footnote-ref::before {
|
|
372
|
+
content: "\2060";
|
|
373
|
+
}
|
|
374
|
+
|
|
369
375
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
370
376
|
.markdown-body .markdown-embed {
|
|
371
377
|
color: var(--md2pdf-muted);
|
|
@@ -376,3 +382,14 @@
|
|
|
376
382
|
.markdown-body .page-break {
|
|
377
383
|
break-after: page;
|
|
378
384
|
}
|
|
385
|
+
|
|
386
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
387
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
388
|
+
its features with font-variant-* instead. */
|
|
389
|
+
@media print {
|
|
390
|
+
@supports (font: -apple-system-body) {
|
|
391
|
+
.markdown-body {
|
|
392
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
@@ -20,3 +20,12 @@ body {
|
|
|
20
20
|
margin: 0;
|
|
21
21
|
background: #fff;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
25
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
26
|
+
also drops the space above a block that a page break moves. */
|
|
27
|
+
@supports (font: -apple-system-body) {
|
|
28
|
+
.markdown-body {
|
|
29
|
+
margin-trim: block-end;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/styles/print/classic.css
CHANGED
|
@@ -25,3 +25,12 @@ body {
|
|
|
25
25
|
margin: 0;
|
|
26
26
|
background: #fff;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
30
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
31
|
+
also drops the space above a block that a page break moves. */
|
|
32
|
+
@supports (font: -apple-system-body) {
|
|
33
|
+
.markdown-body {
|
|
34
|
+
margin-trim: block-end;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -90,3 +90,12 @@ body {
|
|
|
90
90
|
margin: 0;
|
|
91
91
|
background: #fff;
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
95
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
96
|
+
also drops the space above a block that a page break moves. */
|
|
97
|
+
@supports (font: -apple-system-body) {
|
|
98
|
+
.markdown-body {
|
|
99
|
+
margin-trim: block-end;
|
|
100
|
+
}
|
|
101
|
+
}
|
package/styles/print/elvish.css
CHANGED
|
@@ -67,3 +67,12 @@ body {
|
|
|
67
67
|
margin: 0;
|
|
68
68
|
background: #fff;
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
72
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
73
|
+
also drops the space above a block that a page break moves. */
|
|
74
|
+
@supports (font: -apple-system-body) {
|
|
75
|
+
.markdown-body {
|
|
76
|
+
margin-trim: block-end;
|
|
77
|
+
}
|
|
78
|
+
}
|
package/styles/print/github.css
CHANGED
|
@@ -30,3 +30,12 @@ body {
|
|
|
30
30
|
.markdown-body table {
|
|
31
31
|
overflow: visible;
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
35
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
36
|
+
also drops the space above a block that a page break moves. */
|
|
37
|
+
@supports (font: -apple-system-body) {
|
|
38
|
+
.markdown-body {
|
|
39
|
+
margin-trim: block-end;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/styles/print/gothic.css
CHANGED
|
@@ -27,3 +27,12 @@ body {
|
|
|
27
27
|
margin: 0;
|
|
28
28
|
background: #fff;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
32
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
33
|
+
also drops the space above a block that a page break moves. */
|
|
34
|
+
@supports (font: -apple-system-body) {
|
|
35
|
+
.markdown-body {
|
|
36
|
+
margin-trim: block-end;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/styles/print/modern.css
CHANGED
|
@@ -28,3 +28,12 @@ body {
|
|
|
28
28
|
margin: 0;
|
|
29
29
|
background: #fff;
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
33
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
34
|
+
also drops the space above a block that a page break moves. */
|
|
35
|
+
@supports (font: -apple-system-body) {
|
|
36
|
+
.markdown-body {
|
|
37
|
+
margin-trim: block-end;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/styles/print/report.css
CHANGED
|
@@ -58,3 +58,12 @@ body {
|
|
|
58
58
|
margin: 0;
|
|
59
59
|
background: #fff;
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
63
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
64
|
+
also drops the space above a block that a page break moves. */
|
|
65
|
+
@supports (font: -apple-system-body) {
|
|
66
|
+
.markdown-body {
|
|
67
|
+
margin-trim: block-end;
|
|
68
|
+
}
|
|
69
|
+
}
|
package/styles/print/resume.css
CHANGED
|
@@ -17,3 +17,12 @@ body {
|
|
|
17
17
|
margin: 0;
|
|
18
18
|
background: #fff;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
22
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
23
|
+
also drops the space above a block that a page break moves. */
|
|
24
|
+
@supports (font: -apple-system-body) {
|
|
25
|
+
.markdown-body {
|
|
26
|
+
margin-trim: block-end;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -45,3 +45,12 @@ body {
|
|
|
45
45
|
margin: 0;
|
|
46
46
|
background: #fff;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
50
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
51
|
+
also drops the space above a block that a page break moves. */
|
|
52
|
+
@supports (font: -apple-system-body) {
|
|
53
|
+
.markdown-body {
|
|
54
|
+
margin-trim: block-end;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -28,3 +28,12 @@ body {
|
|
|
28
28
|
margin: 0;
|
|
29
29
|
background: #fff;
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
/* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
|
|
33
|
+
page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
|
|
34
|
+
also drops the space above a block that a page break moves. */
|
|
35
|
+
@supports (font: -apple-system-body) {
|
|
36
|
+
.markdown-body {
|
|
37
|
+
margin-trim: block-end;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/styles/report.css
CHANGED
|
@@ -345,12 +345,18 @@
|
|
|
345
345
|
color: var(--md2pdf-muted);
|
|
346
346
|
}
|
|
347
347
|
.markdown-body .footnotes ol {
|
|
348
|
-
|
|
348
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
349
|
+
padding-left: 2.2em;
|
|
349
350
|
}
|
|
350
351
|
.markdown-body .footnotes p {
|
|
351
352
|
margin: 0 0 calc(0.3em * var(--md2pdf-space));
|
|
352
353
|
}
|
|
353
354
|
|
|
355
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
356
|
+
.markdown-body .footnote-ref::before {
|
|
357
|
+
content: "\2060";
|
|
358
|
+
}
|
|
359
|
+
|
|
354
360
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
355
361
|
.markdown-body .markdown-embed {
|
|
356
362
|
color: var(--md2pdf-muted);
|
|
@@ -361,3 +367,14 @@
|
|
|
361
367
|
.markdown-body .page-break {
|
|
362
368
|
break-after: page;
|
|
363
369
|
}
|
|
370
|
+
|
|
371
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
372
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
373
|
+
its features with font-variant-* instead. */
|
|
374
|
+
@media print {
|
|
375
|
+
@supports (font: -apple-system-body) {
|
|
376
|
+
.markdown-body {
|
|
377
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
package/styles/resume.css
CHANGED
|
@@ -343,7 +343,8 @@
|
|
|
343
343
|
color: var(--md2pdf-muted);
|
|
344
344
|
}
|
|
345
345
|
.markdown-body .footnotes ol {
|
|
346
|
-
|
|
346
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
347
|
+
padding-left: 2.2em;
|
|
347
348
|
}
|
|
348
349
|
.markdown-body .footnotes p {
|
|
349
350
|
margin: 0;
|
|
@@ -352,6 +353,11 @@
|
|
|
352
353
|
display: none;
|
|
353
354
|
}
|
|
354
355
|
|
|
356
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
357
|
+
.markdown-body .footnote-ref::before {
|
|
358
|
+
content: "\2060";
|
|
359
|
+
}
|
|
360
|
+
|
|
355
361
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
356
362
|
.markdown-body .markdown-embed {
|
|
357
363
|
color: var(--md2pdf-muted);
|
|
@@ -362,3 +368,14 @@
|
|
|
362
368
|
.markdown-body .page-break {
|
|
363
369
|
break-after: page;
|
|
364
370
|
}
|
|
371
|
+
|
|
372
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
373
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
374
|
+
its features with font-variant-* instead. */
|
|
375
|
+
@media print {
|
|
376
|
+
@supports (font: -apple-system-body) {
|
|
377
|
+
.markdown-body {
|
|
378
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
package/styles/sandwake.css
CHANGED
|
@@ -520,14 +520,19 @@
|
|
|
520
520
|
break-after: avoid;
|
|
521
521
|
}
|
|
522
522
|
.markdown-body .footnotes ol {
|
|
523
|
-
/* Room for
|
|
524
|
-
padding-left:
|
|
523
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
524
|
+
padding-left: 2.4em;
|
|
525
525
|
}
|
|
526
526
|
.markdown-body .footnote-ref a,
|
|
527
527
|
.markdown-body .footnote-backref {
|
|
528
528
|
color: var(--md2pdf-accent);
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
532
|
+
.markdown-body .footnote-ref::before {
|
|
533
|
+
content: "\2060";
|
|
534
|
+
}
|
|
535
|
+
|
|
531
536
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
532
537
|
.markdown-body .markdown-embed {
|
|
533
538
|
color: var(--md2pdf-muted);
|
|
@@ -538,3 +543,14 @@
|
|
|
538
543
|
.markdown-body .page-break {
|
|
539
544
|
break-after: page;
|
|
540
545
|
}
|
|
546
|
+
|
|
547
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
548
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
549
|
+
its features with font-variant-* instead. */
|
|
550
|
+
@media print {
|
|
551
|
+
@supports (font: -apple-system-body) {
|
|
552
|
+
.markdown-body {
|
|
553
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
package/styles/worksheet.css
CHANGED
|
@@ -462,7 +462,8 @@
|
|
|
462
462
|
color: var(--md2pdf-muted);
|
|
463
463
|
}
|
|
464
464
|
.markdown-body .footnotes ol {
|
|
465
|
-
|
|
465
|
+
/* Room for numbers up to 99, which Safari sets further left than Chrome. */
|
|
466
|
+
padding-left: 2.2em;
|
|
466
467
|
}
|
|
467
468
|
.markdown-body .footnotes li {
|
|
468
469
|
margin: calc(0.2em * var(--md2pdf-space)) 0;
|
|
@@ -471,6 +472,11 @@
|
|
|
471
472
|
margin: 0;
|
|
472
473
|
}
|
|
473
474
|
|
|
475
|
+
/* A word joiner keeps a footnote mark on the line with the word before it. */
|
|
476
|
+
.markdown-body .footnote-ref::before {
|
|
477
|
+
content: "\2060";
|
|
478
|
+
}
|
|
479
|
+
|
|
474
480
|
/* An Obsidian embed (![[Other note]]) that can't be shown: a muted placeholder. */
|
|
475
481
|
.markdown-body .markdown-embed {
|
|
476
482
|
color: var(--md2pdf-muted);
|
|
@@ -481,3 +487,14 @@
|
|
|
481
487
|
.markdown-body .page-break {
|
|
482
488
|
break-after: page;
|
|
483
489
|
}
|
|
490
|
+
|
|
491
|
+
/* Safari's PDFs copy a ligature as the wrong characters ("The" pastes as "!e", "ffi" as "ffi"), so it
|
|
492
|
+
prints without them. An element's own font-feature-settings or `font` shorthand undoes this; set
|
|
493
|
+
its features with font-variant-* instead. */
|
|
494
|
+
@media print {
|
|
495
|
+
@supports (font: -apple-system-body) {
|
|
496
|
+
.markdown-body {
|
|
497
|
+
font-feature-settings: "liga" 0, "clig" 0;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|