@threepenny/md2pdf 2.6.0 → 2.8.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.
Files changed (65) hide show
  1. package/README.md +24 -10
  2. package/bin/md2pdf.js +60 -16
  3. package/lib/address-links.js +38 -0
  4. package/lib/attributions.js +69 -0
  5. package/lib/fit.js +50 -9
  6. package/lib/italic-lines.js +27 -0
  7. package/lib/render.js +6 -0
  8. package/lib/styles.js +2 -0
  9. package/package.json +1 -1
  10. package/styles/academic.css +14 -0
  11. package/styles/classic.css +88 -2
  12. package/styles/fiendish.css +671 -0
  13. package/styles/fonts/andika/Andika-Bold.woff2 +0 -0
  14. package/styles/fonts/andika/Andika-BoldItalic.woff2 +0 -0
  15. package/styles/fonts/andika/Andika-Italic.woff2 +0 -0
  16. package/styles/fonts/andika/Andika-Regular.woff2 +0 -0
  17. package/styles/fonts/andika/OFL.txt +94 -93
  18. package/styles/fonts/bodoni-moda/OFL.txt +93 -0
  19. package/styles/fonts/bodoni-moda/bodoni-moda-latin-900-normal.woff2 +0 -0
  20. package/styles/fonts/cinzel/OFL.txt +93 -0
  21. package/styles/fonts/cinzel/cinzel-latin-400-normal.woff2 +0 -0
  22. package/styles/fonts/cinzel/cinzel-latin-700-normal.woff2 +0 -0
  23. package/styles/fonts/courier-prime/OFL.txt +93 -0
  24. package/styles/fonts/courier-prime/courier-prime-latin-400-italic.woff2 +0 -0
  25. package/styles/fonts/courier-prime/courier-prime-latin-400-normal.woff2 +0 -0
  26. package/styles/fonts/courier-prime/courier-prime-latin-700-normal.woff2 +0 -0
  27. package/styles/fonts/libre-caslon-text/OFL.txt +93 -0
  28. package/styles/fonts/libre-caslon-text/libre-caslon-text-latin-400-italic.woff2 +0 -0
  29. package/styles/fonts/libre-caslon-text/libre-caslon-text-latin-400-normal.woff2 +0 -0
  30. package/styles/fonts/libre-caslon-text/libre-caslon-text-latin-700-normal.woff2 +0 -0
  31. package/styles/fonts/literata/OFL.txt +93 -0
  32. package/styles/fonts/literata/literata-latin-400-italic.woff2 +0 -0
  33. package/styles/fonts/literata/literata-latin-400-normal.woff2 +0 -0
  34. package/styles/fonts/literata/literata-latin-700-italic.woff2 +0 -0
  35. package/styles/fonts/literata/literata-latin-700-normal.woff2 +0 -0
  36. package/styles/fonts/literata/literata-latin-ext-400-italic.woff2 +0 -0
  37. package/styles/fonts/literata/literata-latin-ext-400-normal.woff2 +0 -0
  38. package/styles/fonts/literata/literata-latin-ext-700-italic.woff2 +0 -0
  39. package/styles/fonts/literata/literata-latin-ext-700-normal.woff2 +0 -0
  40. package/styles/fonts/nunito-sans/OFL.txt +93 -0
  41. package/styles/fonts/nunito-sans/nunito-sans-latin-400-italic.woff2 +0 -0
  42. package/styles/fonts/nunito-sans/nunito-sans-latin-400-normal.woff2 +0 -0
  43. package/styles/fonts/nunito-sans/nunito-sans-latin-700-italic.woff2 +0 -0
  44. package/styles/fonts/nunito-sans/nunito-sans-latin-700-normal.woff2 +0 -0
  45. package/styles/fonts/nunito-sans/nunito-sans-latin-ext-400-italic.woff2 +0 -0
  46. package/styles/fonts/nunito-sans/nunito-sans-latin-ext-400-normal.woff2 +0 -0
  47. package/styles/fonts/nunito-sans/nunito-sans-latin-ext-700-italic.woff2 +0 -0
  48. package/styles/fonts/nunito-sans/nunito-sans-latin-ext-700-normal.woff2 +0 -0
  49. package/styles/fonts/old-standard-tt/OFL.txt +93 -0
  50. package/styles/fonts/old-standard-tt/old-standard-tt-latin-400-italic.woff2 +0 -0
  51. package/styles/fonts/old-standard-tt/old-standard-tt-latin-400-normal.woff2 +0 -0
  52. package/styles/fonts/old-standard-tt/old-standard-tt-latin-700-normal.woff2 +0 -0
  53. package/styles/gothic.css +15 -0
  54. package/styles/modern.css +62 -1
  55. package/styles/newspaper.css +899 -0
  56. package/styles/print/classic.css +1 -1
  57. package/styles/print/fiendish.css +92 -0
  58. package/styles/print/modern.css +1 -1
  59. package/styles/print/newspaper.css +95 -0
  60. package/styles/sandwake.css +14 -0
  61. package/styles/worksheet.css +10 -8
  62. package/styles/fonts/andika/andika-latin-400-italic.woff2 +0 -0
  63. package/styles/fonts/andika/andika-latin-400-normal.woff2 +0 -0
  64. package/styles/fonts/andika/andika-latin-700-italic.woff2 +0 -0
  65. package/styles/fonts/andika/andika-latin-700-normal.woff2 +0 -0
package/README.md CHANGED
@@ -6,7 +6,7 @@ Convert Markdown to beautifully styled PDFs. This is the rendering engine and ma
6
6
  - **On a Mac and comfortable with a terminal?** Install the command-line tool below. It adds a Finder right-click action and a keyboard shortcut.
