@threepenny/md2pdf 2.4.0 → 2.5.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/lib/math.js CHANGED
@@ -1,11 +1,12 @@
1
1
  // TeX math, rendered by KaTeX: $…$ and \(…\) inline, $$…$$, \[…\] and \begin{env}…\end{env} displayed,
2
- // and a number in parentheses after a displayed formula, `$$E = mc^2$$ (1)`. The syntax is that of
2
+ // and a number in parentheses after a displayed formula on its last line, `$$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 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
7
- // tables built in one pass over the source. A displayed formula also ends inside the blockquote it starts
8
- // in; texmath's could run on past it, so that each of a run of quotes echoed the rest of the document.
4
+ // a $ formula may also start or end beside a line break, start after ( * or _, or end before ) * _ ? ! or :,
5
+ // and can't hold an unescaped $, and that starred environments such as align* start a block too. texmath
6
+ // searches for the closing delimiter from every opening one, which takes quadratic time on a line of
7
+ // openers, so these rules find closers through tables built in one pass over the source. A displayed
8
+ // formula also ends inside the blockquote it starts in; texmath's could run on past it, so that each of a
9
+ // run of quotes echoed the rest of the document.
9
10
 
10
11
  import { first, nextWhere } from './scan.js';
11
12
 
@@ -56,10 +57,10 @@ const nonSpace = (s, i) => !SPACE.test(s[i]);
56
57
  const bracketNumberStop = (s, i) => ')$\r\n'.includes(s[i]);
57
58
  const dollarNumberStop = (s, i) => s[i] === ')' || SPACE.test(s[i]);
58
59
 
59
- // Whether the $ at `at` opens or closes a formula: whitespace or the paragraph's edge is outside it,
60
- // or after a closing $, punctuation that ends a clause.
61
- const dollarPre = (src, at) => at === 0 || SPACE.test(src[at - 1]);
62
- const dollarPost = (src, at) => at + 1 >= src.length || /[\s.,;]/.test(src[at + 1]);
60
+ // Whether the $ at `at` opens or closes a formula: whitespace or the paragraph's edge is outside it, or
61
+ // emphasis or a parenthesis, or after a closing $, punctuation that ends a clause.
62
+ const dollarPre = (src, at) => at === 0 || /[\s(*_]/.test(src[at - 1]);
63
+ const dollarPost = (src, at) => at + 1 >= src.length || /[\s.,;:?!)*_]/.test(src[at + 1]);
63
64
  // texmath's own test for $$ inside a paragraph, which outerSpace doesn't reach: no backslash or digit
64
65
  // before the opening $$, and no digit after the closing one.
65
66
  const isDigit = (c) => c >= '0' && c <= '9';
@@ -131,10 +132,14 @@ function inline(state, silent) {
131
132
  return true;
132
133
  }
133
134
 
