@cenk1cenk2/md-printer 2.20.12 → 3.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/README.md +332 -48
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorate.mjs +1 -2
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateMetadata.mjs +1 -2
- package/dist/_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/decorateParam.mjs +8 -0
- package/dist/commands/index.mjs +136 -257
- package/dist/components/Date.svelte +1 -0
- package/dist/components/Markdown.svelte +20 -0
- package/dist/components/Nodes.svelte +32 -0
- package/dist/components/Page.svelte +20 -0
- package/dist/components/PageBreak.svelte +5 -0
- package/dist/components/PageNumber.svelte +1 -0
- package/dist/components/SignatureBlock.svelte +56 -0
- package/dist/components/Title.svelte +1 -0
- package/dist/components/TotalPages.svelte +1 -0
- package/dist/components/index.ts +8 -0
- package/dist/constants/file.constants.mjs +1 -8
- package/dist/constants/index.mjs +3 -4
- package/dist/constants/template.constants.mjs +48 -10
- package/dist/interfaces/commands/index.mjs +1 -1
- package/dist/interfaces/commands/run.interface.mjs +1 -1
- package/dist/interfaces/index.mjs +1 -1
- package/dist/interfaces/markdown.interface.mjs +1 -0
- package/dist/interfaces/renderer.interface.mjs +1 -0
- package/dist/interfaces/session.interface.mjs +1 -0
- package/dist/interfaces/signature.interface.mjs +1 -0
- package/dist/interfaces/template.interface.mjs +1 -0
- package/dist/services/i18n.service.mjs +4 -8
- package/dist/services/index.mjs +13 -2
- package/dist/services/loopback.mjs +18 -0
- package/dist/services/markdown.service.mjs +123 -0
- package/dist/services/printer.module.mjs +41 -0
- package/dist/services/printer.service.mjs +171 -0
- package/dist/services/renderer/browser.mjs +41 -0
- package/dist/services/renderer/browser.service.mjs +56 -0
- package/dist/services/renderer/renderer.service.mjs +198 -0
- package/dist/services/session/Preview.svelte +238 -0
- package/dist/services/session/preview.service.mjs +187 -0
- package/dist/services/session/session.service.mjs +115 -0
- package/dist/services/signature/adapters/a-trust.adapter.mjs +106 -0
- package/dist/services/signature/adapters/a-trust.html +77 -0
- package/dist/services/signature/index.mjs +4 -0
- package/dist/services/signature/signature.adapter.mjs +4 -0
- package/dist/services/signature/signature.service.mjs +95 -0
- package/dist/services/template/Document.svelte +21 -0
- package/dist/services/template/Margin.svelte +15 -0
- package/dist/services/template/assets.mjs +127 -0
- package/dist/services/template/render.entry.ts +32 -0
- package/dist/services/template/svelte.plugin.mjs +66 -0
- package/dist/services/template/template.service.mjs +211 -0
- package/oclif.manifest.json +64 -33
- package/package.json +70 -35
- package/templates/default/Template.svelte +83 -0
- package/templates/default/settings.json +1 -3
- package/templates/invoice/Template.svelte +247 -0
- package/templates/invoice/components/Client.svelte +42 -0
- package/templates/invoice/components/Company.svelte +41 -0
- package/templates/invoice/components/Items.svelte +66 -0
- package/templates/invoice/components/Notes.svelte +21 -0
- package/templates/invoice/components/Payment.svelte +25 -0
- package/templates/invoice/components/Signature.svelte +34 -0
- package/templates/invoice/components/Totals.svelte +47 -0
- package/templates/invoice/i18n/de.yaml +6 -0
- package/templates/invoice/i18n/en.yaml +6 -0
- package/templates/invoice/round.js +2 -0
- package/templates/invoice/settings.json +1 -4
- package/templates/kilic.dev/Template.svelte +102 -0
- package/templates/kilic.dev/settings.json +1 -3
- package/templates/mail/Template.svelte +166 -0
- package/templates/mail/settings.json +1 -3
- package/dist/hooks/not-found.hook.mjs +0 -7
- package/dist/hooks/update-notifier.hook.mjs +0 -7
- package/dist/interfaces/pupeteer.mjs +0 -1
- package/templates/default/main.css +0 -73
- package/templates/invoice/.gitignore +0 -1
- package/templates/invoice/footer.html +0 -18
- package/templates/invoice/tailwind.css +0 -164
- package/templates/invoice/template.html.j2 +0 -189
- package/templates/kilic.dev/footer.html +0 -26
- package/templates/kilic.dev/header.html +0 -16
- package/templates/kilic.dev/main.css +0 -74
- package/templates/mail/.gitignore +0 -1
- package/templates/mail/tailwind.css +0 -145
- package/templates/mail/template.html.j2 +0 -14
package/README.md
CHANGED
|
@@ -1,81 +1,365 @@
|
|
|
1
1
|
# md-printer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Renders a Markdown or YAML file through a Svelte template into a PDF or HTML document. The PDF is printed by a locally installed Chromium-based browser, so there is no bundled Chrome download.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm i -g @cenk1cenk2/md-printer
|
|
9
|
+
```
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
- [Usage](#usage)
|
|
11
|
-
- [Commands](#commands)
|
|
12
|
-
<!-- tocstop -->
|
|
11
|
+
### Requirements
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
- Node.js >= 24.15.
|
|
14
|
+
- A Chromium-based browser. md-printer uses `puppeteer-core` and never downloads one.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
The browser executable is resolved in this order:
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
1. `--browser <path>`. If this path is not executable, md-printer fails instead of falling back.
|
|
19
|
+
2. `PUPPETEER_EXECUTABLE_PATH`
|
|
20
|
+
3. `CHROME_PATH`
|
|
21
|
+
4. Brave, Chrome, Chromium, Edge, in that order, looked up by name on `PATH`. Only Linux is supported.
|
|
22
|
+
|
|
23
|
+
When running as root or when the `CI` environment variable is set, the browser is started with `--no-sandbox`, because Chromium refuses to start its sandbox as root, which is the default in CI containers.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
# render to document.pdf in the current directory
|
|
29
|
+
md-printer document.md
|
|
30
|
+
|
|
31
|
+
# choose the output file
|
|
32
|
+
md-printer document.md out/document.pdf
|
|
33
|
+
|
|
34
|
+
# write to stdout, logs go to stderr
|
|
35
|
+
md-printer document.md -O > document.pdf
|
|
36
|
+
|
|
37
|
+
# read from stdin, the only argument is then the output
|
|
38
|
+
cat document.md | md-printer --stdin out.pdf
|
|
39
|
+
|
|
40
|
+
# template by built-in name or by path to a template directory
|
|
41
|
+
md-printer document.md -t kilic.dev
|
|
42
|
+
md-printer document.md -t ./my-template
|
|
43
|
+
|
|
44
|
+
# language for template translations
|
|
45
|
+
md-printer invoice.yaml -t invoice -l de
|
|
46
|
+
|
|
47
|
+
# one single page without page breaks
|
|
48
|
+
md-printer document.md --continuous
|
|
49
|
+
|
|
50
|
+
# HTML output instead of PDF
|
|
51
|
+
md-printer document.md -F html
|
|
28
52
|
```
|
|
29
53
|
|
|
30
|
-
|
|
54
|
+
- The input type is detected from the extension (`.md`, `.yaml`, `.yml`) and is markdown for stdin. Override it with `-f, --input-filetype`.
|
|
55
|
+
- YAML input has no body, the whole document is the `data` of the template. Invoices use this.
|
|
56
|
+
- The output defaults to `<input name>.<pdf|html>` in the current directory. Without an input file (stdin) there is no default, pass an output argument, `dest` in front-matter or `-O`.
|
|
57
|
+
- Output is written atomically: a temporary file next to it is renamed into place, keeping the mode and owner of an existing file.
|
|
58
|
+
- `dest` in front-matter and the output argument resolve against the current directory, while local assets resolve against the directory of the input file (the current directory for stdin).
|
|
59
|
+
- Only files inside the input directory are loaded, for PDF and HTML alike. Symlinks are followed first, so a link pointing outside the directory is not loaded either. Remote images are loaded as they are.
|
|
60
|
+
- HTML output inlines local images as data URIs: image attributes (`src`, `srcset`, `poster`), `style` attributes and `<style>` blocks. Text and code samples are never rewritten.
|
|
61
|
+
- `-T, --title` sets the document title, see [precedence](#precedence).
|
|
62
|
+
|
|
63
|
+
## Markdown
|
|
31
64
|
|
|
32
|
-
|
|
65
|
+
Markdown is rendered with [unified](https://unifiedjs.com): GitHub flavoured markdown (tables, task lists, footnotes, autolinks), heading ids, syntax highlighting with the selected highlight.js theme, and raw HTML, which is parsed as well, so a heading or code block written in HTML gets its id and highlighting too.
|
|
33
66
|
|
|
34
|
-
|
|
67
|
+
`::pagebreak` on its own line starts a new page. It works anywhere, also inside flex or grid layouts, and in continuous mode, where every part becomes a page of its own height. `<div class="page-break"></div>` in HTML and the `PageBreak` component (`::page-break`) do the same.
|
|
35
68
|
|
|
36
|
-
|
|
37
|
-
- [`md-printer help [COMMAND]`](#md-printer-help-command)
|
|
69
|
+
### Components
|
|
38
70
|
|
|
39
|
-
|
|
71
|
+
Markdown places Svelte components with [directives](https://github.com/remarkjs/remark-directive). The template's components and the [shared components](#shared-components) are available by their file name in kebab case, `PaymentInfo.svelte` as `payment-info`:
|
|
40
72
|
|
|
41
|
-
|
|
73
|
+
```md
|
|
74
|
+
::payment-info{iban="AT00 0000" due="14"}
|
|
42
75
|
|
|
76
|
+
:::callout{type="warning"}
|
|
77
|
+
Inner markdown, **bold** included, is rendered and passed as `children`.
|
|
78
|
+
:::
|
|
79
|
+
|
|
80
|
+
Total :items[3 items]{count="3"} so far.
|
|
43
81
|
```
|
|
44
|
-
USAGE
|
|
45
|
-
$ md-printer [FILE] [OUTPUT] [-t <value>] [-T <value>] [-w] [-d]
|
|
46
82
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
- `::name{...}` on its own line is a leaf component without children.
|
|
84
|
+
- `:::name{...}` up to a closing `:::` is a container. Its content is rendered as markdown and passed as the `children` snippet.
|
|
85
|
+
- `:name[label]{...}` inside text is inline. The label is passed as `children`.
|
|
86
|
+
- Attributes are passed as props, always as strings: `{count="3"}` gives `count: '3'`. `{.note #intro flag}` gives `class`, `id` and `flag: ''`.
|
|
87
|
+
- A name without a component stays the text it was written as, so `10:30am`, `note:here` or `::unknown` are printed unchanged.
|
|
50
88
|
|
|
51
|
-
|
|
52
|
-
-T, --title=<value> Overwrite document title.
|
|
53
|
-
-d, --dev Run with Chrome browser instead of publishing the file.
|
|
54
|
-
-t, --template=<value> [default: default] HTML template for the generated PDF file.
|
|
55
|
-
-w, --watch Watch the changes on the given file.
|
|
89
|
+
## Front-matter and settings
|
|
56
90
|
|
|
57
|
-
|
|
58
|
-
|
|
91
|
+
Markdown files take YAML front-matter. For YAML input the same keys are top-level keys of the file. All other keys are passed to the template as `data`.
|
|
92
|
+
|
|
93
|
+
| Key | Description |
|
|
94
|
+
| ----------------- | --------------------------------------------------------------------------------------------- |
|
|
95
|
+
| `template` | Built-in template name or path to a template directory. |
|
|
96
|
+
| `dest` | Output file, relative to the current directory, not to the input file. |
|
|
97
|
+
| `outputFiletype` | `pdf` (default) or `html`. |
|
|
98
|
+
| `language` | Language for template translations. |
|
|
99
|
+
| `continuous` | `true` renders one page per part, each as tall as its content, split only at page breaks. |
|
|
100
|
+
| `documentTitle` | Document title. |
|
|
101
|
+
| `pdfOptions` | Puppeteer [PDF options](https://pptr.dev/api/puppeteer.pdfoptions), merged over the defaults. |
|
|
102
|
+
| `sign` | Signing options, see [Signing](#signing). |
|
|
103
|
+
|
|
104
|
+
A template may carry a `settings.json` with defaults for its documents:
|
|
105
|
+
|
|
106
|
+
| Key | Description |
|
|
107
|
+
| ----------------- | ---------------------------------------------------------------------------------------- |
|
|
108
|
+
| `pdfOptions` | Puppeteer PDF options. |
|
|
109
|
+
| `i18n` | `{ "language": "en", "fallback": "en" }`, default and fallback language of translations. |
|
|
110
|
+
| `sign` | Signing options. |
|
|
111
|
+
| `continuous` | Render continuously by default. |
|
|
112
|
+
| `media` | CSS media type used for printing, `screen` (default) or `print`. |
|
|
113
|
+
| `highlightStyle` | highlight.js theme name from `highlight.js/styles`, defaults to `atom-one-dark`. |
|
|
114
|
+
|
|
115
|
+
The default `pdfOptions` are `format: A4`, `printBackground: true` and a margin of `30mm 40mm 30mm 20mm` (top, right, bottom, left). `pdfOptions` are merged recursively, so a document can override single keys. `margin` may be a CSS shorthand string such as `"18mm 12mm"`, and plain numbers are pixels, in continuous mode too.
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
---
|
|
119
|
+
template: kilic.dev
|
|
120
|
+
dest: ./out/report.pdf
|
|
121
|
+
language: de
|
|
122
|
+
documentTitle: Quarterly Report
|
|
123
|
+
pdfOptions:
|
|
124
|
+
format: A4
|
|
125
|
+
margin: 20mm
|
|
126
|
+
---
|
|
59
127
|
```
|
|
60
128
|
|
|
61
|
-
|
|
129
|
+
### Precedence
|
|
130
|
+
|
|
131
|
+
- General: flags > front-matter > template `settings.json` > defaults. `pdfOptions` are merged key by key in the order defaults, `settings.json`, front-matter.
|
|
132
|
+
- The language is `--language`, then `language`, then `settings.json` `i18n.language`, then `en`.
|
|
133
|
+
- `continuous` is enabled when any of `--continuous`, front-matter or `settings.json` enables it.
|
|
134
|
+
- The document title is `--title`, then `documentTitle`, then the `<title>` set by the template, then the input file name.
|
|
62
135
|
|
|
63
|
-
|
|
136
|
+
## Development
|
|
64
137
|
|
|
138
|
+
```sh
|
|
139
|
+
md-printer document.md --preview
|
|
140
|
+
md-printer document.md out.pdf --preview --no-open
|
|
65
141
|
```
|
|
142
|
+
|
|
143
|
+
- `-p, --preview` rebuilds when the input file, the template (components, imports, `settings.json`, translations) or a local asset used by the page changes. Every build rewrites the output file, the same one a normal run writes; reading from stdin without an output argument only previews. `-O` is not supported.
|
|
144
|
+
- It starts a local preview server and opens it in an app window of the discovered browser, using a throwaway profile. The page has HTML, Split and PDF tabs. Build errors, such as Svelte compile errors, are shown in an overlay and cleared by the next successful build. Closing the window ends the session, as does Ctrl+C.
|
|
145
|
+
- `--host` sets the loopback host, default `127.0.0.1`.
|
|
146
|
+
- `--port` sets the port, default `0` (random). A port in use fails the run with an error.
|
|
147
|
+
- It serves the files next to the input, except dotfiles such as `.env`.
|
|
148
|
+
- `--no-open` does not open a window: md-printer keeps rebuilding and writing until Ctrl+C, and the printed URL can be opened by hand.
|
|
149
|
+
- Signing is skipped while previewing. Run without `--preview` to sign.
|
|
150
|
+
|
|
151
|
+
## Templates
|
|
152
|
+
|
|
153
|
+
### Built-in templates
|
|
154
|
+
|
|
155
|
+
| Name | Description |
|
|
156
|
+
| ----------- | -------------------------------------------------------------------------------------------------------------- |
|
|
157
|
+
| `default` | GitHub-flavoured Markdown styling with Montserrat. This is the default. |
|
|
158
|
+
| `kilic.dev` | Same styling with a logo in the header and a footer with title and page numbers. |
|
|
159
|
+
| `invoice` | Invoice from YAML data (`company`, `client`, `payment`, `items`, `currency`, `date`, `id`) and Markdown notes. Translations in `en` and `de`, a signature block when signing. See `test/invoice.md`. |
|
|
160
|
+
| `mail` | Plain content with no margin and Tailwind typography, meant for HTML output. |
|
|
161
|
+
|
|
162
|
+
### Authoring a template
|
|
163
|
+
|
|
164
|
+
A template is a directory. Pass it with `-t ./path` or `template: ./path`. A value without a path separator is a built-in name, anything with `/` or starting with `.` or `~` is a path.
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
my-template/
|
|
168
|
+
Template.svelte required
|
|
169
|
+
settings.json optional
|
|
170
|
+
i18n/ optional, en.yaml, de.json, ...
|
|
171
|
+
components/ optional, *.svelte placed from markdown, see Markdown components
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`Template.svelte` is a Svelte 5 component receiving these props:
|
|
175
|
+
|
|
176
|
+
| Prop | Description |
|
|
177
|
+
| ----------- | -------------------------------------------------------------------------------------------- |
|
|
178
|
+
| `data` | Front-matter (or the YAML file) as an object. |
|
|
179
|
+
| `content` | The Markdown body rendered to HTML, with the components of directives rendered in place. Empty for YAML input. |
|
|
180
|
+
| `t` | i18next translate function, loaded from `i18n/<language>.(yaml\|yml\|json)`. |
|
|
181
|
+
| `language` | The resolved language. |
|
|
182
|
+
| `signature` | `{ date, name?, issuer?, serial? }` while signing is enabled, otherwise `undefined`. |
|
|
183
|
+
|
|
184
|
+
Set the document title with `<svelte:head><title>...</title></svelte:head>`.
|
|
185
|
+
|
|
186
|
+
Styles that need Tailwind CSS v4 or package imports go into a `<style lang="postcss">` block in `Template.svelte` or any component it imports. These blocks are collected and compiled together, so they can `@import 'tailwindcss'` and use `@plugin`, `@theme` and utility classes. Plain `<style>` blocks stay scoped Svelte styles. `@import` of packages (for example `@fontsource/*`, `github-markdown-css`) resolves from the template directory first and also from md-printer's own dependencies, so the template does not need a `node_modules`. The selected highlight.js theme is always included. Local `url()` and image references are inlined as data URIs.
|
|
187
|
+
|
|
188
|
+
Images are imported, which inlines them as data URIs:
|
|
189
|
+
|
|
190
|
+
```svelte
|
|
191
|
+
<script>
|
|
192
|
+
import logo from './logo.png'
|
|
193
|
+
</script>
|
|
194
|
+
|
|
195
|
+
<img src={logo} alt="logo" />
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Shared components
|
|
199
|
+
|
|
200
|
+
Import from `@cenk1cenk2/md-printer/components`:
|
|
201
|
+
|
|
202
|
+
| Component | Description |
|
|
203
|
+
| ---------------- | ------------------------------------------------------------------------------------------------- |
|
|
204
|
+
| `Page` | Layout wrapper. Children are the body, the `header` and `footer` snippets are the print header and footer of every page. |
|
|
205
|
+
| `Markdown` | Renders the Markdown body in an `<article class="markdown-body">`, styled by `github-markdown-css` if the template imports it. Directives render as live components. |
|
|
206
|
+
| `PageBreak` | Starts a new page anywhere, also in continuous mode. In markdown, `::page-break` or `::pagebreak` does the same. |
|
|
207
|
+
| `PageNumber` | Current page number, filled by Chrome. Header and footer only. |
|
|
208
|
+
| `TotalPages` | Total page count, filled by Chrome. Header and footer only. |
|
|
209
|
+
| `Title` | Document title, filled by Chrome. Header and footer only. |
|
|
210
|
+
| `Date` | Print date, filled by Chrome. Header and footer only. |
|
|
211
|
+
| `SignatureBlock` | Visible signature block for the `signature` prop. Needs Tailwind in a `<style lang="postcss">` block. Optional `labels` prop overrides its texts. |
|
|
212
|
+
|
|
213
|
+
```svelte
|
|
214
|
+
<script>
|
|
215
|
+
import { Markdown, Page, PageNumber, TotalPages, Title } from '@cenk1cenk2/md-printer/components'
|
|
216
|
+
|
|
217
|
+
let { data } = $props()
|
|
218
|
+
</script>
|
|
219
|
+
|
|
220
|
+
<svelte:head>
|
|
221
|
+
<title>{data.documentTitle ?? 'Document'}</title>
|
|
222
|
+
</svelte:head>
|
|
223
|
+
|
|
224
|
+
<Page>
|
|
225
|
+
{#snippet footer()}
|
|
226
|
+
<div style="width: 100%; text-align: center; font-size: 8px">
|
|
227
|
+
<Title /> - <PageNumber />/<TotalPages />
|
|
228
|
+
</div>
|
|
229
|
+
{/snippet}
|
|
230
|
+
|
|
231
|
+
<Markdown />
|
|
232
|
+
</Page>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### Markdown components
|
|
236
|
+
|
|
237
|
+
Every `*.svelte` file in the template's `components/` directory can be placed from markdown, see [Components](#components). The shared components can be placed the same way, for example `::page-break` or `::signature-block`, except `Markdown`. A template component with the same name as a shared one replaces it.
|
|
238
|
+
|
|
239
|
+
```svelte
|
|
240
|
+
<!-- components/Callout.svelte -->
|
|
241
|
+
<script>
|
|
242
|
+
import { getContext } from 'svelte'
|
|
243
|
+
|
|
244
|
+
let { type = 'note', children } = $props()
|
|
245
|
+
|
|
246
|
+
const { data, t, language, signature } = getContext('md-printer:document')
|
|
247
|
+
</script>
|
|
248
|
+
|
|
249
|
+
<aside class="callout callout-{type}">
|
|
250
|
+
<strong>{t(type)}</strong>
|
|
251
|
+
{@render children?.()}
|
|
252
|
+
</aside>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
- Props are the directive's attributes, always strings, and `children` for containers and inline directives.
|
|
256
|
+
- `getContext('md-printer:document')` gives `{ data, t, language, signature }`, the template's props, so a component needs nothing passed down.
|
|
257
|
+
- `<Markdown />` renders the components in place. A template that places `{@html content}` gets their rendered markup instead, without their scoped `<style>` blocks, so style them with Tailwind classes or a `<style lang="postcss">` block.
|
|
258
|
+
- A component can start new pages with `PageBreak` or an element with the `page-break` class.
|
|
259
|
+
- `--preview` picks up added and removed component files.
|
|
260
|
+
|
|
261
|
+
#### Header and footer
|
|
262
|
+
|
|
263
|
+
The `header` and `footer` snippets are rendered into Chrome's print header and footer, which are isolated from the page. md-printer inlines the CSS and images for them automatically, including remote images, and the default font size is 10px. Chrome does not reserve space for them, so set `pdfOptions.margin` in `settings.json` or the front-matter large enough for what you render. Both are omitted in continuous mode.
|
|
264
|
+
|
|
265
|
+
Templates are code: Svelte components run on your machine when a document is rendered. Only use templates you trust.
|
|
266
|
+
|
|
267
|
+
## Signing
|
|
268
|
+
|
|
269
|
+
PDF output can be signed with a qualified electronic signature through ID Austria, using A-Trust.
|
|
270
|
+
|
|
271
|
+
```sh
|
|
272
|
+
md-printer invoice.yaml -t invoice --sign --sign-certificate ~/id-austria.pem
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
- `--sign` enables signing. `--sign-provider` selects the provider, `a-trust` is the only one and the default. `--sign-certificate` is a DER or PEM file of your signer certificate.
|
|
276
|
+
- The same keys can be set as `sign` in front-matter or `settings.json`: `enabled`, `provider`, `certificate`, `reason`, `location`, `contact`. Flags win. `reason`, `location` and `contact` are stored in the signature.
|
|
277
|
+
- Signing only works for PDF output and is skipped with `--preview`.
|
|
278
|
+
- The signing session has to run in your browser. md-printer opens a link to a temporary local page, you log in with ID Austria in the A-Trust page, and paste the resulting signature (starts with `MII`) back into the local page. It waits until the signature arrives, press Ctrl+C to abort.
|
|
279
|
+
- With a certificate, the signer name, issuer and serial are passed to the template as `signature`, so `SignatureBlock` can show who signed and when. The certificate must be valid at signing time, and the returned signature is rejected if it was not made with it. Without a certificate only the date is available.
|
|
280
|
+
- Verify the result at https://www.signaturpruefung.gv.at.
|
|
281
|
+
|
|
282
|
+
## Migrating from 2.x
|
|
283
|
+
|
|
284
|
+
- Nunjucks `template.html.j2`, `header.html`, `footer.html`, `main.css` and `tailwind.css` are replaced by `Template.svelte`, with styles in a `<style lang="postcss">` block.
|
|
285
|
+
- Removed from `settings.json` and front-matter: `body_class`, `css`, `stylesheet`, `script`, `marked_options`, `launch_options`, `gray_matter_options`. `documentTitle` in `settings.json` is removed too, set the title in the template.
|
|
286
|
+
- Front-matter on stdout is gone, use `-O`.
|
|
287
|
+
- `--title` now beats front-matter, and `--template` now beats front-matter.
|
|
288
|
+
- Assets resolve relative to the input file directory instead of the current directory.
|
|
289
|
+
- Continuous mode has no header and footer.
|
|
290
|
+
- `puppeteer` is replaced by `puppeteer-core`, there is no bundled Chrome, a local Chromium-based browser is required.
|
|
291
|
+
- `--dev` is replaced by `--preview`, which also rebuilds and rewrites the output on every change; there is no separate `--watch`.
|
|
292
|
+
- The default highlight theme is `atom-one-dark`.
|
|
293
|
+
- Files with an unknown extension are read as markdown, as before; `-f` still forces a type.
|
|
294
|
+
- The update notifier and the did-you-mean suggestion for mistyped commands are removed, md-printer is a single command.
|
|
295
|
+
|
|
296
|
+
## Command reference
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
Renders a markdown or yaml file through a Svelte template into a PDF or HTML document.
|
|
300
|
+
|
|
66
301
|
USAGE
|
|
67
|
-
$ md-printer
|
|
302
|
+
$ md-printer [FILE] [OUTPUT] [--log-level
|
|
303
|
+
silent|direct|fatal|error|warn|info|verbose|debug|trace] [-I] [-f
|
|
304
|
+
md|yaml|yml] [-F pdf|html] [-O] [-t <value>] [-T <value>] [-l <value>] [-b
|
|
305
|
+
<value>] [--continuous] [-p] [--host 127.0.0.1|localhost|::1] [--port
|
|
306
|
+
<value>] [--open] [--sign] [--sign-provider <value>] [--sign-certificate
|
|
307
|
+
<value>]
|
|
68
308
|
|
|
69
309
|
ARGUMENTS
|
|
70
|
-
|
|
310
|
+
[FILE] Markdown or yaml file to render.
|
|
311
|
+
[OUTPUT] Output file. Overwrites the one defined in front-matter.
|
|
71
312
|
|
|
72
313
|
FLAGS
|
|
73
|
-
-
|
|
314
|
+
-F, --output-filetype=<option> Output file type, defaults to pdf. Overwrites
|
|
315
|
+
the one defined in front-matter.
|
|
316
|
+
<options: pdf|html>
|
|
317
|
+
-I, --stdin Read the input from stdin.
|
|
318
|
+
-O, --stdout Write the output to stdout instead of a file.
|
|
319
|
+
-T, --title=<value> Document title. Overwrites the one defined in
|
|
320
|
+
front-matter or the template.
|
|
321
|
+
-b, --browser=<value> Browser executable used for printing.
|
|
322
|
+
Discovered automatically when omitted (Brave,
|
|
323
|
+
Chrome, Chromium, Edge).
|
|
324
|
+
-f, --input-filetype=<option> Input file type. Detected from the file
|
|
325
|
+
extension, markdown for stdin and unknown
|
|
326
|
+
extensions.
|
|
327
|
+
<options: md|yaml|yml>
|
|
328
|
+
-l, --language=<value> Language for template translations. Overwrites
|
|
329
|
+
the one defined in front-matter and template
|
|
330
|
+
settings.
|
|
331
|
+
-p, --preview Rebuild whenever the input, the template or
|
|
332
|
+
its assets change, show the HTML and the PDF
|
|
333
|
+
in a live preview and rewrite the output file
|
|
334
|
+
when there is one.
|
|
335
|
+
-t, --template=<value> Built-in template name or path to a template
|
|
336
|
+
directory, defaults to "default". Overwrites
|
|
337
|
+
the one defined in front-matter.
|
|
338
|
+
--continuous Render the PDF as a single continuous page
|
|
339
|
+
without page breaks.
|
|
340
|
+
--host=<option> [default: 127.0.0.1] Loopback host for the
|
|
341
|
+
preview server, it serves the files next to
|
|
342
|
+
the input and is never exposed to the network.
|
|
343
|
+
<options: 127.0.0.1|localhost|::1>
|
|
344
|
+
--[no-]open Open the preview window, --no-open keeps
|
|
345
|
+
rebuilding and writing without one.
|
|
346
|
+
--port=<value> Port for the preview server, random when 0.
|
|
347
|
+
--sign Sign the PDF with a qualified electronic
|
|
348
|
+
signature through ID Austria (A-Trust).
|
|
349
|
+
--sign-certificate=<value> Signer certificate (DER or PEM) used for the
|
|
350
|
+
visible signature block and to verify the
|
|
351
|
+
returned signature.
|
|
352
|
+
--sign-provider=<value> Signature provider, defaults to a-trust.
|
|
353
|
+
Overwrites the one defined in front-matter and
|
|
354
|
+
template settings.
|
|
355
|
+
|
|
356
|
+
CLI FLAGS
|
|
357
|
+
--log-level=<option> [default: INFO, env: LOG_LEVEL] Set the log level of the
|
|
358
|
+
application.
|
|
359
|
+
<options:
|
|
360
|
+
silent|direct|fatal|error|warn|info|verbose|debug|trace>
|
|
74
361
|
|
|
75
362
|
DESCRIPTION
|
|
76
|
-
|
|
363
|
+
Renders a markdown or yaml file through a Svelte template into a PDF or HTML
|
|
364
|
+
document.
|
|
77
365
|
```
|
|
78
|
-
|
|
79
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.1.17/src/commands/help.ts)_
|
|
80
|
-
|
|
81
|
-
<!-- commandsstop -->
|
|
@@ -5,6 +5,5 @@ function __decorate(decorators, target, key, desc) {
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
8
|
//#endregion
|
|
10
|
-
export { __decorate as default };
|
|
9
|
+
export { __decorate as default };
|