7
7
  - **Building something?** Use the renderer and styles as a dependency, to make PDFs ([Using the renderer](#using-the-renderer)) or to show Markdown in your own pages ([Embedding in a web page](#embedding-in-a-web-page)).
8
8
 
9
- Supports GitHub-flavored Markdown: tables, task lists, footnotes, emoji shortcodes, syntax-highlighted code, raw HTML, GitHub alerts and Obsidian callouts (`> [!NOTE]`, `> [!tip] Custom title`), Obsidian wikilinks and embeds (`[[Note|alias]]` prints as plain text, `![[image.png]]` as an image, and an embedded note as a placeholder naming it), YAML front matter (a leading `---` block of `key: value` properties, left out of the PDF; its `title:` names the document when there is no level-one heading, `#` or `<h1>`. A leading `---` block of ordinary Markdown prints as Markdown after a divider), and page breaks (`<div class="page-break"></div>`). Collapsed `<details>` sections print open. Typed `--`, `---`, `...` and `+-` print as –, —, … and ±, and straight quotes as curly ones; `(c)`, `(r)` and `(tm)` print as typed (before 2.5 they became ©, ® and ™, so type the symbol or `&copy;`, `&reg;`, `&trade;` where you want one). Eleven print styles are included: `github`, `classic`, `academic`, `modern`, `report`, `resume`, `worksheet`, `gothic`, `sandwake`, `elvish` and `cyberpunk`.
9
+ Supports GitHub-flavored Markdown: tables, task lists, footnotes, emoji shortcodes, syntax-highlighted code, raw HTML, GitHub alerts and Obsidian callouts (`> [!NOTE]`, `> [!tip] Custom title`), Obsidian wikilinks and embeds (`[[Note|alias]]` prints as plain text, `![[image.png]]` as an image, and an embedded note as a placeholder naming it), YAML front matter (a leading `---` block of `key: value` properties, left out of the PDF; its `title:` names the document when there is no level-one heading, `#` or `<h1>`. A leading `---` block of ordinary Markdown prints as Markdown after a divider), and page breaks (`<div class="page-break"></div>`). Collapsed `<details>` sections print open. Typed `--`, `---`, `...` and `+-` print as –, —, … and ±, and straight quotes as curly ones; `(c)`, `(r)` and `(tm)` print as typed (before 2.5 they became ©, ® and ™, so type the symbol or `&copy;`, `&reg;`, `&trade;` where you want one). Thirteen print styles are included: `github`, `classic`, `academic`, `modern`, `report`, `resume`, `worksheet`, `gothic`, `sandwake`, `elvish`, `cyberpunk`, `newspaper` and `fiendish`.
10
10
 
11
11
  # Command-line tool (macOS)
12
12
 
@@ -14,7 +14,7 @@ Markdown is rendered to HTML with [markdown-it](https://github.com/markdown-it/m
14
14
 
15
15
  ## Install
16
16
 
17
- Requires Node.js and Google Chrome (Chromium, Edge or Brave also work).
17
+ Requires Node.js and Google Chrome in `/Applications` or `~/Applications` (Chromium, Edge, Brave or Chrome Canary also work; see [Usage](#usage) to use one installed elsewhere).
18
18
 
19
19
  ```sh
20
20
  ./install.sh
@@ -54,14 +54,24 @@ A `--css` file's `@import`s resolve against it too. The rules they import come b
54
54
 
55
55
  From Finder, a single file opens in Preview when done; multiple files show a notification.
56
56
 
57
+ md2pdf prints with the first of these it finds in `/Applications` or `~/Applications`: Google Chrome, Chromium, Microsoft Edge, Brave Browser, Google Chrome Canary. When the same browser is in both folders, md2pdf uses the one in `/Applications`. To use another Chrome-based browser, or one installed somewhere else, set `CHROME_PATH` to the program inside its app:
58
+
59
+ ```sh
60
+ CHROME_PATH="/path/to/Google Chrome.app/Contents/MacOS/Google Chrome" md2pdf notes.md
61
+ ```
62
+
63
+ The Quick Action and the keyboard shortcut don't load your shell profile, so they don't see a `CHROME_PATH` set there: from Finder, md2pdf looks for a browser only in `/Applications` and `~/Applications`. If yours is one of the browsers above but is installed somewhere else, move it into either folder.
64
+
65
+ A Chrome that stops responding, as it can while it updates itself, would otherwise leave a conversion waiting forever. md2pdf gives Chrome 60 seconds to print each document, then stops it and reports that it didn't respond. For a document that really takes longer, set `MD2PDF_CHROME_TIMEOUT` to a number of seconds, as the message shows. Like `CHROME_PATH`, it reaches only the `md2pdf` command, not the Quick Action or the shortcut.
66
+
57
67
  ## Styles
58
68
 
59
69
  | Style | Look |
60
70
  | --------- | ---- |
61
71
  | `github` | GitHub's Markdown rendering: sans-serif, boxed tables, GitHub syntax colors |
62
- | `classic` | Book-like: Iowan Old Style serif, justified text, small-caps headings, ruled tables, page numbers |
72
+ | `classic` | Book-like: Iowan Old Style serif (bundled Literata on computers without it), justified text, small-caps headings, ruled tables, page numbers |
63
73
  | `academic` | Journal article: Palatino, numbered sections (1, 1.1, 1.1.1), booktabs tables, journal-style footnotes |
64
- | `modern` | Clean sans-serif (Avenir Next / Segoe UI), generous whitespace, one blue accent |
74
+ | `modern` | Clean sans-serif: Avenir Next (bundled Nunito Sans on computers without it), generous whitespace, one blue accent |
65
75
  | `report` | Business or technical report: title block from the first heading, running header with the title, "Page N of M" footers, gridded tables |
66
76
  | `resume` | Compact and one-page friendly: the first heading is your name, the paragraph after it your contact line, `##` headings are ruled section dividers |
67
77
  | `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 |
@@ -69,6 +79,8 @@ From Finder, a single file opens in Preview when done; multiple files show a not
69
79
  | `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 |
70
80
  | `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 |
71
81
  | `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
+ | `newspaper` | The front page of a 1920s small-town daily: the first heading is the paper's nameplate in Grenze Gotisch blackletter and the paragraph after it the dateline, in capitals between rules (so keep that line short: volume, place, date, price); each `##` is a headline in heavy Bodoni Moda capitals, with a line in italics (`*…*`) straight after it, or after a later `#`, as its deck, while `###` headings are small section heads; justified Old Standard TT text in two columns when printed (one in Safari, which can't print columns; Firefox can leave a headline at the foot of a page or split a two-line paragraph across the columns), an image too tall for a column scaled down to fit it (Safari slices it between pages instead), one-paragraph quotes as pull quotes (with a last line that starts with a dash, `—` or `---`, as the attribution: `— The Treasurer`; type it after a blank `>` line, or straight under a quote that ends in `.`, `!`, `?`, `…` or a closing quote mark, since under any other ending the line stays part of the quote, as a sentence carried on after a dash should) and longer ones as plain text between rules, boxed notices for callouts, code blocks as telegrams in Courier Prime (all bundled), oxblood bullets, list numbers and footnote numbers, and a running head with the page number from the second page (from the CLI and Chrome; Safari and Firefox don't print running heads) |
83
+ | `fiendish` | An infernal contract drawn up in good order: Cinzel Roman capitals and justified Libre Caslon Text (both bundled), black ink and seal-wax vermilion; the first heading is the instrument's title, under "By these presents" and over a wax seal, and the paragraph after it a centred italic preamble; each `##` is a numbered clause ("Clause I."), a later `#` an addendum ("Addendum I") that starts the clauses again; ordered lists are lettered sub-clauses, (a) then (i) (Safari prints "a." and "i."); vermilion crosses for bullets, a quotation mark over quotes, double-ruled callouts, a flame for rules, framed Courier Prime code (bundled), footnotes as "The fine print"; bold italic prints as bold, as Libre Caslon has no bold italic; a running title from the second page and "Initial here" and "Page N of M" on every page (from the CLI and Chrome) |
72
84
 
73
85
  Switch the default style — used by the Finder Quick Action, the keyboard shortcut and the `md2pdf` command:
74
86
 
@@ -93,7 +105,7 @@ Register it in `STYLES` and add its page margin to `pageMargins` in `lib/styles.
93
105
  A style can bundle fonts, so it looks the same on every computer:
94
106
 
95
107
  - 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.
96
- - Check whether the font reserves its name, in the copyright lines at the top of upstream's `OFL.txt` or in the font's own copyright notice; a Fontsource or Google Fonts copy of `OFL.txt` can leave the name out. A modified font can't use a reserved name, and subsetting counts as modifying, so subset files like Fontsource's can't be bundled under it. Bundle upstream's own `.woff2` files, unchanged, and add the family's folder name to `RESERVED_NAME_FONTS` in `test/run.js` with the reason; or pick another font. IM Fell English is listed there for another reason: its files reserve the name, but Google Fonts' licence for them doesn't, and John decided that's the one that counts (#37).
108
+ - Check whether the font reserves its name, in the copyright lines at the top of upstream's `OFL.txt` or in the font's own copyright notice; a Fontsource or Google Fonts copy of `OFL.txt` can leave the name out. A modified font can't use a reserved name, and subsetting counts as modifying, so subset files like Fontsource's can't be bundled under it. Bundle upstream's own `.woff2` files, unchanged, and add the family's folder name to `RESERVED_NAME_FONTS` in `test/run.js` with the reason, as Worksheet does with SIL's Andika (#143); or pick another font. IM Fell English is listed there for another reason: its files reserve the name, but Google Fonts' licence for them doesn't, and John decided that's the one that counts (#37).
97
109
  - Declare them in the on-screen file with `@font-face`, relative to it: `src: url("fonts/<family>/<file>.woff2") format("woff2")`, with a `font-weight` and `font-style` for each face. The print file can use them without declaring them again.
98
110
  - Name each family `md2pdf <Name>`, so it can't collide with a font on a page that embeds the style. Don't use `local()`, which would bring back the differences between computers, or `font-display: optional`, which lets the browser skip the font.
99
111
  - Set the bundled family through the font variables, e.g. `--md2pdf-font: "md2pdf Andika", sans-serif`, so they can still be overridden.
@@ -140,7 +152,7 @@ A style that [bundles fonts](#adding-a-style) loads them relative to its stylesh
140
152
  | `@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 |
141
153
  | `@threepenny/md2pdf/styles/print/<name>.css` | Each style's print rules: page margins, running headers and page numbers, collapsed `<details>` sections printed open, 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. A section without a `<summary>` still shows the browser's closed arrow; to turn the arrow, remove each section's `name` and set `open` on it before printing, as the CLI does |
142
154
 
143
- `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.
155
+ `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. A paragraph that is italic from start to end gets `class="markdown-italic-line"`, which `newspaper` sets as a headline's deck. A quote's last paragraph, when it starts with a dash (`—`, `―` or `–`, which `---` and `--` print as) and some text, and isn't the quote's only block, gets `class="markdown-attribution"`, which `newspaper` sets under a pull quote. When the quote is one paragraph and its last line starts that way, that line is wrapped in a `<span>` with the same class, inside the same `<p>`; the text before it must end a sentence or a quotation (`.`, `!`, `?`, `…` or a closing quote mark) and not itself start with a dash. A link of more than 12 characters whose text is its own address (`https://example.org/tickets`, `<someone@example.org>`, or `[example.org/tickets](https://example.org/tickets)`), outside a table, gets `class="markdown-address"`. `classic`, `academic`, `gothic`, `sandwake` and `newspaper` let it break anywhere where their text is justified, so it starts on the line where it falls instead of leaving wide gaps in the line before. `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.
144
156
 
145
157
  ### Variables
146
158
 
@@ -148,17 +160,17 @@ Every style takes the same variables, set on the `.markdown-body` element. A `--
148
160
 
149
161
  | Variable | What it sets |
150
162
  | -------- | ------------ |
151
- | `--md2pdf-font-size` | The body text size; headings and smaller text scale with it. An absolute length (`pt`, `px` or `rem`), since `em` and `%` would compound. 11pt, or 10.5pt in `modern` and `report`, 10pt in `resume`, 13.5pt in `worksheet` and `elvish`, and 12pt in `gothic` and `cyberpunk` |
163
+ | `--md2pdf-font-size` | The body text size; headings and smaller text scale with it. An absolute length (`pt`, `px` or `rem`), since `em` and `%` would compound. 11pt, or 10.5pt in `modern`, `report` and `newspaper`, 10pt in `resume`, 13.5pt in `worksheet` and `elvish`, 11.5pt in `fiendish`, and 12pt in `gothic` and `cyberpunk` |
152
164
  | `--md2pdf-leading` | Line spacing: scales each line height's excess over 1. 1 as designed |
153
165
  | `--md2pdf-space` | The vertical gaps between blocks. 1 as designed |
154
166
  | `--md2pdf-background` | The document's background, white |
155
167
  | `--md2pdf-text` | Body text |
156
168
  | `--md2pdf-muted` | Secondary text, such as footnotes and captions |
157
- | `--md2pdf-accent` | The accent color: links, headings, list markers or callouts, depending on the style, and `github`'s focus rings. `gothic`'s leaf ornaments stay oxblood, `sandwake`'s horizon ornament stays rust, `elvish`'s title, `#`, `##`, `####` and `#####` headings, links, quotes, note callouts, table rules and ornaments keep their own greens and gold, and `cyberpunk`'s `##` and `####` headings, links, nested bullets, list numbers, tick boxes, table headings, the title's frame, most of each rule, the quote label, note callouts and function names in code stay teal |
169
+ | `--md2pdf-accent` | The accent color: links, headings, list markers or callouts, depending on the style, and `github`'s focus rings. `gothic`'s leaf ornaments stay oxblood, `sandwake`'s horizon ornament stays rust, `elvish`'s title, `#`, `##`, `####` and `#####` headings, links, quotes, note callouts, table rules and ornaments keep their own greens and gold, `cyberpunk`'s `##` and `####` headings, links, nested bullets, list numbers, tick boxes, table headings, the title's frame, most of each rule, the quote label, note callouts and function names in code stay teal, and in `newspaper` it marks only bullets, list and footnote numbers, the diamond in a rule and caution callouts, while keywords in code stay oxblood, and `fiendish`'s seal, quotation mark, bullet crosses and flame stay vermilion |
158
170
  | `--md2pdf-rule` | Rules, borders and table lines (every style but `github`) |
159
- | `--md2pdf-surface` | A tinted background: inline code and code blocks in `classic`, `modern`, `worksheet`, `gothic` and `elvish`, and callouts too in `classic` and `gothic`; inline code, quotes and table headings in `report`; the inside of code blocks, callouts and inline code in `sandwake`, white as designed; the title panel, inline code, code blocks, table headings and shaded table rows in `cyberpunk`. The other styles don't use it |
171
+ | `--md2pdf-surface` | A tinted background: inline code and code blocks in `classic`, `modern`, `worksheet`, `gothic` and `elvish`, and callouts too in `classic` and `gothic`; inline code, quotes and table headings in `report`; the inside of code blocks, callouts and inline code in `sandwake`, white as designed; the title panel, inline code, code blocks, table headings and shaded table rows in `cyberpunk`; inline code in `newspaper`; the inside of code blocks and inline code in `fiendish`, white as designed. The other styles don't use it |
160
172
  | `--md2pdf-font` | The body font |
161
- | `--md2pdf-heading-font` | The heading font: the body font, except in `report`, where it's Helvetica and also sets callout titles and tables, in `worksheet`, where it's Fredoka and also sets callout titles, table headings and list markers, in `gothic`, where it's Grenze Gotisch for `#`, `##` and `###` headings and the drop cap, in `sandwake`, where it's Michroma for `#` and `##` headings and the drop cap, and in `elvish`, where it's Cormorant Unicase for `#` and `##` headings and the drop cap |
173
+ | `--md2pdf-heading-font` | The heading font: the body font, except in `report`, where it's Helvetica and also sets callout titles and tables, in `worksheet`, where it's Fredoka and also sets callout titles, table headings and list markers, in `gothic`, where it's Grenze Gotisch for `#`, `##` and `###` headings and the drop cap, in `sandwake`, where it's Michroma for `#` and `##` headings and the drop cap, in `elvish`, where it's Cormorant Unicase for `#` and `##` headings and the drop cap, and in `newspaper`, where it's Bodoni Moda for `##` headlines, `#` headings after the first and callout titles (the first `#`, the nameplate, stays Grenze Gotisch), and in `fiendish`, where it's Cinzel for `#`, `##`, `####` and `#####` headings, callout titles, table headings and the fine print's heading |
162
174
  | `--md2pdf-code-font` | The code font, and in `sandwake` the small capital labels too: section and book numbers, `####` headings, table headings, callout titles and ordered-list numbers; in `cyberpunk` also keys, `###` and `######` headings, footnotes and every small label: section numbers, list numbers, table headings, callout titles and the title's, quotes' and code blocks' labels |
163
175
 
164
176
  The styles are designed for light pages; a dark page isn't supported. Page headers and footers in a PDF keep the style's own fonts and colors.
@@ -230,6 +242,8 @@ npm run demo # the embedding demo, at http://localhost:3900/demo/
230
242
 
231
243
  Set `CHROME_PATH` to use a specific browser binary.
232
244
 
245
+ A Chrome launch sometimes aborts during the run, unable to load its framework. The tests run such a launch once more, and the run ends by naming the tests it happened in.
246
+
233
247
  # License
234
248
 
235
249
  [MIT](LICENSE) © 2026 Threepenny Labs LLC
package/bin/md2pdf.js CHANGED
@@ -34,6 +34,8 @@ const STYLES = {
34
34
  sandwake: styleFiles('sandwake'),
35
35
  elvish: styleFiles('elvish'),
36
36
  cyberpunk: styleFiles('cyberpunk'),
37
+ newspaper: styleFiles('newspaper'),
38
+ fiendish: styleFiles('fiendish'),
37
39
  };
38
40
  const FALLBACK_STYLE = 'github';
39
41
  // Not STYLES[name], which is truthy for names every object inherits, such as toString.
@@ -61,13 +63,8 @@ const CONFIG_PATH =
61
63
  process.env.MD2PDF_CONFIG ??
62
64
  join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'md2pdf', 'config.json');
63
65
 
64
- const CHROME_CANDIDATES = [
65
- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
66
- '/Applications/Chromium.app/Contents/MacOS/Chromium',
67
- '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
68
- '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
69
- '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
70
- ];
66
+ // In the order md2pdf prefers them. Each app's program has the app's name.
67
+ const CHROME_APPS = ['Google Chrome', 'Chromium', 'Microsoft Edge', 'Brave Browser', 'Google Chrome Canary'];
71
68
 
72
69
  const usage = (defaultStyle) => `Usage: md2pdf [options] <file.md>...
73
70
  md2pdf --set-style <name>
@@ -88,7 +85,8 @@ Options:
88
85
 
89
86
  Environment:
90
87
  CHROME_PATH Path to a Chrome/Chromium binary to use
91
- MD2PDF_CONFIG Config file (default: ${CONFIG_PATH})`;
88
+ MD2PDF_CONFIG Config file (default: ${CONFIG_PATH})
89
+ MD2PDF_CHROME_TIMEOUT Seconds Chrome gets to print each document (default: 60)`;
92
90
 
93
91
  function readConfig() {
94
92
  if (!existsSync(CONFIG_PATH)) return {};
@@ -114,9 +112,20 @@ function unknownStyle(name) {
114
112
 
115
113
  function findChrome() {
116
114
  if (process.env.CHROME_PATH) return process.env.CHROME_PATH;
117
- const found = CHROME_CANDIDATES.find((p) => existsSync(p));
118
- if (!found) throw new Error('Could not find Chrome. Install Google Chrome or set CHROME_PATH.');
119
- return found;
115
+ // A browser in /Applications wins over the same browser in ~/Applications, but not over a browser md2pdf prefers.
116
+ const folders = ['/Applications', join(homedir(), 'Applications')];
117
+ const programs = CHROME_APPS.flatMap((app) => folders.map((folder) => join(folder, `${app}.app/Contents/MacOS/${app}`)));
118
+ const found = programs.find((p) => existsSync(p));
119
+ if (found) return found;
120
+ // The Quick Action's notification shows only the first line, and a Quick Action can't see CHROME_PATH.
121
+ throw new Error(
122
+ [
123
+ "Couldn't find Chrome in Applications. Install Google Chrome there.",
124
+ ` md2pdf looks in /Applications and ~/Applications for ${CHROME_APPS.slice(0, -1).join(', ')} or ${CHROME_APPS.at(-1)}.`,
125
+ ' To use a browser installed elsewhere, set CHROME_PATH to the program inside its app:',
126
+ ' CHROME_PATH="/path/to/Google Chrome.app/Contents/MacOS/Google Chrome" md2pdf notes.md',
127
+ ].join('\n'),
128
+ );
120
129
  }
121
130
 
122
131
  // A stylesheet's text, with its relative url()s and @imports (a style's bundled fonts, say) made absolute:
@@ -226,8 +235,9 @@ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
226
235
  // What went wrong and what to do on the first line, the only one the Quick Action's notification shows,
227
236
  // so it never suggests setting CHROME_PATH, which a Quick Action can't see. The Chrome that ran and its
228
237
  // own output go below.
229
- function chromeFailed(chrome, first, { output = '', suggestChromePath = true } = {}) {
238
+ function chromeFailed(chrome, first, { output = '', suggestChromePath = true, hint } = {}) {
230
239
  const lines = [first];
240
+ if (hint) lines.push(` ${hint}`);
231
241
  if (suggestChromePath) lines.push(' If it keeps failing, set CHROME_PATH to a different Chrome-based browser.');
232
242
  lines.push(` Chrome: ${chrome}`);
233
243
  if (output.trim()) lines.push(" Chrome's output:", ...output.trim().split('\n').map((l) => ` ${l}`));
@@ -236,6 +246,15 @@ function chromeFailed(chrome, first, { output = '', suggestChromePath = true } =
236
246
 
237
247
  const TRY_AGAIN = 'It may be updating; try again in a moment.';
238
248
 
249
+ const MAX_CHROME_TIMEOUT_SECONDS = 86400;
250
+ // How long Chrome gets to print one document before md2pdf stops it: far longer than a real print takes.
251
+ const CHROME_TIMEOUT_SECONDS = (() => {
252
+ const seconds = Number(process.env.MD2PDF_CHROME_TIMEOUT);
253
+ return seconds > 0 && seconds <= MAX_CHROME_TIMEOUT_SECONDS ? seconds : 60;
254
+ })();
255
+ // The limit the timeout message suggests trying next.
256
+ const longerTimeout = (seconds) => Math.min(Math.ceil(Math.max(seconds * 5, 300)), MAX_CHROME_TIMEOUT_SECONDS);
257
+
239
258
  function cantStart(chrome, err) {
240
259
  if (!process.env.CHROME_PATH) return chromeFailed(chrome, `Chrome couldn't start (${err.code ?? err.message}). ${TRY_AGAIN}`);
241
260
  let folder = false;
@@ -289,15 +308,40 @@ function runChrome(chrome, htmlPath, pdfPath) {
289
308
  }
290
309
  let stderr = '';
291
310
  proc.stderr.on('data', (d) => (stderr += d));
292
- // A Chrome that fails to start emits 'error' first, and main() may exit before its 'close' arrives.
293
- proc.on('error', (err) => {
311
+ let timedOut = false;
312
+ let settled = false;
313
+ const settle = () => {
314
+ if (settled) return false;
315
+ settled = true;
316
+ clearTimeout(timer);
294
317
  if (chromeProc === proc) chromeProc = null;
295
318
  removeTempDir(profile);
319
+ return true;
320
+ };
321
+ const noResponse = () => {
322
+ if (!settle()) return;
323
+ reject(
324
+ chromeFailed(chrome, `Chrome didn't respond within ${CHROME_TIMEOUT_SECONDS} second${CHROME_TIMEOUT_SECONDS === 1 ? '' : 's'}, so md2pdf stopped it. ${TRY_AGAIN}`, {
325
+ output: stderr,
326
+ hint: CHROME_TIMEOUT_SECONDS < MAX_CHROME_TIMEOUT_SECONDS && `If the document is just slow to print, give Chrome longer: MD2PDF_CHROME_TIMEOUT=${longerTimeout(CHROME_TIMEOUT_SECONDS)} md2pdf notes.md`,
327
+ }),
328
+ );
329
+ };
330
+ // A Chrome that stalls, as it can while it updates itself, never exits on its own. SIGKILL, as for
331
+ // an interrupt; 'close' also waits for Chrome's helpers to let go of stderr, so don't wait on it forever.
332
+ const timer = setTimeout(() => {
333
+ timedOut = true;
334
+ proc.kill('SIGKILL');
335
+ setTimeout(noResponse, 5000).unref();
336
+ }, CHROME_TIMEOUT_SECONDS * 1000);
337
+ // A Chrome that fails to start emits 'error' first, and main() may exit before its 'close' arrives.
338
+ proc.on('error', (err) => {
339
+ if (!settle()) return;
296
340
  reject(cantStart(chrome, err));
297
341
  });
298
342
  proc.on('close', (code, signal) => {
299
- if (chromeProc === proc) chromeProc = null;
300
- removeTempDir(profile);
343
+ if (timedOut) return noResponse();
344
+ if (!settle()) return;
301
345
  if (code === 0 && existsSync(pdfPath)) resolvePromise();
302
346
  else if (code === 0) reject(chromeFailed(chrome, `Chrome quit without printing. ${TRY_AGAIN}`, { output: stderr }));
303
347
  else {
@@ -0,0 +1,38 @@
1
+ // A link of more than 12 characters whose text is its own address, such as https://example.org/tickets,
2
+ // <secretary@example.org> or [example.org/tickets](https://example.org/tickets), gets
3
+ // class="markdown-address", so a justified style can let it break anywhere: unhyphenated (#149), it would
4
+ // otherwise drop whole to the next line and leave wide gaps in the line before. CSS alone can't tell it from
5
+ // a link with words for text, such as [page two](#two), which must never break mid-word. A shorter address
6
+ // stays whole: dropping it leaves a gap no wider than a long word does. Links in tables aren't marked:
7
+ // lib/fit.js breaks those at slashes and dots when the table needs it.
8
+
9
+ const LONGEST_WHOLE = 12;
10
+
11
+ // The address as it would be written out: no mailto:, no scheme, no slash at the end.
12
+ const bare = (href) => href.replace(/^mailto:/i, '').replace(/^[a-z][a-z\d+.-]*:\/\//i, '').replace(/\/$/, '');
13
+
14
+ export default function addressLinks(md) {
15
+ md.core.ruler.push('address_links', (state) => {
16
+ let cells = 0;
17
+ for (const block of state.tokens) {
18
+ if (block.type === 'td_open' || block.type === 'th_open') cells++;
19
+ if (block.type === 'td_close' || block.type === 'th_close') cells--;
20
+ if (block.type !== 'inline' || cells > 0) continue;
21
+ const children = block.children;
22
+ for (let i = 0; i < children.length; i++) {
23
+ if (children[i].type !== 'link_open') continue;
24
+ const link = children[i];
25
+ let close = i + 1;
26
+ while (close < children.length && children[close].type !== 'link_close') close++;
27
+ const inside = children.slice(i + 1, close);
28
+ i = close;
29
+ const href = link.attrGet('href') ?? '';
30
+ // A link within the document is no address, and idPrefix may already have changed it.
31
+ if (!inside.length || inside.some((t) => t.type !== 'text') || href.startsWith('#')) continue;
32
+ const text = inside.map((t) => t.content).join('');
33
+ const auto = link.markup === 'linkify' || link.markup === 'autolink';
34
+ if (Array.from(text).length > LONGEST_WHOLE && (auto || bare(text) === bare(href))) link.attrJoin('class', 'markdown-address');
35
+ }
36
+ }
37
+ });
38
+ }
@@ -0,0 +1,69 @@
1
+ // A quote's attribution, a dash and a name at its end (`— The Treasurer`; typography has already turned
2
+ // `---` and `--` into an em and an en dash), gets class="markdown-attribution", so a style can set it
3
+ // apart: Newspaper keeps a quote of one block and its attribution a pull quote. When it's the quote's last
4
+ // paragraph, after a blank `>` line, the paragraph gets the class. When it's the last line of the quote's
5
+ // only paragraph, that line is wrapped in a span with the class, so the paragraph stays one and a style
6
+ // that ignores the class lays it out as before. CSS alone can't tell an attribution from other text, since
7
+ // it can't see the text.
8
+
9
+ const DASH = /^\s*[—―–]/;
10
+ const NAMED = /^\s*[—―–]\s*\S/;
11
+ // The end of a sentence or of a quotation: a line that follows one isn't the rest of its sentence.
12
+ const ENDED = /[.!?…”’"'»]\s*$/;
13
+
14
+ // The dash must be plain text, not bold or linked; the name after it may be italic.
15
+ function named(children) {
16
+ const first = children[0];
17
+ return first?.type === 'text' && DASH.test(first.content) && NAMED.test(children.map((child) => child.content).join(''));
18
+ }
19
+
20
+ // Wraps the paragraph's last line in a span when it's an attribution. A last line that starts with a dash
21
+ // is often something else, so the text before it must end a sentence or a quotation (`for an hour` /
22
+ // `— and then I laughed` is one sentence) and must not itself start with a dash (dialogue). The line break
23
+ // before it must be outside any Markdown emphasis or link, or the span would open inside an <em> and close
24
+ // outside it.
25
+ function markLastLine(state, children) {
26
+ let at = -1;
27
+ let depth = 0;
28
+ let depthAt = 0;
29
+ children.forEach((child, i) => {
30
+ depth += child.nesting;
31
+ if (child.type === 'softbreak' || child.type === 'hardbreak') {
32
+ at = i;
33
+ depthAt = depth;
34
+ }
35
+ });
36
+ if (at === -1 || depthAt !== 0 || !named(children.slice(at + 1))) return;
37
+ const before = children.slice(0, at);
38
+ if (!ENDED.test(before.map((child) => child.content).join('')) || (before[0].type === 'text' && DASH.test(before[0].content))) return;
39
+ const open = new state.Token('span_open', 'span', 1);
40
+ open.attrSet('class', 'markdown-attribution');
41
+ children.splice(at + 1, 0, open);
42
+ children.push(new state.Token('span_close', 'span', -1));
43
+ }
44
+
45
+ export default function attributions(md) {
46
+ md.core.ruler.push('attributions', (state) => {
47
+ const quotes = [];
48
+ for (const token of state.tokens) {
49
+ if (token.type === 'blockquote_close') {
50
+ const { open, blocks, last, inline } = quotes.pop();
51
+ // A callout is a blockquote retagged as a div.
52
+ if (open.tag !== 'blockquote' || last?.type !== 'paragraph_open' || !inline) continue;
53
+ // A paragraph that starts with a dash is an attribution only after another block: alone, it's the quote.
54
+ if (blocks === 1) markLastLine(state, inline.children);
55
+ else if (named(inline.children)) last.attrJoin('class', 'markdown-attribution');
56
+ continue;
57
+ }
58
+ const quote = quotes.at(-1);
59
+ if (quote && token.level === quote.open.level + 1 && token.nesting !== -1) {
60
+ quote.blocks++;
61
+ quote.last = token;
62
+ quote.inline = null;
63
+ } else if (quote && token.type === 'inline' && token.level === quote.open.level + 2) {
64
+ quote.inline = token;
65
+ }
66
+ if (token.type === 'blockquote_open') quotes.push({ open: token, blocks: 0, last: null, inline: null });
67
+ }
68
+ });
69
+ }
package/lib/fit.js CHANGED
@@ -61,6 +61,12 @@ export function fitFormulas(root = document) {
61
61
  // A table that fits isn't written to, so it prints as it did. If the printed width can't be read, nothing
62
62
  // changes. Running it again is harmless.
63
63
  //
64
+ // A style that prints in columns fits its tables to the page's width all the same, and runs a list, quote
65
+ // or other block that holds one across the columns. It names its columns in --md2pdf-print-columns and
66
+ // --md2pdf-print-column-gap on .markdown-body, since its print rules aren't on while this runs. Then each
67
+ // of the document's own blocks whose tables all fit one printed column as they are, with no word broken,
68
+ // is marked data-md2pdf-in-column, for the style to leave in its column.
69
+ //
64
70
  // Self-contained, so the CLI can put its source in the page.
65
71
  export function fitTables(root = document) {
66
72
  const FIT = 'data-md2pdf-fit';
@@ -81,6 +87,8 @@ export function fitTables(root = document) {
81
87
  parent.normalize();
82
88
  }
83
89
  for (const el of root.querySelectorAll(`[${FIT}]`)) unset(el, 'overflow-wrap', 'font-size');
90
+ const IN_COLUMN = 'data-md2pdf-in-column';
91
+ for (const el of root.querySelectorAll(`[${IN_COLUMN}]`)) el.removeAttribute(IN_COLUMN);
84
92
  const tables = [...root.querySelectorAll('table')];
85
93
  if (!tables.length) return;
86
94
 
@@ -143,24 +151,57 @@ export function fitTables(root = document) {
143
151
  box.remove();
144
152
  if (!(column > 0)) return;
145
153
 
154
+ // How far a table reaches past its box.
155
+ const reach = (table) => {
156
+ const parent = table.parentElement;
157
+ const s = getComputedStyle(parent);
158
+ const edge = parent.getBoundingClientRect().right - parseFloat(s.borderRightWidth) - parseFloat(s.paddingRight);
159
+ let right = table.getBoundingClientRect().right;
160
+ for (const row of table.rows) right = Math.max(right, row.getBoundingClientRect().right);
161
+ return right - edge;
162
+ };
163
+
164
+ // Marks the blocks that can stay in a printed column. Runs before any table is fitted, so each is
165
+ // measured as it is.
166
+ const markInColumn = (body) => {
167
+ const blocks = [...body.children].filter((block) => block.localName !== 'table' && block.querySelector('table'));
168
+ if (!blocks.length || !getComputedStyle(body).getPropertyValue('--md2pdf-print-columns').trim()) return;
169
+ // The browser works out the column's width, which depends on how many fit the page.
170
+ const columns = document.createElement('div');
171
+ columns.style.cssText =
172
+ 'visibility: hidden; height: 0; margin: 0; padding: 0; border: 0; columns: var(--md2pdf-print-columns); column-gap: var(--md2pdf-print-column-gap, normal)';
173
+ const one = columns.appendChild(document.createElement('div'));
174
+ body.append(columns);
175
+ const [all, width] = [columns, one].map((el) => el.getBoundingClientRect().width);
176
+ columns.remove();
177
+ // One column is the page's width, where a block that spans it prints the same.
178
+ if (!(width > 0 && width < all - 1)) return;
179
+ const before = body.getAttribute('style');
180
+ body.style.boxSizing = 'content-box';
181
+ // 2px narrower than the column, so a rounding difference from the printed column's width can't push
182
+ // a table that just fits here past its column there: one past the page's edge shrinks every page.
183
+ body.style.width = `${width - 2}px`;
184
+ try {
185
+ const fitting = blocks.filter((block) =>
186
+ [...block.querySelectorAll('table')].every((table) => table.getClientRects().length && table.parentElement && !(reach(table) > 1)),
187
+ );
188
+ for (const block of fitting) block.setAttribute(IN_COLUMN, '');
189
+ } finally {
190
+ restore(body, before);
191
+ }
192
+ };
193
+
146
194
  const style = html.getAttribute('style');
147
195
  html.style.width = `${column}px`;
148
196
  try {
197
+ for (const body of new Set(tables.map((table) => table.closest('.markdown-body')))) if (body) markInColumn(body);
149
198
  for (const table of tables) fit(table);
150
199
  } finally {
151
200
  restore(html, style);
152
201
  }
153
202
 
154
203
  function fit(table) {
155
- // How far the table reaches past its box.
156
- const past = () => {
157
- const parent = table.parentElement;
158
- const s = getComputedStyle(parent);
159
- const edge = parent.getBoundingClientRect().right - parseFloat(s.borderRightWidth) - parseFloat(s.paddingRight);
160
- let right = table.getBoundingClientRect().right;
161
- for (const row of table.rows) right = Math.max(right, row.getBoundingClientRect().right);
162
- return right - edge;
163
- };
204
+ const past = () => reach(table);
164
205
  // A table is fitted when it runs past its box by more than a pixel: less only reaches into the page
165
206
  // margin, and the slack keeps a rounding difference from the printed page's width from changing a table
166
207
  // that fits. Fitted, it stays inside its box.
@@ -0,0 +1,27 @@
1
+ // A paragraph that is italic from start to end, such as `*Third disappearance since August*`, gets
2
+ // class="markdown-italic-line", so a style can set it apart: Newspaper makes one under a ## headline its
3
+ // deck. CSS alone can't tell it from a paragraph that only begins with an italic word, since it can't see
4
+ // the plain text beside the italic.
5
+
6
+ export default function italicLines(md) {
7
+ md.core.ruler.push('italic_lines', (state) => {
8
+ const tokens = state.tokens;
9
+ for (let i = 1; i < tokens.length; i++) {
10
+ if (tokens[i].type !== 'inline' || tokens[i - 1].type !== 'paragraph_open') continue;
11
+ const children = tokens[i].children;
12
+ if (children.length < 3 || children[0].type !== 'em_open' || children.at(-1).type !== 'em_close') continue;
13
+ // The first italic run must close only at the end: `*one* and *two*` starts and ends in italic but
14
+ // has plain text between.
15
+ let depth = 0;
16
+ let whole = true;
17
+ for (let k = 0; k < children.length - 1; k++) {
18
+ if (children[k].type === 'em_open') depth++;
19
+ else if (children[k].type === 'em_close' && --depth === 0) {
20
+ whole = false;
21
+ break;
22
+ }
23
+ }
24
+ if (whole) tokens[i - 1].attrJoin('class', 'markdown-italic-line');
25
+ }
26
+ });
27
+ }
package/lib/render.js CHANGED
@@ -10,6 +10,9 @@ import ids, { ID_PREFIX } from './ids.js';
10
10
  import mathRules from './math.js';
11
11
  import { PAPER, isPageSize } from './page-size.js';
12
12
  import taskLists from './tasklists.js';
13
+ import italicLines from './italic-lines.js';
14
+ import addressLinks from './address-links.js';
15
+ import attributions from './attributions.js';
13
16
  import typography from './typography.js';
14
17
  import wikilinks from './wikilinks.js';
15
18
 
@@ -127,6 +130,9 @@ export function createRenderer({ hljs, math, html = true, idPrefix = '', highlig
127
130
  .use(footnote)
128
131
  .use(footnotes, { idPrefix })
129
132
  .use(taskLists)
133
+ .use(italicLines)
134
+ .use(addressLinks)
135
+ .use(attributions)
130
136
  .use(typography)
131
137
  .use(emoji)
132
138
  .use(callouts)
package/lib/styles.js CHANGED
@@ -13,4 +13,6 @@ export const pageMargins = {
13
13
  sandwake: '1in 0.9in 0.9in',
14
14
  elvish: '1.1in 1.25in 1in',
15
15
  cyberpunk: '1in 0.75in 0.9in',
16
+ newspaper: '1in 0.75in 0.8in',
17
+ fiendish: '1in 1.1in 0.95in',
16
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threepenny/md2pdf",
3
- "version": "2.6.0",
3
+ "version": "2.8.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,8 @@
33
33
  color: var(--md2pdf-text);
34
34
  /* A long web address wraps at the margin instead of making Chrome shrink the page to fit it. */
35
35
  overflow-wrap: break-word;
36
+ /* Whether a long address may break anywhere, set beside each text-align: only in justified text. */
37
+ --md2pdf-address-break: normal;
36
38
  font-kerning: normal;
37
39
  counter-reset: h2 figure;
38
40
  -webkit-print-color-adjust: exact;
@@ -42,6 +44,7 @@
42
44
  .markdown-body p,
43
45
  .markdown-body li {
44
46
  text-align: justify;
47
+ --md2pdf-address-break: break-all;
45
48
  hyphens: auto;
46
49
  orphans: 2;
47
50
  widows: 2;
@@ -74,6 +77,7 @@
74
77
  font-size: calc(17 / 11 * var(--md2pdf-font-size));
75
78
  font-weight: normal;
76
79
  text-align: center;
80
+ --md2pdf-address-break: normal;
77
81
  margin: 0 0 calc(1.5em * var(--md2pdf-space));
78
82
  }
79
83
  .markdown-body h1:not(:first-child) {
@@ -122,10 +126,16 @@
122
126
  .markdown-body a {
123
127
  color: var(--md2pdf-accent);
124
128
  text-decoration: none;
129
+ hyphens: manual;
125
130
  }
126
131
  .markdown-body a.header-anchor {
127
132
  display: none;
128
133
  }
134
+ /* A long address in justified text may break anywhere, without a hyphen, so it starts on the line where it
135
+ falls rather than dropping whole and leaving wide gaps in the line before (#150). */
136
+ .markdown-body a.markdown-address {
137
+ word-break: var(--md2pdf-address-break);
138
+ }
129
139
 
130
140
  /* Lists */
131
141
 
@@ -206,6 +216,7 @@
206
216
  font-weight: bold;
207
217
  letter-spacing: 0.03em;
208
218
  text-align: left;
219
+ --md2pdf-address-break: normal;
209
220
  hyphens: manual;
210
221
  }
211
222
  .markdown-body .markdown-alert-title .octicon {
@@ -227,6 +238,7 @@
227
238
  .markdown-body code,
228
239
  .markdown-body kbd {
229
240
  font-family: var(--md2pdf-code-font);
241
+ hyphens: manual;
230
242
  font-size: 0.84em;
231
243
  }
232
244
  .markdown-body kbd {
@@ -326,6 +338,8 @@
326
338
  .markdown-body td {
327
339
  padding: 0.3em 0.8em;
328
340
  text-align: left;
341
+ --md2pdf-address-break: normal;
342
+ hyphens: manual;
329
343
  }
330
344
  .markdown-body th {
331
345
  font-weight: normal;