@brahim.ariani/md2pdf-cli 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 +107 -0
- package/bin/md2pdf.js +80 -0
- package/lib/index.js +184 -0
- package/lib/styles.js +103 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brahim Ariani
|
|
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,107 @@
|
|
|
1
|
+
# md2pdf-cli
|
|
2
|
+
|
|
3
|
+
Convert Markdown files into beautifully styled PDFs using [marked](https://github.com/markedjs/marked), [KaTeX](https://katex.org/) and [puppeteer](https://github.com/puppeteer/puppeteer).
|
|
4
|
+
|
|
5
|
+
GitHub-flavored Markdown, tables, code blocks, blockquotes, images **and LaTeX math equations** (`$inline$` and `$$display$$`) are all rendered with sane, print-friendly defaults — page numbers in the footer, A4 by default, justified body text, and zebra-striped tables.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g md2pdf-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or use it directly in a project:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install md2pdf-cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## CLI
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
md2pdf <input.md> [output.pdf] [options]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If `output.pdf` is omitted, the output filename is derived from the input (e.g. `research.md` → `research.pdf`).
|
|
26
|
+
|
|
27
|
+
### Options
|
|
28
|
+
|
|
29
|
+
| Flag | Description |
|
|
30
|
+
|------------------------|------------------------------------------------------------|
|
|
31
|
+
| `--title <text>` | Document title (defaults to the input filename) |
|
|
32
|
+
| `--css <file>` | Path to a custom CSS file (replaces the default styles) |
|
|
33
|
+
| `--format <size>` | Page format: `A4`, `Letter`, `Legal`, ... Default: `A4` |
|
|
34
|
+
| `--no-page-numbers` | Disable the page-number footer |
|
|
35
|
+
| `--no-math` | Disable KaTeX equation rendering |
|
|
36
|
+
| `--keep-html` | Keep the intermediate `.tmp.html` file for debugging |
|
|
37
|
+
| `-h`, `--help` | Show usage |
|
|
38
|
+
|
|
39
|
+
### Examples
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
md2pdf research.md
|
|
43
|
+
md2pdf research.md out/research.pdf
|
|
44
|
+
md2pdf report.md report.pdf --title "Quarterly Report" --css theme.css
|
|
45
|
+
md2pdf notes.md notes.pdf --format Letter --no-page-numbers
|
|
46
|
+
md2pdf paper.md paper.pdf # equations rendered by default
|
|
47
|
+
md2pdf draft.md draft.pdf --no-math # treat $...$ as literal text
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Math / LaTeX equations
|
|
51
|
+
|
|
52
|
+
Inline math uses single dollars, display math uses double dollars:
|
|
53
|
+
|
|
54
|
+
```markdown
|
|
55
|
+
The famous identity is $e^{i\pi} + 1 = 0$.
|
|
56
|
+
|
|
57
|
+
$$
|
|
58
|
+
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
|
|
59
|
+
$$
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Equations are rendered server-side with KaTeX, so the PDF is self-contained and prints identically on any machine.
|
|
63
|
+
|
|
64
|
+
## Programmatic API
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
const { convert } = require('md2pdf-cli');
|
|
68
|
+
|
|
69
|
+
await convert({
|
|
70
|
+
input: 'research.md',
|
|
71
|
+
output: 'research.pdf',
|
|
72
|
+
title: 'My Research Report',
|
|
73
|
+
// cssFile: 'theme.css',
|
|
74
|
+
// css: '/* inline CSS string */',
|
|
75
|
+
format: 'A4',
|
|
76
|
+
pageNumbers: true,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `convert(options)`
|
|
81
|
+
|
|
82
|
+
| Option | Type | Default | Description |
|
|
83
|
+
|---------------------|-------------------------------|------------------------|--------------------------------------------------------|
|
|
84
|
+
| `input` | `string` | — | Path to a Markdown file (required) |
|
|
85
|
+
| `output` | `string` | — | Path to the output PDF (required) |
|
|
86
|
+
| `title` | `string` | input basename | `<title>` of the generated HTML |
|
|
87
|
+
| `css` | `string` | bundled default | Inline CSS string |
|
|
88
|
+
| `cssFile` | `string` | — | Path to a CSS file (overrides `css`) |
|
|
89
|
+
| `format` | `string` | `'A4'` | Puppeteer page format |
|
|
90
|
+
| `margin` | `object` | 22mm / 18mm | `{ top, bottom, left, right }` |
|
|
91
|
+
| `pageNumbers` | `boolean` | `true` | Render `n / total` in the footer |
|
|
92
|
+
| `math` | `boolean` | `true` | Render `$...$` and `$$...$$` as KaTeX |
|
|
93
|
+
| `headerTemplate` | `string` | empty | Puppeteer header HTML |
|
|
94
|
+
| `footerTemplate` | `string` | page numbers | Puppeteer footer HTML |
|
|
95
|
+
| `puppeteerOptions` | `object` | `{}` | Extra options passed to `puppeteer.launch` |
|
|
96
|
+
| `keepHtml` | `boolean` | `false` | Keep the intermediate `.tmp.html` file |
|
|
97
|
+
|
|
98
|
+
Returns `{ output, brokenImages }` where `brokenImages` lists any `<img>` URLs that failed to load.
|
|
99
|
+
|
|
100
|
+
## Requirements
|
|
101
|
+
|
|
102
|
+
- Node.js >= 18
|
|
103
|
+
- Puppeteer will download a compatible Chromium on install (≈ 170 MB). To skip this and reuse an existing Chrome, set `PUPPETEER_SKIP_DOWNLOAD=true` before installing and pass `puppeteerOptions: { executablePath: '...' }` to `convert()`.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
package/bin/md2pdf.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { convert } = require('../lib/index');
|
|
6
|
+
|
|
7
|
+
function printUsage() {
|
|
8
|
+
console.log(`Usage:
|
|
9
|
+
md2pdf <input.md> [output.pdf] [options]
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
--title <text> Document title (defaults to input filename)
|
|
13
|
+
--css <file> Path to a custom CSS file (replaces the default styles)
|
|
14
|
+
--format <size> Page format (A4, Letter, ...). Default: A4
|
|
15
|
+
--no-page-numbers Disable footer page numbers
|
|
16
|
+
--no-math Disable KaTeX equation rendering ($...$ / $$...$$)
|
|
17
|
+
--keep-html Keep the intermediate .tmp.html file
|
|
18
|
+
-h, --help Show this help
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
md2pdf research.md
|
|
22
|
+
md2pdf research.md out/research.pdf
|
|
23
|
+
md2pdf report.md report.pdf --title "Quarterly Report" --css theme.css
|
|
24
|
+
`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseArgs(argv) {
|
|
28
|
+
const args = { positional: [], flags: {} };
|
|
29
|
+
for (let i = 0; i < argv.length; i++) {
|
|
30
|
+
const a = argv[i];
|
|
31
|
+
if (a === '-h' || a === '--help') { args.flags.help = true; continue; }
|
|
32
|
+
if (a === '--no-page-numbers') { args.flags.pageNumbers = false; continue; }
|
|
33
|
+
if (a === '--no-math') { args.flags.math = false; continue; }
|
|
34
|
+
if (a === '--keep-html') { args.flags.keepHtml = true; continue; }
|
|
35
|
+
if (a === '--title') { args.flags.title = argv[++i]; continue; }
|
|
36
|
+
if (a === '--css') { args.flags.cssFile = argv[++i]; continue; }
|
|
37
|
+
if (a === '--format') { args.flags.format = argv[++i]; continue; }
|
|
38
|
+
if (a.startsWith('--')) {
|
|
39
|
+
console.error(`Unknown option: ${a}`);
|
|
40
|
+
process.exit(2);
|
|
41
|
+
}
|
|
42
|
+
args.positional.push(a);
|
|
43
|
+
}
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
(async () => {
|
|
48
|
+
const args = parseArgs(process.argv.slice(2));
|
|
49
|
+
|
|
50
|
+
if (args.flags.help || args.positional.length === 0) {
|
|
51
|
+
printUsage();
|
|
52
|
+
process.exit(args.flags.help ? 0 : 1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const input = args.positional[0];
|
|
56
|
+
const output =
|
|
57
|
+
args.positional[1] ||
|
|
58
|
+
input.replace(/\.md$/i, '') + '.pdf';
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const result = await convert({
|
|
62
|
+
input,
|
|
63
|
+
output,
|
|
64
|
+
title: args.flags.title,
|
|
65
|
+
cssFile: args.flags.cssFile,
|
|
66
|
+
format: args.flags.format || 'A4',
|
|
67
|
+
pageNumbers: args.flags.pageNumbers !== false,
|
|
68
|
+
math: args.flags.math !== false,
|
|
69
|
+
keepHtml: !!args.flags.keepHtml,
|
|
70
|
+
});
|
|
71
|
+
if (result.brokenImages && result.brokenImages.length) {
|
|
72
|
+
console.warn('WARNING: broken images:');
|
|
73
|
+
for (const src of result.brokenImages) console.warn(' -', src);
|
|
74
|
+
}
|
|
75
|
+
console.log('PDF generated:', result.output);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error('Error:', err.message);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
})();
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { marked } = require('marked');
|
|
6
|
+
const markedKatex = require('marked-katex-extension');
|
|
7
|
+
const puppeteer = require('puppeteer');
|
|
8
|
+
const { defaultCss, katexCssLink } = require('./styles');
|
|
9
|
+
|
|
10
|
+
let katexExtensionRegistered = false;
|
|
11
|
+
function ensureKatexExtension() {
|
|
12
|
+
if (katexExtensionRegistered) return;
|
|
13
|
+
marked.use(markedKatex({ throwOnError: false, output: 'html', nonStandard: true }));
|
|
14
|
+
katexExtensionRegistered = true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function buildHtml({ body, title, css, math }) {
|
|
18
|
+
const katexTag = math ? katexCssLink() : '';
|
|
19
|
+
return `<!doctype html>
|
|
20
|
+
<html lang="en">
|
|
21
|
+
<head>
|
|
22
|
+
<meta charset="utf-8">
|
|
23
|
+
<title>${escapeHtml(title)}</title>
|
|
24
|
+
${katexTag}
|
|
25
|
+
<style>${css}</style>
|
|
26
|
+
</head>
|
|
27
|
+
<body>
|
|
28
|
+
${body}
|
|
29
|
+
</body>
|
|
30
|
+
</html>`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function escapeHtml(s) {
|
|
34
|
+
return String(s)
|
|
35
|
+
.replace(/&/g, '&')
|
|
36
|
+
.replace(/</g, '<')
|
|
37
|
+
.replace(/>/g, '>');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// marked-katex-extension only treats `$$...$$` as a display-math block when
|
|
41
|
+
// surrounded by blank lines. Normalize the source so users don't trip on it.
|
|
42
|
+
function normalizeBlockMath(src) {
|
|
43
|
+
const lines = src.split(/\r?\n/);
|
|
44
|
+
const out = [];
|
|
45
|
+
let inFence = false;
|
|
46
|
+
let inMath = false;
|
|
47
|
+
const pushBlankIfNeeded = () => {
|
|
48
|
+
if (out.length > 0 && out[out.length - 1].trim() !== '') out.push('');
|
|
49
|
+
};
|
|
50
|
+
for (let i = 0; i < lines.length; i++) {
|
|
51
|
+
const line = lines[i];
|
|
52
|
+
const trimmed = line.trim();
|
|
53
|
+
if (!inMath && /^(```|~~~)/.test(trimmed)) {
|
|
54
|
+
inFence = !inFence;
|
|
55
|
+
out.push(line);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (inFence) { out.push(line); continue; }
|
|
59
|
+
const singleBlock = /^\$\$[^$]+\$\$$/.test(trimmed);
|
|
60
|
+
const opensBlock = !inMath && !singleBlock && /^\$\$/.test(trimmed) && !/\$\$.+\$\$$/.test(trimmed);
|
|
61
|
+
const closesBlock = inMath && /\$\$\s*$/.test(trimmed);
|
|
62
|
+
if (singleBlock) {
|
|
63
|
+
pushBlankIfNeeded();
|
|
64
|
+
out.push(line);
|
|
65
|
+
if (i + 1 < lines.length && lines[i + 1].trim() !== '') out.push('');
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (opensBlock) {
|
|
69
|
+
pushBlankIfNeeded();
|
|
70
|
+
inMath = true;
|
|
71
|
+
out.push(line);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (closesBlock) {
|
|
75
|
+
inMath = false;
|
|
76
|
+
out.push(line);
|
|
77
|
+
if (i + 1 < lines.length && lines[i + 1].trim() !== '') out.push('');
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
out.push(line);
|
|
81
|
+
}
|
|
82
|
+
return out.join('\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function convert(options) {
|
|
86
|
+
const {
|
|
87
|
+
input,
|
|
88
|
+
output,
|
|
89
|
+
title,
|
|
90
|
+
css,
|
|
91
|
+
cssFile,
|
|
92
|
+
format = 'A4',
|
|
93
|
+
margin = { top: '22mm', bottom: '22mm', left: '18mm', right: '18mm' },
|
|
94
|
+
pageNumbers = true,
|
|
95
|
+
headerTemplate,
|
|
96
|
+
footerTemplate,
|
|
97
|
+
puppeteerOptions = {},
|
|
98
|
+
keepHtml = false,
|
|
99
|
+
math = true,
|
|
100
|
+
} = options;
|
|
101
|
+
|
|
102
|
+
if (!input) throw new Error('`input` is required');
|
|
103
|
+
if (!output) throw new Error('`output` is required');
|
|
104
|
+
|
|
105
|
+
const inputAbs = path.resolve(input);
|
|
106
|
+
const outputAbs = path.resolve(output);
|
|
107
|
+
|
|
108
|
+
if (!fs.existsSync(inputAbs)) {
|
|
109
|
+
throw new Error(`Input markdown file not found: ${inputAbs}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const rawMd = fs.readFileSync(inputAbs, 'utf8');
|
|
113
|
+
marked.setOptions({ gfm: true, breaks: false });
|
|
114
|
+
if (math) ensureKatexExtension();
|
|
115
|
+
const md = math ? normalizeBlockMath(rawMd) : rawMd;
|
|
116
|
+
const body = marked.parse(md);
|
|
117
|
+
|
|
118
|
+
let resolvedCss = css || defaultCss;
|
|
119
|
+
if (cssFile) {
|
|
120
|
+
resolvedCss = fs.readFileSync(path.resolve(cssFile), 'utf8');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const docTitle = title || path.basename(inputAbs, path.extname(inputAbs));
|
|
124
|
+
const html = buildHtml({ body, title: docTitle, css: resolvedCss, math });
|
|
125
|
+
|
|
126
|
+
const tmpHtmlPath = outputAbs.replace(/\.pdf$/i, '') + '.tmp.html';
|
|
127
|
+
fs.writeFileSync(tmpHtmlPath, html, 'utf8');
|
|
128
|
+
const fileUrl = 'file:///' + tmpHtmlPath.replace(/\\/g, '/');
|
|
129
|
+
|
|
130
|
+
const launchOptions = Object.assign(
|
|
131
|
+
{ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] },
|
|
132
|
+
puppeteerOptions
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const browser = await puppeteer.launch(launchOptions);
|
|
136
|
+
try {
|
|
137
|
+
const page = await browser.newPage();
|
|
138
|
+
await page.goto(fileUrl, { waitUntil: ['load', 'networkidle0'] });
|
|
139
|
+
|
|
140
|
+
await page.evaluate(async () => {
|
|
141
|
+
const imgs = Array.from(document.images);
|
|
142
|
+
await Promise.all(imgs.map((img) => {
|
|
143
|
+
if (img.complete && img.naturalWidth > 0) return;
|
|
144
|
+
return new Promise((res) => {
|
|
145
|
+
img.addEventListener('load', res);
|
|
146
|
+
img.addEventListener('error', res);
|
|
147
|
+
});
|
|
148
|
+
}));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const broken = await page.evaluate(() =>
|
|
152
|
+
Array.from(document.images)
|
|
153
|
+
.filter((img) => !img.complete || img.naturalWidth === 0)
|
|
154
|
+
.map((img) => img.src)
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const pdfOptions = {
|
|
158
|
+
path: outputAbs,
|
|
159
|
+
format,
|
|
160
|
+
printBackground: true,
|
|
161
|
+
margin,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (pageNumbers || headerTemplate || footerTemplate) {
|
|
165
|
+
pdfOptions.displayHeaderFooter = true;
|
|
166
|
+
pdfOptions.headerTemplate = headerTemplate || '<div></div>';
|
|
167
|
+
pdfOptions.footerTemplate =
|
|
168
|
+
footerTemplate ||
|
|
169
|
+
'<div style="font-size:8pt; color:#64748b; width:100%; text-align:center;">' +
|
|
170
|
+
'<span class="pageNumber"></span> / <span class="totalPages"></span>' +
|
|
171
|
+
'</div>';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
await page.pdf(pdfOptions);
|
|
175
|
+
return { output: outputAbs, brokenImages: broken };
|
|
176
|
+
} finally {
|
|
177
|
+
await browser.close();
|
|
178
|
+
if (!keepHtml) {
|
|
179
|
+
try { fs.unlinkSync(tmpHtmlPath); } catch (_) { /* ignore */ }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
module.exports = { convert, defaultCss };
|
package/lib/styles.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
function katexCssLink() {
|
|
6
|
+
let katexCssPath;
|
|
7
|
+
try {
|
|
8
|
+
katexCssPath = require.resolve('katex/dist/katex.min.css');
|
|
9
|
+
} catch (_) {
|
|
10
|
+
return '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">';
|
|
11
|
+
}
|
|
12
|
+
const fileUrl = 'file:///' + katexCssPath.replace(/\\/g, '/');
|
|
13
|
+
return `<link rel="stylesheet" href="${fileUrl}">`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const defaultCss = `
|
|
17
|
+
@page { size: A4; margin: 22mm 18mm 22mm 18mm; }
|
|
18
|
+
* { box-sizing: border-box; }
|
|
19
|
+
body {
|
|
20
|
+
font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
|
|
21
|
+
font-size: 11pt;
|
|
22
|
+
line-height: 1.55;
|
|
23
|
+
color: #1a1a1a;
|
|
24
|
+
max-width: 100%;
|
|
25
|
+
margin: 0;
|
|
26
|
+
}
|
|
27
|
+
h1, h2, h3, h4 {
|
|
28
|
+
color: #102a43;
|
|
29
|
+
page-break-after: avoid;
|
|
30
|
+
break-after: avoid;
|
|
31
|
+
}
|
|
32
|
+
h1 { font-size: 22pt; border-bottom: 2px solid #102a43; padding-bottom: 6px; margin-top: 0; }
|
|
33
|
+
h2 { font-size: 16pt; border-bottom: 1px solid #bcccdc; padding-bottom: 4px; margin-top: 28px; }
|
|
34
|
+
h3 { font-size: 13pt; margin-top: 22px; }
|
|
35
|
+
h4 { font-size: 11.5pt; margin-top: 18px; }
|
|
36
|
+
p { text-align: justify; margin: 0 0 10px 0; }
|
|
37
|
+
ul, ol { margin: 6px 0 12px 0; padding-left: 24px; }
|
|
38
|
+
li { margin-bottom: 4px; }
|
|
39
|
+
strong { color: #0b2447; }
|
|
40
|
+
code {
|
|
41
|
+
background: #f1f5f9;
|
|
42
|
+
padding: 1px 5px;
|
|
43
|
+
border-radius: 3px;
|
|
44
|
+
font-family: "Consolas", "Courier New", monospace;
|
|
45
|
+
font-size: 9.5pt;
|
|
46
|
+
color: #b91c1c;
|
|
47
|
+
}
|
|
48
|
+
pre {
|
|
49
|
+
background: #0f172a;
|
|
50
|
+
color: #f1f5f9;
|
|
51
|
+
padding: 12px;
|
|
52
|
+
border-radius: 5px;
|
|
53
|
+
overflow-x: auto;
|
|
54
|
+
font-size: 9pt;
|
|
55
|
+
}
|
|
56
|
+
pre code { background: transparent; color: inherit; padding: 0; }
|
|
57
|
+
table {
|
|
58
|
+
width: 100%;
|
|
59
|
+
border-collapse: collapse;
|
|
60
|
+
margin: 12px 0 18px 0;
|
|
61
|
+
page-break-inside: avoid;
|
|
62
|
+
font-size: 9.5pt;
|
|
63
|
+
}
|
|
64
|
+
th, td {
|
|
65
|
+
border: 1px solid #cbd5e1;
|
|
66
|
+
padding: 6px 9px;
|
|
67
|
+
text-align: left;
|
|
68
|
+
vertical-align: top;
|
|
69
|
+
}
|
|
70
|
+
th { background: #e2e8f0; color: #0b2447; font-weight: 600; }
|
|
71
|
+
tr:nth-child(even) td { background: #f8fafc; }
|
|
72
|
+
hr { border: none; border-top: 1px solid #cbd5e1; margin: 24px 0; }
|
|
73
|
+
blockquote {
|
|
74
|
+
border-left: 4px solid #64748b;
|
|
75
|
+
padding: 4px 12px;
|
|
76
|
+
color: #475569;
|
|
77
|
+
background: #f8fafc;
|
|
78
|
+
margin: 10px 0;
|
|
79
|
+
}
|
|
80
|
+
img {
|
|
81
|
+
max-width: 100%;
|
|
82
|
+
height: auto;
|
|
83
|
+
display: block;
|
|
84
|
+
margin: 12px auto;
|
|
85
|
+
border: 1px solid #e2e8f0;
|
|
86
|
+
border-radius: 4px;
|
|
87
|
+
page-break-inside: avoid;
|
|
88
|
+
break-inside: avoid;
|
|
89
|
+
}
|
|
90
|
+
img + em, p > em {
|
|
91
|
+
display: block;
|
|
92
|
+
text-align: center;
|
|
93
|
+
color: #475569;
|
|
94
|
+
font-size: 9.5pt;
|
|
95
|
+
margin-bottom: 14px;
|
|
96
|
+
}
|
|
97
|
+
a { color: #1d4ed8; text-decoration: none; }
|
|
98
|
+
.katex { font-size: 1.05em; }
|
|
99
|
+
.katex-display { margin: 14px 0; overflow-x: auto; overflow-y: hidden; page-break-inside: avoid; }
|
|
100
|
+
.katex-display > .katex { display: inline-block; text-align: center; max-width: 100%; }
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
module.exports = { defaultCss, katexCssLink };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brahim.ariani/md2pdf-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Convert Markdown files to beautifully styled PDFs using marked and puppeteer.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdown",
|
|
7
|
+
"pdf",
|
|
8
|
+
"md-to-pdf",
|
|
9
|
+
"puppeteer",
|
|
10
|
+
"marked",
|
|
11
|
+
"katex",
|
|
12
|
+
"math",
|
|
13
|
+
"latex",
|
|
14
|
+
"equations",
|
|
15
|
+
"cli",
|
|
16
|
+
"converter"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Brahim Ariani <brahim.ariani.inc@gmail.com>",
|
|
20
|
+
"main": "lib/index.js",
|
|
21
|
+
"bin": {
|
|
22
|
+
"md2pdf": "bin/md2pdf.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"lib",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node test/smoke.js"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"katex": "^0.16.9",
|
|
38
|
+
"marked": "^12.0.0",
|
|
39
|
+
"marked-katex-extension": "^5.0.0",
|
|
40
|
+
"puppeteer": "^24.15.0"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/brahimariani/md2pdf-cli.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/brahimariani/md2pdf-cli/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/brahimariani/md2pdf-cli#readme"
|
|
50
|
+
}
|