134
- // An equation number after a displayed formula that ends at `from`: whitespace, then (number).
135
+ // An equation number after a displayed formula that ends at `from`: spaces, then (number), on the closing
136
+ // delimiter's own line. texmath's could start on any later line, so it took the (a) that starts the next
137
+ // paragraph.
135
138
  function equationNumber(state, from, stop) {
136
139
  const open = first(state, nonSpace, from);
137
140
  if (open < 0 || state.src[open] !== '(') return null;
141
+ const br = first(state, lineBreak, from);
142
+ if (br >= 0 && br < open) return null;
138
143
  const close = first(state, stop, open + 1);
139
144
  if (close <= open + 1 || state.src[close] !== ')') return null;
140
145
  return { info: state.src.slice(open + 1, close), end: close + 1 };
@@ -0,0 +1,20 @@
1
+ // The @page sizes md2pdf takes, shared by the CLI and buildDocument: auto, a paper name, an orientation or
2
+ // both, or one or two lengths. Chrome prints a size it can't read at Letter without a word. It also reads
3
+ // calc() and newer units, which aren't taken here.
4
+
5
+ export const PAPER = ['a5', 'a4', 'a3', 'b5', 'b4', 'jis-b5', 'jis-b4', 'letter', 'legal', 'ledger'];
6
+ const ORIENTATION = ['portrait', 'landscape'];
7
+ const LENGTH = /^\+?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(?:in|cm|mm|q|pt|pc|px|em|rem|ex|ch|vw|vh|vmin|vmax)$/;
8
+ // buildDocument writes a size that passes straight into its <style> element, so this is checked first, on the
9
+ // string as given: whatever the word rules below come to accept, nothing else can reach the stylesheet. Only
10
+ // CSS's whitespace separates words; to CSS, a no-break space is part of a word.
11
+ const CHARACTERS = /^[A-Za-z0-9.+\- \t\n\r\f]*$/;
12
+
13
+ export function isPageSize(size) {
14
+ if (typeof size !== 'string' || !CHARACTERS.test(size)) return false;
15
+ const words = size.trim().toLowerCase().split(/\s+/);
16
+ if (words.length > 2) return false;
17
+ if (words.every((w) => LENGTH.test(w)) || size.trim().toLowerCase() === 'auto') return true;
18
+ const count = (list) => words.filter((w) => list.includes(w)).length;
19
+ return count(PAPER) <= 1 && count(ORIENTATION) <= 1 && count(PAPER) + count(ORIENTATION) === words.length;
20
+ }
package/lib/render.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Markdown → HTML rendering shared by the CLI and the md2pdf.me website.
2
2
 
3
+ import { decodeHTML } from 'entities';
3
4
  import MarkdownIt from 'markdown-it';
4
5
  import footnote from 'markdown-it-footnote';
5
6
  import { full as emoji } from 'markdown-it-emoji';
@@ -7,7 +8,9 @@ import callouts from './callouts.js';
7
8
  import footnotes from './footnotes.js';
8
9
  import ids, { ID_PREFIX } from './ids.js';
9
10
  import mathRules from './math.js';
11
+ import { PAPER, isPageSize } from './page-size.js';
10
12
  import taskLists from './tasklists.js';
13
+ import typography from './typography.js';
11
14
  import wikilinks from './wikilinks.js';
12
15
 
13
16
  // YAML front matter: a `---` line at the very start of the document, closed by another `---` line.
@@ -17,6 +20,16 @@ const YAML_KEY = /^[^\s#:-][^:]*:(?:[ \t]|$)/;
17
20
  // Any other line properties can have: a `- item`, an indented continuation or a # comment.
18
21
  const YAML_OTHER = /^(?:-(?:[ \t]|$)|[ \t]+\S|#)/;
19
22
 
23
+ // Windows editors start a file with U+FEFF, which isn't whitespace to markdown-it: left in, the first line
24
+ // is no longer a heading or the start of front matter.
25
+ const withoutByteOrderMark = (s) => (s.charCodeAt(0) === 0xfeff ? s.slice(1) : s);
26
+
27
+ function byteOrderMark(md) {
28
+ md.core.ruler.before('normalize', 'byte_order_mark', (state) => {
29
+ state.src = withoutByteOrderMark(state.src);
30
+ });
31
+ }
32
+
20
33
  // The front matter block at the start of `markdown` and the YAML inside it, or null. A `---…---` block
21
34
  // that isn't YAML properties is Markdown after a divider, as AI answers write it. A # line could be a
22
35
  // comment or a heading, and a - line a list, so the first other line must be a property.
@@ -114,10 +127,12 @@ export function createRenderer({ hljs, math, html = true, idPrefix = '', highlig
114
127
  .use(footnote)
115
128
  .use(footnotes, { idPrefix })
116
129
  .use(taskLists)
130
+ .use(typography)
117
131
  .use(emoji)
118
132
  .use(callouts)
119
133
  .use(wikilinks, { slugify })
120
- .use(frontMatter);
134
+ .use(frontMatter)
135
+ .use(byteOrderMark);
121
136
  if (math) md.use(mathRules, { katex: math.katex, maxHtml: math.maxHtml });
122
137
  return md;
123
138
  }
@@ -133,17 +148,72 @@ function trimSpaceTab(s) {
133
148
  return s.slice(start, end);
134
149
  }
135
150
 
136
- // The document title: the text of the first level-one heading as it renders, else the front matter's
137
- // `title:`, else the fallback.
151
+ // A block scalar's header: > or |, with its chomping and indentation indicators.
152
+ const BLOCK_SCALAR = /^[>|][+-]?\d?[+-]?(?:[ \t]+#[^]*)?$/;
153
+
154
+ // The first `title:` in front matter's YAML that has a value, or ''. A lowercase key only, as YAML's keys
155
+ // are case-sensitive. A `>` or `|` block reads as one line, and a quoted value loses its quotes.
156
+ function yamlTitle(yaml) {
157
+ const lines = yaml.split(/\r?\n/);
158
+ for (let i = 0; i < lines.length; i++) {
159
+ if (!/^title:(?:[ \t]|$)/.test(lines[i])) continue;
160
+ let value = trimSpaceTab(lines[i].slice('title:'.length));
161
+ // [^]* and not .*, here and below: a line can hold a lone \r or a line separator, which . stops at, and
162
+ // the search would then run again from every #.
163
+ const quoted = value.match(/^(["'])(.*?)\1[ \t]*(?:#[^]*)?$/);
164
+ if (BLOCK_SCALAR.test(value)) {
165
+ const text = [];
166
+ for (let j = i + 1; j < lines.length && (/^[ \t]/.test(lines[j]) || !lines[j].trim()); j++) text.push(lines[j].trim());
167
+ value = text.filter(Boolean).join(' ');
168
+ } else if (quoted) {
169
+ value = quoted[2];
170
+ } else {
171
+ // A # after a space starts a comment.
172
+ value = value.startsWith('#') ? '' : value.replace(/[ \t]#[^]*$/, '');
173
+ }
174
+ if (value.trim()) return value.trim();
175
+ }
176
+ return '';
177
+ }
178
+
179
+ // Whether a block token is raw HTML, or holds some, whose text matches `pattern`.
180
+ const rawHtml = (token, pattern = /^/) =>
181
+ token.type === 'html_block'
182
+ ? pattern.test(token.content)
183
+ : token.type === 'inline' && token.children.some((t) => t.type === 'html_inline' && pattern.test(t.content));
184
+
185
+ // The document title: the text of the first level-one heading, Markdown or raw HTML, as headingText finds it
186
+ // in a render with raw HTML on; else the front matter's `title:`, else the fallback.
138
187
  export function titleOf(markdown, fallback) {
139
- titleParser ??= createRenderer({});
188
+ if (!titleParser) {
189
+ // Code renders unhighlighted and callouts without icons, with the same text. Each render call starts
190
+ // the icon cap again, so the pieces below would otherwise draw every icon.
191
+ titleParser = createRenderer({ hljs: { getLanguage: () => undefined } });
192
+ titleParser.renderer.rules.callout_title_open = () => '<p class="markdown-alert-title">';
193
+ }
140
194
  const env = {};
141
195
  const tokens = titleParser.parse(markdown, env);
142
- const at = tokens.findIndex((t) => t.type === 'heading_open' && t.tag === 'h1');
143
- const heading = at < 0 ? '' : headingText(titleParser.renderer.render(tokens.slice(at, at + 3), titleParser.options, env));
144
- const yaml = frontMatterOf(markdown)?.yaml ?? '';
145
- const title = trimSpaceTab(yaml.match(/^title:(.+)$/m)?.[1] ?? '').replace(/^(["'])(.*)\1$/, '$2').trim();
146
- return heading || title || fallback;
196
+ // Before the first h1 or raw HTML, a render has no h1 and leaves no tag open, so it can't change what
197
+ // headingText finds: start there. Render in pieces, each ending at a token that may close an h1. No token
198
+ // that ends a piece looks at the next, and none that starts one looks back, so the pieces' text joins as
199
+ // one render's would. Look for the h1 again only once the HTML has doubled, so a document full of </h1 in
200
+ // comments takes linear time; a longer render finds the same first h1.
201
+ const start = tokens.findIndex((t) => (t.type === 'heading_open' && t.tag === 'h1') || rawHtml(t));
202
+ let heading;
203
+ let html = '';
204
+ let scanned = -1;
205
+ for (let from = start, end = start; start >= 0 && end < tokens.length && heading === undefined; end++) {
206
+ const t = tokens[end];
207
+ const last = end === tokens.length - 1;
208
+ if (!last && !(t.type === 'heading_close' && t.tag === 'h1') && !rawHtml(t, /<\/h1/i)) continue;
209
+ html += titleParser.renderer.render(tokens.slice(from, end + 1), titleParser.options, env);
210
+ from = end + 1;
211
+ if (last || html.length >= 2 * scanned) {
212
+ scanned = html.length;
213
+ heading = firstHeading(html);
214
+ }
215
+ }
216
+ return heading || yamlTitle(frontMatterOf(withoutByteOrderMark(markdown))?.yaml ?? '') || fallback;
147
217
  }
148
218
 
149
219
  // A quoted CSS string, safe inside a <style> element.
@@ -169,19 +239,54 @@ function formulasAsTex(html) {
169
239
  return html;
170
240
  }
171
241
 
172
- const ENTITIES = { lt: '<', gt: '>', quot: '"', amp: '&', '#x27': "'", '#039': "'" };
242
+ // A comment, or a tag whose > may sit in a quoted attribute value; a quote opens a value only after =. Every
243
+ // alternative matches once it starts, so a scan never backs up, and an unclosed comment, tag or quote runs
244
+ // to the end, as in a browser.
245
+ const TAG = /<!--(?:-?>|[\s\S]*?(?:-->|$))|<[a-zA-Z/!?](?:[^>=]|=[\t\n\f\r ]*(?:"[^"]*(?:"|$)|'[^']*(?:'|$))?)*>?/g;
246
+ const H1_OPEN = /^<h1[\t\n\f\r />]/i;
247
+ const H1_CLOSE = /^<\/h1[\t\n\f\r />]/i;
248
+
249
+ // The text of the first <h1> in rendered HTML, as a browser shows it, or undefined if no <h1> is closed. Raw
250
+ // HTML can write the h1 in any case, inside a comment or with entities. A formula in it shows as its TeX.
251
+ function firstHeading(html) {
252
+ let start = -1;
253
+ TAG.lastIndex = 0;
254
+ for (let tag; (tag = TAG.exec(html)); ) {
255
+ if (start < 0) {
256
+ if (H1_OPEN.test(tag[0])) start = TAG.lastIndex;
257
+ } else if (H1_CLOSE.test(tag[0])) {
258
+ return decodeHTML(formulasAsTex(html.slice(start, tag.index)).replace(TAG, '')).trim();
259
+ }
260
+ }
261
+ return undefined;
262
+ }
173
263
 
174
- // The text of the first <h1> in rendered HTML, or '' if there is none. A formula in it shows as its TeX.
264
+ // The text of the first <h1> in rendered HTML, as a browser shows it, or '' if there is none.
175
265
  export function headingText(html) {
176
- const inner = html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/)?.[1] ?? '';
177
- const text = formulasAsTex(inner).replace(/<[^>]*>/g, '');
178
- return text.replace(/&(lt|gt|quot|amp|#x27|#039);/g, (_, e) => ENTITIES[e]).trim();
266
+ return firstHeading(html) ?? '';
267
+ }
268
+
269
+ export { isPageSize };
270
+
271
+ // The value in a pageSize error: quoted and cut short, with < > & and everything outside printable ASCII
272
+ // escaped too, for a host that shows the message as HTML or writes it to a log or a terminal.
273
+ function describe(value) {
274
+ if (value === null) return 'null';
275
+ if (typeof value !== 'string') return `${/^[aeiou]/.test(typeof value) ? 'an' : 'a'} ${typeof value}`;
276
+ const text = JSON.stringify(value.length > 80 ? `${value.slice(0, 80)}…` : value);
277
+ return text.replace(/[^\x20-\x7e…]|[<>&]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
179
278
  }
180
279
 
181
280
  // A complete printable HTML document. `css` is the style's on-screen stylesheet followed by its print
182
- // stylesheet.
281
+ // stylesheet, written as given but for a \ before the / of each </style, in any case: the same in CSS, and
282
+ // it can't end the element. `head` and `bodyHtml` are written as given. `pageSize` must pass isPageSize, or this throws.
183
283
  // Styles can show the first heading in a running header with `content: var(--document-title)`.
184
284
  export function buildDocument({ bodyHtml, title, css, pageSize = 'Letter', head = '' }) {
285
+ if (!isPageSize(pageSize)) {
286
+ throw new TypeError(
287
+ `buildDocument: pageSize ${describe(pageSize)} isn't a page size. Use auto, portrait or landscape, a paper name (${PAPER.join(', ')}) alone or with portrait or landscape, or one or two lengths such as "5in 8in"`,
288
+ );
289
+ }
185
290
  return `<!DOCTYPE html>
186
291
  <html lang="en">
187
292
  <head>
@@ -189,7 +294,7 @@ export function buildDocument({ bodyHtml, title, css, pageSize = 'Letter', head
189
294
  <title>${escapeHtml(title)}</title>
190
295
  ${head}
191
296
  <style>
192
- ${css}
297
+ ${String(css).replace(/<\/(style)/gi, '<\\/$1')}
193
298
  @page { size: ${pageSize}; }
194
299
  :root { --document-title: ${cssString(headingText(bodyHtml))}; }
195
300
  </style>
@@ -0,0 +1,32 @@
1
+ // markdown-it's typographic replacements without (c), (r) and (tm), which it turns into ©, ® and ™ wherever
2
+ // they stand: the last of "(a) (b) (c)", "Rule 12(c)", "f(r)". Its one option, typographer, covers them
3
+ // together with the dashes, the ellipsis and ±, so this is its `replacements` rule (15.0.2) with the rest.
4
+
5
+ const RARE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/;
6
+
7
+ export default function typography(md) {
8
+ md.core.ruler.at('replacements', (state) => {
9
+ if (!state.md.options.typographer) return;
10
+ for (const block of state.tokens) {
11
+ if (block.type !== 'inline' || !RARE.test(block.content)) continue;
12
+ let insideAutolink = 0;
13
+ for (let i = block.children.length - 1; i >= 0; i--) {
14
+ const token = block.children[i];
15
+ if (token.type === 'text' && !insideAutolink && RARE.test(token.content)) {
16
+ token.content = token.content
17
+ .replace(/\+-/g, '±')
18
+ // .., ..., ....... -> …, but ?..... and !..... -> ?.. and !..
19
+ .replace(/\.{2,}/g, '…')
20
+ .replace(/([?!])…/g, '$1..')
21
+ .replace(/([?!]){4,}/g, '$1$1$1')
22
+ .replace(/,{2,}/g, ',')
23
+ .replace(/(^|[^-])---(?=[^-]|$)/gm, '$1—')
24
+ .replace(/(^|\s)--(?=\s|$)/gm, '$1–')
25
+ .replace(/(^|[^-\s])--(?=[^-\s]|$)/gm, '$1–');
26
+ }
27
+ if (token.type === 'link_open' && token.info === 'auto') insideAutolink--;
28
+ if (token.type === 'link_close' && token.info === 'auto') insideAutolink++;
29
+ }
30
+ }
31
+ });
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threepenny/md2pdf",
3
- "version": "2.4.0",
3
+ "version": "2.5.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",
@@ -33,6 +33,7 @@
33
33
  "demo": "echo 'Open http://localhost:3900/demo/' && python3 -m http.server 3900 --bind 127.0.0.1"
34
34
  },
35
35
  "dependencies": {
36
+ "entities": "^8.0.0",
36
37
  "github-markdown-css": "5.9.0",
37
38
  "highlight.js": "^11.12.0",
38
39
  "katex": "^0.19.1",
package/styles/github.css CHANGED
@@ -12,7 +12,7 @@
12
12
  --md2pdf-leading: 1;
13
13
  --md2pdf-space: 1;
14
14
  /* Colors: --md2pdf-background the document's background; --md2pdf-text body text; --md2pdf-muted
15
- quotes, footnotes and secondary text; --md2pdf-accent links. */
15
+ quotes, footnotes and secondary text; --md2pdf-accent links and focus rings. */
16
16
  --md2pdf-background: #fff;
17
17
  --md2pdf-text: #1f2328;
18
18
  --md2pdf-muted: #59636e;
@@ -24,6 +24,14 @@
24
24
  --md2pdf-code-font: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
25
25
  }
26
26
 
27
+ /* github-markdown-light.css draws focus rings, and <kbd>'s border and shadow, in these colors but
28
+ leaves them to github-markdown.css to define. Undefined, the ring turns off the browser's own, and
29
+ <kbd> loses its border and shadow. --borderColor-muted is github-markdown.css's light value (5.9.0). */
30
+ :where(.markdown-body) {
31
+ --borderColor-accent-emphasis: var(--md2pdf-accent);
32
+ --borderColor-muted: #d1d9e0b3;
33
+ }
34
+
27
35
  /* highlight.js's GitHub theme, limited to the document. From highlight.js 11.12.0.
28
36
  On .hljs itself, :where() keeps each selector's specificity what it is in the theme, so the rules
29
37
  below still override it. The token rules take .markdown-body's specificity, to outrank a theme on
@@ -189,11 +197,13 @@
189
197
  }
190
198
 
191
199
  /* 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. */
200
+ size, the same at 11pt. A key's padding stays github-markdown-css's 0.25rem (3pt here) but shrinks
201
+ with smaller text, or the key, border included, makes its line taller. */
193
202
  .markdown-body .footnotes {
194
203
  font-size: calc(9 / 11 * var(--md2pdf-font-size));
195
204
  }
196
205
  .markdown-body kbd {
206
+ padding: min(0.25rem, calc(3 / 11 * var(--md2pdf-font-size)));
197
207
  font-size: calc(8.25 / 11 * var(--md2pdf-font-size));
198
208
  line-height: calc(7.5 / 11 * var(--md2pdf-font-size));
199
209
  }
@@ -21,6 +21,30 @@ body {
21
21
  background: #fff;
22
22
  }
23
23
 
24
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
25
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
26
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
27
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
28
+ a nested list, the next item is then an item's space away, as after text. */
29
+ .markdown-body details {
30
+ margin-bottom: calc(0.6em * var(--md2pdf-space));
31
+ }
32
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
33
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
34
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
35
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
36
+ margin-bottom: 0;
37
+ }
38
+ .markdown-body details::details-content {
39
+ content-visibility: visible;
40
+ }
41
+ .markdown-body details:not([open]) > summary {
42
+ list-style-type: disclosure-open;
43
+ }
44
+ .markdown-body details > summary {
45
+ break-after: avoid;
46
+ }
47
+
24
48
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
25
49
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
26
50
  also drops the space above a block that a page break moves. */
@@ -26,6 +26,30 @@ body {
26
26
  background: #fff;
27
27
  }
28
28
 
29
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
30
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
31
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
32
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
33
+ a nested list, the next item is then an item's space away, as after text. */
34
+ .markdown-body details {
35
+ margin-bottom: calc(0.75em * var(--md2pdf-space));
36
+ }
37
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
38
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
39
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
40
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
41
+ margin-bottom: 0;
42
+ }
43
+ .markdown-body details::details-content {
44
+ content-visibility: visible;
45
+ }
46
+ .markdown-body details:not([open]) > summary {
47
+ list-style-type: disclosure-open;
48
+ }
49
+ .markdown-body details > summary {
50
+ break-after: avoid;
51
+ }
52
+
29
53
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
30
54
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
31
55
  also drops the space above a block that a page break moves. */
@@ -91,6 +91,30 @@ body {
91
91
  background: #fff;
92
92
  }
93
93
 
94
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
95
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
96
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
97
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
98
+ a nested list, the next item is then an item's space away, as after text. */
99
+ .markdown-body details {
100
+ margin-bottom: calc(0.8em * var(--md2pdf-space));
101
+ }
102
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
103
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
104
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
105
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
106
+ margin-bottom: 0;
107
+ }
108
+ .markdown-body details::details-content {
109
+ content-visibility: visible;
110
+ }
111
+ .markdown-body details:not([open]) > summary {
112
+ list-style-type: disclosure-open;
113
+ }
114
+ .markdown-body details > summary {
115
+ break-after: avoid;
116
+ }
117
+
94
118
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
95
119
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
96
120
  also drops the space above a block that a page break moves. */
@@ -68,6 +68,30 @@ body {
68
68
  background: #fff;
69
69
  }
70
70
 
71
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
72
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
73
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
74
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
75
+ a nested list, the next item is then an item's space away, as after text. */
76
+ .markdown-body details {
77
+ margin-bottom: calc(0.75em * var(--md2pdf-space));
78
+ }
79
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
80
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
81
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
82
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
83
+ margin-bottom: 0;
84
+ }
85
+ .markdown-body details::details-content {
86
+ content-visibility: visible;
87
+ }
88
+ .markdown-body details:not([open]) > summary {
89
+ list-style-type: disclosure-open;
90
+ }
91
+ .markdown-body details > summary {
92
+ break-after: avoid;
93
+ }
94
+
71
95
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
72
96
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
73
97
  also drops the space above a block that a page break moves. */
@@ -19,6 +19,26 @@ body {
19
19
  background: #fff;
20
20
  }
21
21
 
22
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. A
23
+ section that ends a quote, callout, table cell, or the last item of a list inside one of those or another
24
+ list, gives up the space below it, and so do the sections and last block inside it, up to three sections
25
+ deep, so none shows inside. */
26
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
27
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
28
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
29
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
30
+ margin-bottom: 0;
31
+ }
32
+ .markdown-body details::details-content {
33
+ content-visibility: visible;
34
+ }
35
+ .markdown-body details:not([open]) > summary {
36
+ list-style-type: disclosure-open;
37
+ }
38
+ .markdown-body details > summary {
39
+ break-after: avoid;
40
+ }
41
+
22
42
  .markdown-body {
23
43
  max-width: none;
24
44
  margin: 0;
@@ -28,6 +28,30 @@ body {
28
28
  background: #fff;
29
29
  }
30
30
 
31
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
32
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
33
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
34
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
35
+ a nested list, the next item is then an item's space away, as after text. */
36
+ .markdown-body details {
37
+ margin-bottom: calc(0.75em * var(--md2pdf-space));
38
+ }
39
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
40
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
41
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
42
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
43
+ margin-bottom: 0;
44
+ }
45
+ .markdown-body details::details-content {
46
+ content-visibility: visible;
47
+ }
48
+ .markdown-body details:not([open]) > summary {
49
+ list-style-type: disclosure-open;
50
+ }
51
+ .markdown-body details > summary {
52
+ break-after: avoid;
53
+ }
54
+
31
55
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
32
56
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
33
57
  also drops the space above a block that a page break moves. */
@@ -29,6 +29,30 @@ body {
29
29
  background: #fff;
30
30
  }
31
31
 
32
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
33
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
34
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
35
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
36
+ a nested list, the next item is then an item's space away, as after text. */
37
+ .markdown-body details {
38
+ margin-bottom: calc(1em * var(--md2pdf-space));
39
+ }
40
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
41
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
42
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
43
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
44
+ margin-bottom: 0;
45
+ }
46
+ .markdown-body details::details-content {
47
+ content-visibility: visible;
48
+ }
49
+ .markdown-body details:not([open]) > summary {
50
+ list-style-type: disclosure-open;
51
+ }
52
+ .markdown-body details > summary {
53
+ break-after: avoid;
54
+ }
55
+
32
56
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
33
57
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
34
58
  also drops the space above a block that a page break moves. */
@@ -59,6 +59,30 @@ body {
59
59
  background: #fff;
60
60
  }
61
61
 
62
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
63
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
64
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
65
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
66
+ a nested list, the next item is then an item's space away, as after text. */
67
+ .markdown-body details {
68
+ margin-bottom: calc(0.8em * var(--md2pdf-space));
69
+ }
70
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
71
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
72
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
73
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
74
+ margin-bottom: 0;
75
+ }
76
+ .markdown-body details::details-content {
77
+ content-visibility: visible;
78
+ }
79
+ .markdown-body details:not([open]) > summary {
80
+ list-style-type: disclosure-open;
81
+ }
82
+ .markdown-body details > summary {
83
+ break-after: avoid;
84
+ }
85
+
62
86
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
63
87
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
64
88
  also drops the space above a block that a page break moves. */
@@ -18,6 +18,30 @@ body {
18
18
  background: #fff;
19
19
  }
20
20
 
21
+ /* A PDF can't be clicked, so a collapsed section prints open, its summary kept with what follows. After it
22
+ comes a paragraph's space, or its last block's if that is more. A section that ends a quote, callout,
23
+ table cell, or the last item of a list inside one of those or another list, gives up that space, and so
24
+ do the sections and last block inside it, up to three sections deep, so none shows inside; at the end of
25
+ a nested list, the next item is then an item's space away, as after text. */
26
+ .markdown-body details {
27
+ margin-bottom: calc(0.45em * var(--md2pdf-space));
28
+ }
29
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child,
30
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > :last-child,
31
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > :last-child,
32
+ .markdown-body :is(blockquote, .markdown-alert, td, th, :is(blockquote, .markdown-alert, td, th, li) :is(ul, ol) > li:last-child) > details:last-child > details:last-child > details:last-child > :last-child {
33
+ margin-bottom: 0;
34
+ }
35
+ .markdown-body details::details-content {
36
+ content-visibility: visible;
37
+ }
38
+ .markdown-body details:not([open]) > summary {
39
+ list-style-type: disclosure-open;
40
+ }
41
+ .markdown-body details > summary {
42
+ break-after: avoid;
43
+ }
44
+
21
45
  /* Nothing follows the document's last block, so Safari keeps no space below it: it starts a blank
22
46
  page for that space when it runs past the end of a page. Only Safari, since Chrome's margin-trim
23
47
  also drops the space above a block that a page break moves. */