printdown 1.0.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/LICENSE +21 -0
- package/README.md +303 -0
- package/dist/chunk-HX2CR2SJ.js +1006 -0
- package/dist/chunk-HX2CR2SJ.js.map +1 -0
- package/dist/chunk-INBZBWSZ.js +868 -0
- package/dist/chunk-INBZBWSZ.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +71 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +165 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/themes/default/index.d.ts +40 -0
- package/dist/themes/default/index.js +31 -0
- package/dist/themes/default/index.js.map +1 -0
- package/dist/themes/default/style.css +2133 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sota Misaki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# Printdown
|
|
2
|
+
|
|
3
|
+
A customizable Markdown renderer for generating beautifully styled PDFs and images with CSS.
|
|
4
|
+
|
|
5
|
+
Printdown turns Markdown into clean, publication-grade PDFs, PNGs, JPEGs, and WebPs using Playwright (Chromium), markdown-it, and Shiki for syntax highlighting.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Modern Visual Language**: Clean, minimal, editorial default theme with crisp typography and vibrant accents.
|
|
10
|
+
- **Multi-Format Output**: Generate A4 formatted **PDF**, high-resolution **PNG** (2x Retina), compressed **JPEG**, and modern **WebP**.
|
|
11
|
+
- **Multi-Page Image Export**: Export individual page images sliced to standard PDF/A4 proportions (`--pages` or `pages: true`).
|
|
12
|
+
- **Marker Pen Highlights**: Physical marker pen effect with `==text==` (blue) and `=={amber}text==` (amber).
|
|
13
|
+
- **Badges & Labels**: Badges with `<Badge>` / `[badge:...]` supporting `solid`, `soft`, and `outline` variants.
|
|
14
|
+
- **Keyboard Keys**: Styled keyboard keys with `<Kbd icon="command" />` / `[kbd:...]` and embedded icon masks.
|
|
15
|
+
- **Code Highlighting**: Syntax highlighting powered by **Shiki** with dark theme support.
|
|
16
|
+
- **Custom CSS & Variables**: Full control over styling by overriding OKLCH CSS variables or injecting custom CSS.
|
|
17
|
+
- **Japanese & Multilingual Typography**: Balanced typography for Japanese and English mixed documents with robust fallbacks.
|
|
18
|
+
- **CLI & Node.js API**: Use via command-line interface or programmatic TypeScript/JavaScript API.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add printdown
|
|
24
|
+
# or
|
|
25
|
+
npm install printdown
|
|
26
|
+
# or
|
|
27
|
+
yarn add printdown
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Make sure Playwright Chromium is installed:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx playwright install chromium
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### Programmatic API
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { render, renderFile, renderPages } from "printdown";
|
|
42
|
+
|
|
43
|
+
// Render a Markdown string to PDF
|
|
44
|
+
await render("# Hello, world!\n\nThis is a **printdown** document with ==highlight==.", {
|
|
45
|
+
output: "document.pdf",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Render a Markdown file to PNG
|
|
49
|
+
const pngBuffer = await renderFile("./document.md", {
|
|
50
|
+
output: "./document.png",
|
|
51
|
+
format: "png",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Render a Markdown file to WebP
|
|
55
|
+
const webpBuffer = await renderFile("./document.md", {
|
|
56
|
+
output: "./document.webp",
|
|
57
|
+
format: "webp",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Render into multiple page images (A4 sized pages: document-1.png, document-2.png...)
|
|
61
|
+
const pageBuffers = await renderPages(markdown, {
|
|
62
|
+
output: "./document.png",
|
|
63
|
+
format: "png",
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Command Line Interface (CLI)
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Render document.md to document.pdf (default)
|
|
71
|
+
npx printdown document.md
|
|
72
|
+
|
|
73
|
+
# Specify output file and format (pdf, png, jpeg, webp)
|
|
74
|
+
npx printdown document.md -o output.png -f png
|
|
75
|
+
npx printdown document.md -o output.webp -f webp
|
|
76
|
+
|
|
77
|
+
# Export multiple page images matching PDF/A4 dimensions
|
|
78
|
+
npx printdown document.md -o page.png -f png --pages
|
|
79
|
+
|
|
80
|
+
# Set image output scale (e.g. 1x, 2x, 3x)
|
|
81
|
+
npx printdown document.md -o output-3x.png -f png --scale 3
|
|
82
|
+
|
|
83
|
+
# Apply custom CSS
|
|
84
|
+
npx printdown document.md -o output.pdf --css ./custom.css
|
|
85
|
+
|
|
86
|
+
# Customize width and image quality
|
|
87
|
+
npx printdown document.md -o output.jpeg -f jpeg --width 1000 --quality 95
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Marker Pen / Highlight Syntax
|
|
91
|
+
|
|
92
|
+
Printdown includes a physical marker pen style that paints a translucent accent under the lower portion of the text across multi-line breaks.
|
|
93
|
+
|
|
94
|
+
### Default Blue Highlight
|
|
95
|
+
|
|
96
|
+
```markdown
|
|
97
|
+
This is ==essential text== highlighted in blue.
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Amber Highlight
|
|
101
|
+
|
|
102
|
+
```markdown
|
|
103
|
+
This is =={amber}warning text== highlighted in warm amber.
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Highlights with Inline Code
|
|
107
|
+
|
|
108
|
+
```markdown
|
|
109
|
+
Run ==`pnpm add printdown`== to install.
|
|
110
|
+
Warning: =={amber}`sudo rm -rf /`== is destructive.
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Badges
|
|
114
|
+
|
|
115
|
+
Printdown provides status and category badges, available via `<Badge>` HTML tags or concise Markdown syntax.
|
|
116
|
+
|
|
117
|
+
### Component Syntax
|
|
118
|
+
|
|
119
|
+
```markdown
|
|
120
|
+
<Badge>Solid</Badge>
|
|
121
|
+
<Badge variant="soft">Soft</Badge>
|
|
122
|
+
<Badge variant="outline">Outline</Badge>
|
|
123
|
+
|
|
124
|
+
<!-- Custom Colors (blue, amber, neutral) -->
|
|
125
|
+
|
|
126
|
+
<Badge color="amber">Amber Solid</Badge>
|
|
127
|
+
<Badge variant="soft" color="amber">Amber Soft</Badge>
|
|
128
|
+
<Badge variant="outline" color="neutral">v1.2.0</Badge>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Markdown Inline Syntax
|
|
132
|
+
|
|
133
|
+
```markdown
|
|
134
|
+
[badge:New]
|
|
135
|
+
[badge(soft):Beta]
|
|
136
|
+
[badge(outline):v1.0]
|
|
137
|
+
[badge(amber):Warning]
|
|
138
|
+
[badge(soft,amber):Notice]
|
|
139
|
+
[badge(outline,amber):Draft]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Keyboard Keys (Kbd)
|
|
143
|
+
|
|
144
|
+
Display crisp, physical-styled keyboard shortcuts.
|
|
145
|
+
|
|
146
|
+
### Component Syntax
|
|
147
|
+
|
|
148
|
+
```markdown
|
|
149
|
+
Press <Kbd icon="command" /> + <Kbd>K</Kbd> to open the command palette.
|
|
150
|
+
Use <Kbd icon="arrow-up" /> or <Kbd icon="arrow-down" /> to navigate.
|
|
151
|
+
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Supported Icons
|
|
155
|
+
|
|
156
|
+
`command` (or `cmd`), `arrow-up` (or `up`), `arrow-down` (or `down`), `arrow-left` (or `left`), `arrow-right` (or `right`), `shift`, `option` (or `alt`), `enter` (or `return`).
|
|
157
|
+
|
|
158
|
+
### Markdown Inline Syntax
|
|
159
|
+
|
|
160
|
+
```markdown
|
|
161
|
+
[kbd(command)] + [kbd:K]
|
|
162
|
+
[kbd(shift)] + [kbd:Tab]
|
|
163
|
+
[kbd:Enter]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## CSS Customization
|
|
167
|
+
|
|
168
|
+
Printdown loads styles in a predictable cascade:
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
Default Theme CSS -> User CSS
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
You can customize the appearance by overriding CSS variables or providing custom rules:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { render } from "printdown";
|
|
178
|
+
|
|
179
|
+
await render(markdown, {
|
|
180
|
+
output: "output.pdf",
|
|
181
|
+
css: `
|
|
182
|
+
:root {
|
|
183
|
+
--printdown-primary: oklch(0.5 0.2 140);
|
|
184
|
+
--printdown-font-sans: 'Helvetica Neue', sans-serif;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.printdown h1 {
|
|
188
|
+
border-bottom: 2px solid var(--printdown-primary);
|
|
189
|
+
}
|
|
190
|
+
`,
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
You can also pass a path to an external CSS file:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
await render(markdown, {
|
|
198
|
+
output: "output.pdf",
|
|
199
|
+
css: "./styles/custom.css",
|
|
200
|
+
});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Available CSS Variables
|
|
204
|
+
|
|
205
|
+
| Variable | Description |
|
|
206
|
+
| :------------------------ | :----------------------------------------- |
|
|
207
|
+
| `--printdown-primary` | Main accent color (default: Deep blue) |
|
|
208
|
+
| `--printdown-bg` | Page background color (default: `#ffffff`) |
|
|
209
|
+
| `--printdown-text` | Body text color |
|
|
210
|
+
| `--printdown-text-strong` | Bold and heading text color |
|
|
211
|
+
| `--printdown-text-muted` | Subtle secondary text color |
|
|
212
|
+
| `--printdown-border` | Border separator color |
|
|
213
|
+
| `--printdown-font-sans` | Sans-serif font stack |
|
|
214
|
+
| `--printdown-font-mono` | Monospace code font stack |
|
|
215
|
+
|
|
216
|
+
## API Reference
|
|
217
|
+
|
|
218
|
+
### `render(markdown, options)`
|
|
219
|
+
|
|
220
|
+
Renders a Markdown string into a PDF, PNG, JPEG, or WebP buffer (or `Buffer[]` when `pages: true`).
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
function render(markdown: string, options?: RenderOptions): Promise<Buffer | Buffer[]>;
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### `RenderOptions`
|
|
227
|
+
|
|
228
|
+
- `output?: string`: File path to write output to. In `pages` mode, appends `-1`, `-2` or replaces `%d`.
|
|
229
|
+
- `format?: 'pdf' | 'png' | 'jpeg' | 'webp'`: Target format (default inferred from `output` extension, or `'pdf'`).
|
|
230
|
+
- `pages?: boolean`: Export individual page images matching PDF/A4 dimensions.
|
|
231
|
+
- `pageHeight?: number`: Height in pixels for each page when in `pages` mode.
|
|
232
|
+
- `pageMarginTop?: number`: Top margin in pixels for each page in `pages` mode.
|
|
233
|
+
- `pageMarginBottom?: number`: Bottom margin in pixels for each page in `pages` mode.
|
|
234
|
+
- `theme?: 'default' | boolean | Theme`: Theme to apply. Set to `false` to disable default theme.
|
|
235
|
+
- `css?: string | string[]`: Custom CSS string or path to CSS file(s).
|
|
236
|
+
- `title?: string`: HTML document `<title>`.
|
|
237
|
+
- `baseUrl?: string`: Base URL / directory for resolving relative images.
|
|
238
|
+
- `scale?: number`: Image resolution scale multiplier (e.g. 1 for 1x, 2 for 2x retina, 3 for 3x, default: 2).
|
|
239
|
+
- `width?: number`: Viewport width in pixels (default: 820 for PDF/pages, 1200 for single image).
|
|
240
|
+
- `height?: number`: Viewport height in pixels (default: 800).
|
|
241
|
+
- `deviceScaleFactor?: number`: Alias for `scale`.
|
|
242
|
+
- `quality?: number`: Quality for JPEG and WebP output (0-100, default: 90).
|
|
243
|
+
- `pdf?: PDFExportOptions`: Playwright PDF options (margin, format, landscape, etc.).
|
|
244
|
+
- `image?: ImageExportOptions`: Playwright screenshot options (fullPage, clip, etc.).
|
|
245
|
+
- `markdown?: MarkdownRenderOptions`: Markdown parser and Shiki highlighter options.
|
|
246
|
+
|
|
247
|
+
### `renderPages(markdown, options)`
|
|
248
|
+
|
|
249
|
+
Renders Markdown into an array of page image buffers.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
function renderPages(markdown: string, options?: RenderOptions): Promise<Buffer[]>;
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### `renderFile(filePath, options)`
|
|
256
|
+
|
|
257
|
+
Reads a Markdown file from disk and renders it.
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
function renderFile(filePath: string, options?: RenderFileOptions): Promise<Buffer | Buffer[]>;
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### `renderFilePages(filePath, options)`
|
|
264
|
+
|
|
265
|
+
Reads a Markdown file from disk and renders it to multiple page images.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
function renderFilePages(filePath: string, options?: RenderFileOptions): Promise<Buffer[]>;
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### `renderToHtml(markdown, options)`
|
|
272
|
+
|
|
273
|
+
Compiles Markdown into an HTML document with theme and user styles without launching Chromium.
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
function renderToHtml(markdown: string, options?: RenderOptions): Promise<string>;
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## CLI Options
|
|
280
|
+
|
|
281
|
+
```text
|
|
282
|
+
Usage:
|
|
283
|
+
printdown <file> [options]
|
|
284
|
+
|
|
285
|
+
Options:
|
|
286
|
+
-o, --output <path> Output file path (e.g., output.pdf, output.png, output.webp)
|
|
287
|
+
-f, --format <format> Output format (pdf, png, jpeg, webp)
|
|
288
|
+
-p, --pages Export multiple page images matching PDF/A4 page size
|
|
289
|
+
-s, --scale <scale> Image resolution scale multiplier (e.g., 1, 2, 3)
|
|
290
|
+
-c, --css <path> Path to custom CSS file or inline CSS string
|
|
291
|
+
-t, --theme <theme> Theme to use (default: 'default', 'false' to disable)
|
|
292
|
+
--width <width> Viewport width in pixels
|
|
293
|
+
--page-height <height> Page height in pixels for pages mode
|
|
294
|
+
--margin-top <margin> Top margin in pixels for pages mode
|
|
295
|
+
--margin-bottom <margin> Bottom margin in pixels for pages mode
|
|
296
|
+
--quality <quality> JPEG / WebP image quality (0-100, default: 90)
|
|
297
|
+
-v, --version Display version number
|
|
298
|
+
-h, --help Display this message
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|