@markdown-viewer/documd 5.2.2 → 5.3.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 +11 -6
- package/browser-renderer.js +6 -6
- package/documd.js +102 -17
- package/package.json +1 -1
package/documd.js
CHANGED
|
@@ -31,14 +31,17 @@ const HELP = `documd v${CLI_VERSION} — ${CLI_HOMEPAGE}
|
|
|
31
31
|
Render Markdown / diagrams / books with headless Chrome
|
|
32
32
|
|
|
33
33
|
Usage:
|
|
34
|
-
documd <input> [
|
|
34
|
+
documd <input> [<output>] [--format <f>] [options]
|
|
35
|
+
|
|
36
|
+
The second positional is treated as the output file (pandoc style) when its
|
|
37
|
+
extension is a known output format; the input extension must be a known input
|
|
38
|
+
format (.md/.markdown/.mdown/.mkd/.txt or a diagram source like .puml/.mmd/...).
|
|
35
39
|
|
|
36
40
|
Output formats (--format; inferred from the output extension when omitted):
|
|
37
41
|
html, epub, docx, pdf markdown / SUMMARY.md (--book) documents
|
|
38
42
|
svg, png, drawio diagram sources (PlantUML/Mermaid/DOT/Vega/...)
|
|
39
43
|
|
|
40
44
|
Options:
|
|
41
|
-
-o, --output <file> Output path
|
|
42
45
|
--format <f> html, epub, docx, pdf, svg, png or drawio
|
|
43
46
|
-b, --book Whole-book export: input is a GitBook SUMMARY.md
|
|
44
47
|
--diagram-type <t> Diagram renderer (default: inferred from the extension)
|
|
@@ -92,6 +95,18 @@ const DIAGRAM_EXT_TYPES = {
|
|
|
92
95
|
'.canvas': 'canvas',
|
|
93
96
|
};
|
|
94
97
|
|
|
98
|
+
// Recognised input extensions: Markdown documents plus every diagram source
|
|
99
|
+
// type. Used to decide whether a second positional argument can be treated as
|
|
100
|
+
// the output file (pandoc style) instead of guessing.
|
|
101
|
+
const INPUT_EXT_FORMATS = {
|
|
102
|
+
'.md': 'markdown',
|
|
103
|
+
'.markdown': 'markdown',
|
|
104
|
+
'.mdown': 'markdown',
|
|
105
|
+
'.mkd': 'markdown',
|
|
106
|
+
'.txt': 'markdown',
|
|
107
|
+
...DIAGRAM_EXT_TYPES,
|
|
108
|
+
};
|
|
109
|
+
|
|
95
110
|
function isDiagramInput(inputPath) {
|
|
96
111
|
return Boolean(DIAGRAM_EXT_TYPES[path.extname(inputPath).toLowerCase()]);
|
|
97
112
|
}
|
|
@@ -127,9 +142,6 @@ export function parseArgs(args) {
|
|
|
127
142
|
} else if (arg === '--format') {
|
|
128
143
|
options.format = takeValue(args, i, arg);
|
|
129
144
|
i += 1;
|
|
130
|
-
} else if (arg === '-o' || arg === '--output') {
|
|
131
|
-
options.output = takeValue(args, i, arg);
|
|
132
|
-
i += 1;
|
|
133
145
|
} else if (arg === '-t' || arg === '--theme') {
|
|
134
146
|
options.theme = takeValue(args, i, arg);
|
|
135
147
|
i += 1;
|
|
@@ -170,8 +182,37 @@ export function parseArgs(args) {
|
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
|
|
173
|
-
if (!options.help && !options.version
|
|
174
|
-
|
|
185
|
+
if (!options.help && !options.version) {
|
|
186
|
+
if (positional.length === 1) {
|
|
187
|
+
options.input = positional[0];
|
|
188
|
+
} else if (positional.length === 2) {
|
|
189
|
+
// Pandoc-style second positional: treat it as the output file. Only
|
|
190
|
+
// when both extensions are recognisable — otherwise fail loudly with
|
|
191
|
+
// the unknown format named, instead of guessing.
|
|
192
|
+
const [candidateInput, candidateOutput] = positional;
|
|
193
|
+
const inputExt = path.extname(candidateInput).toLowerCase();
|
|
194
|
+
const outputExt = path.extname(candidateOutput).toLowerCase();
|
|
195
|
+
const inputKnown = INPUT_EXT_FORMATS[inputExt] !== undefined;
|
|
196
|
+
// An explicit --format makes the output extension irrelevant (same as -o).
|
|
197
|
+
const outputKnown = OUTPUT_EXT_FORMATS[outputExt] !== undefined || Boolean(options.format);
|
|
198
|
+
if (inputKnown && outputKnown) {
|
|
199
|
+
options.input = candidateInput;
|
|
200
|
+
options.output = candidateOutput;
|
|
201
|
+
} else {
|
|
202
|
+
const problems = [];
|
|
203
|
+
if (!inputKnown) {
|
|
204
|
+
problems.push(`unknown input format "${inputExt || path.basename(candidateInput)}"`);
|
|
205
|
+
}
|
|
206
|
+
if (!OUTPUT_EXT_FORMATS[outputExt]) {
|
|
207
|
+
problems.push(`unknown output format "${outputExt || path.basename(candidateOutput)}"`);
|
|
208
|
+
}
|
|
209
|
+
throw new Error(
|
|
210
|
+
`Cannot treat "${candidateOutput}" as the output file: ${problems.join(' and ')}; use --format html|epub|docx|pdf|svg|png|drawio`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
throw new Error('Exactly one input file is required (usage: documd <input> [<output>] [options])');
|
|
215
|
+
}
|
|
175
216
|
}
|
|
176
217
|
if (!['hide', 'table', 'raw'].includes(options.frontmatterDisplay)) {
|
|
177
218
|
throw new Error('--frontmatter must be hide, table, or raw');
|
|
@@ -189,8 +230,6 @@ export function parseArgs(args) {
|
|
|
189
230
|
throw new Error('--format must be html, epub, docx, pdf, svg, png or drawio');
|
|
190
231
|
}
|
|
191
232
|
|
|
192
|
-
options.input = positional[0];
|
|
193
|
-
|
|
194
233
|
// help/version need no input or format inference.
|
|
195
234
|
if (options.help || options.version) {
|
|
196
235
|
return options;
|
|
@@ -471,8 +510,14 @@ export async function renderMarkdownFile(options) {
|
|
|
471
510
|
|
|
472
511
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
473
512
|
const browserErrors = [];
|
|
513
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
514
|
+
// concise console.warn messages (with the source line), never as full
|
|
515
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
516
|
+
// rendered twice) are collapsed.
|
|
474
517
|
page.on('console', (message) => {
|
|
475
|
-
if (message.type() === 'error') browserErrors.
|
|
518
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
519
|
+
browserErrors.push(message.text());
|
|
520
|
+
}
|
|
476
521
|
});
|
|
477
522
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
478
523
|
|
|
@@ -585,8 +630,14 @@ export async function exportMarkdownEpub(options) {
|
|
|
585
630
|
|
|
586
631
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
587
632
|
const browserErrors = [];
|
|
633
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
634
|
+
// concise console.warn messages (with the source line), never as full
|
|
635
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
636
|
+
// rendered twice) are collapsed.
|
|
588
637
|
page.on('console', (message) => {
|
|
589
|
-
if (message.type() === 'error') browserErrors.
|
|
638
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
639
|
+
browserErrors.push(message.text());
|
|
640
|
+
}
|
|
590
641
|
});
|
|
591
642
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
592
643
|
|
|
@@ -651,8 +702,14 @@ export async function exportMarkdownDiagram(options) {
|
|
|
651
702
|
|
|
652
703
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
653
704
|
const browserErrors = [];
|
|
705
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
706
|
+
// concise console.warn messages (with the source line), never as full
|
|
707
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
708
|
+
// rendered twice) are collapsed.
|
|
654
709
|
page.on('console', (message) => {
|
|
655
|
-
if (message.type() === 'error') browserErrors.
|
|
710
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
711
|
+
browserErrors.push(message.text());
|
|
712
|
+
}
|
|
656
713
|
});
|
|
657
714
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
658
715
|
|
|
@@ -727,8 +784,14 @@ export async function exportMarkdownDocx(options) {
|
|
|
727
784
|
|
|
728
785
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
729
786
|
const browserErrors = [];
|
|
787
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
788
|
+
// concise console.warn messages (with the source line), never as full
|
|
789
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
790
|
+
// rendered twice) are collapsed.
|
|
730
791
|
page.on('console', (message) => {
|
|
731
|
-
if (message.type() === 'error') browserErrors.
|
|
792
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
793
|
+
browserErrors.push(message.text());
|
|
794
|
+
}
|
|
732
795
|
});
|
|
733
796
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
734
797
|
|
|
@@ -795,8 +858,14 @@ export async function exportMarkdownBook(options) {
|
|
|
795
858
|
|
|
796
859
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
797
860
|
const browserErrors = [];
|
|
861
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
862
|
+
// concise console.warn messages (with the source line), never as full
|
|
863
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
864
|
+
// rendered twice) are collapsed.
|
|
798
865
|
page.on('console', (message) => {
|
|
799
|
-
if (message.type() === 'error') browserErrors.
|
|
866
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
867
|
+
browserErrors.push(message.text());
|
|
868
|
+
}
|
|
800
869
|
});
|
|
801
870
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
802
871
|
|
|
@@ -850,7 +919,7 @@ function pdfOptions() {
|
|
|
850
919
|
}
|
|
851
920
|
|
|
852
921
|
function doneMessage(action, outputPath) {
|
|
853
|
-
return `${action} ${outputPath}
|
|
922
|
+
return `${action} ${outputPath}`;
|
|
854
923
|
}
|
|
855
924
|
|
|
856
925
|
/**
|
|
@@ -878,8 +947,14 @@ export async function exportMarkdownPdf(options) {
|
|
|
878
947
|
|
|
879
948
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
880
949
|
const browserErrors = [];
|
|
950
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
951
|
+
// concise console.warn messages (with the source line), never as full
|
|
952
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
953
|
+
// rendered twice) are collapsed.
|
|
881
954
|
page.on('console', (message) => {
|
|
882
|
-
if (message.type() === 'error') browserErrors.
|
|
955
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
956
|
+
browserErrors.push(message.text());
|
|
957
|
+
}
|
|
883
958
|
});
|
|
884
959
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
885
960
|
|
|
@@ -947,8 +1022,14 @@ export async function exportMarkdownBookPdf(options) {
|
|
|
947
1022
|
|
|
948
1023
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
949
1024
|
const browserErrors = [];
|
|
1025
|
+
// Collect errors AND warnings: page-side render problems are logged as
|
|
1026
|
+
// concise console.warn messages (with the source line), never as full
|
|
1027
|
+
// stack-trace error dumps. Identical repeats (e.g. the same diagram
|
|
1028
|
+
// rendered twice) are collapsed.
|
|
950
1029
|
page.on('console', (message) => {
|
|
951
|
-
if (message.type() === 'error') browserErrors.
|
|
1030
|
+
if ((message.type() === 'error' || message.type() === 'warning') && !browserErrors.includes(message.text())) {
|
|
1031
|
+
browserErrors.push(message.text());
|
|
1032
|
+
}
|
|
952
1033
|
});
|
|
953
1034
|
page.on('pageerror', (error) => browserErrors.push(error.message));
|
|
954
1035
|
|
|
@@ -1001,6 +1082,10 @@ async function main() {
|
|
|
1001
1082
|
process.stdout.write(HELP);
|
|
1002
1083
|
return;
|
|
1003
1084
|
}
|
|
1085
|
+
// Startup banner: the version and homepage are shown when the CLI starts
|
|
1086
|
+
// (--version/--help print their own header); the completion message below
|
|
1087
|
+
// stays a clean "Rendered/Exported <path>".
|
|
1088
|
+
process.stdout.write(`documd v${CLI_VERSION} — ${CLI_HOMEPAGE}\n`);
|
|
1004
1089
|
if (options.bookMode) {
|
|
1005
1090
|
if (options.format === 'pdf') {
|
|
1006
1091
|
const result = await exportMarkdownBookPdf(options);
|