-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
config.ts
178 lines (154 loc) · 3.88 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { WatchOptions } from 'chokidar';
import { GrayMatterOption } from 'gray-matter';
import { marked } from 'marked';
import { resolve } from 'path';
import { FrameAddScriptTagOptions, launch, PDFOptions } from 'puppeteer';
export const defaultConfig: Config = {
basedir: process.cwd(),
stylesheet: [resolve(__dirname, '..', '..', 'markdown.css')],
script: [],
css: '',
document_title: '',
body_class: [],
page_media_type: 'screen',
highlight_style: 'github',
marked_options: {},
pdf_options: {
printBackground: true,
format: 'a4',
margin: {
top: '30mm',
right: '40mm',
bottom: '30mm',
left: '20mm',
},
},
launch_options: {},
gray_matter_options: {
engines: {
js: () =>
new Error(
'The JS engine for front-matter is disabled by default for security reasons. You can enable it by configuring gray_matter_options.',
),
},
},
md_file_encoding: 'utf-8',
stylesheet_encoding: 'utf-8',
as_html: false,
devtools: false,
marked_extensions: [],
};
/**
* In config keys, dashes of cli flag names are replaced with underscores.
*/
export type Config = PdfConfig | HtmlConfig;
export interface PdfConfig extends BasicConfig {
/**
* If true, generate HTML output instead of PDF output. Default: `false`.
*/
as_html?: false;
}
export interface HtmlConfig extends BasicConfig {
/**
* If true, generate HTML output instead of PDF output. Default: `false`.
*/
as_html: true;
}
interface BasicConfig {
/**
* Base directory to be served by the file server.
*/
basedir: string;
/**
* Optional destination path for the output file (including the extension).
*/
dest?: string;
/**
* List of css files to use for styling.
*
* @todo change to `FrameAddStyleTagOptions` (will be a breaking change)
*/
stylesheet: string[];
/**
* Custom css styles.
*/
css: string;
/**
* List of scripts to load into the page.
*
* @see https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pageaddscripttagoptions
*/
script: FrameAddScriptTagOptions[];
/**
* Name of the HTML Document.
*/
document_title: string;
/**
* List of classes for the body tag.
*/
body_class: string[];
/**
* Media type to emulate the page with.
*/
page_media_type: 'screen' | 'print';
/**
* Highlight.js stylesheet to use (without the .css extension).
*
* @see https://github.com/isagalaev/highlight.js/tree/master/src/styles
*/
highlight_style: string;
/**
* Options for the Marked parser.
*
* @see https://marked.js.org/#/USING_ADVANCED.md
*/
marked_options: marked.MarkedOptions;
/**
* PDF options for Puppeteer.
*
* @see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
*/
pdf_options: PDFOptions;
/**
* Launch options for Puppeteer.
*
* @see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
*/
launch_options: PuppeteerLaunchOptions;
/**
* Options for gray-matter (front-matter parser).
*
* @see https://github.com/jonschlinkert/gray-matter#options
*/
gray_matter_options: GrayMatterOption<string, any>;
/**
* Markdown file encoding. Default: `utf-8`.
*/
md_file_encoding: string;
/**
* CSS stylesheet encoding. Default: `utf-8`.
*/
stylesheet_encoding: string;
/**
* If true, open chromium with devtools instead of saving the pdf. This is
* meant for development only, to inspect the rendered HTML.
*/
devtools: boolean;
/**
* Port to run the local server on.
*/
port?: number;
/**
* Options to pass to Chokidar's `watch` call.
*
* This is specifically useful when running into issues when editor plugins trigger additional saves after the initial save.
*/
watch_options?: WatchOptions;
/**
* Custm Extensions to be passed to marked.
*
* @see https://marked.js.org/using_pro#extensions
*/
marked_extensions: marked.MarkedExtension[];
}
export type PuppeteerLaunchOptions = Parameters<typeof launch>[0];