@md2nativedocx/cli 0.0.0-stage → 0.2.1
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 +114 -2
- package/THIRD_PARTY_NOTICES.md +38 -0
- package/assets/README.md +65 -0
- package/assets/md2nativedocx.opendocument +171 -0
- package/assets/reference.docx +0 -0
- package/assets/reference.odt +0 -0
- package/bin/md2nativedocx.mjs +209 -0
- package/package.json +62 -4
- package/src/chartParts.mjs +177 -0
- package/src/cliSupport.mjs +30 -0
- package/src/convert.d.mts +97 -0
- package/src/convert.mjs +274 -0
- package/src/envOptions.mjs +88 -0
- package/src/postprocess.mjs +628 -0
- package/src/pptxExport.mjs +102 -0
- package/src/referenceDocBuilder.mjs +521 -0
- package/src/unclosedFences.mjs +48 -0
- package/src/wordCheck.mjs +125 -0
- package/src/writeOutputSafely.mjs +69 -0
- package/src/zipUtils.mjs +38 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `MD2NATIVEDOCX_*` environment variables, read into {@link convert}'s typed options.
|
|
3
|
+
*
|
|
4
|
+
* The variables stay the CLI's configuration interface: the VS Code extension's `exportService.ts` sets
|
|
5
|
+
* them from its settings, and a standalone user can set them by hand. Only this adapter reads them
|
|
6
|
+
* (docs/specs/01-v2-engine-spec.md §8); `convert()` itself never looks at the environment.
|
|
7
|
+
*
|
|
8
|
+
* Variables the CLI sets for the Lua filter and the bridge (`_SMARTART_DIR`, `_CHART_DIR`, `_NODE_BIN`,
|
|
9
|
+
* `_PAGE_*_TWIPS`, `_MARGIN_*_TWIPS`) are not inputs and are not read here.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync } from 'node:fs';
|
|
13
|
+
|
|
14
|
+
/** Whether any page/typography option is set (they are ignored under a custom reference document). */
|
|
15
|
+
export function hasLayoutOptions(layout) {
|
|
16
|
+
return Object.values(layout ?? {}).some((v) => v !== undefined);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {NodeJS.ProcessEnv} env
|
|
21
|
+
* @returns {import('./convert.d.mts').ConvertOptions}
|
|
22
|
+
*/
|
|
23
|
+
export function readConvertOptionsFromEnv(env) {
|
|
24
|
+
const str = (name) => {
|
|
25
|
+
const v = env[name];
|
|
26
|
+
return v && v.trim() !== '' ? v.trim() : undefined;
|
|
27
|
+
};
|
|
28
|
+
const num = (name) => {
|
|
29
|
+
const v = env[name];
|
|
30
|
+
if (v === undefined || v.trim() === '') return undefined;
|
|
31
|
+
const n = Number(v);
|
|
32
|
+
return Number.isFinite(n) ? n : undefined;
|
|
33
|
+
};
|
|
34
|
+
const positiveInt = (name) => {
|
|
35
|
+
const n = Number.parseInt(env[name] ?? '', 10);
|
|
36
|
+
return Number.isFinite(n) && n > 0 ? n : undefined;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const marginsCustomCm = {
|
|
40
|
+
top: num('MD2NATIVEDOCX_MARGINS_CUSTOM_TOP'),
|
|
41
|
+
right: num('MD2NATIVEDOCX_MARGINS_CUSTOM_RIGHT'),
|
|
42
|
+
bottom: num('MD2NATIVEDOCX_MARGINS_CUSTOM_BOTTOM'),
|
|
43
|
+
left: num('MD2NATIVEDOCX_MARGINS_CUSTOM_LEFT'),
|
|
44
|
+
};
|
|
45
|
+
const layout = {
|
|
46
|
+
pageSize: str('MD2NATIVEDOCX_PAGE_SIZE'),
|
|
47
|
+
orientation: str('MD2NATIVEDOCX_ORIENTATION'),
|
|
48
|
+
margins: str('MD2NATIVEDOCX_MARGINS'),
|
|
49
|
+
marginsCustomCm: Object.values(marginsCustomCm).some((v) => v !== undefined) ? marginsCustomCm : undefined,
|
|
50
|
+
headingFont: str('MD2NATIVEDOCX_HEADING_FONT'),
|
|
51
|
+
bodyFont: str('MD2NATIVEDOCX_BODY_FONT'),
|
|
52
|
+
fontSizePt: num('MD2NATIVEDOCX_FONT_SIZE'),
|
|
53
|
+
lineSpacing: str('MD2NATIVEDOCX_LINE_SPACING'),
|
|
54
|
+
justify: str('MD2NATIVEDOCX_JUSTIFY'),
|
|
55
|
+
accentColor: str('MD2NATIVEDOCX_ACCENT_COLOR'),
|
|
56
|
+
tableHeaderColor: str('MD2NATIVEDOCX_TABLE_HEADER_COLOR'),
|
|
57
|
+
footerPageNumber: env.MD2NATIVEDOCX_FOOTER_PAGE_NUMBER === '1' ? true : undefined,
|
|
58
|
+
landscapeTables: env.MD2NATIVEDOCX_LANDSCAPE_TABLES === '1' ? true : undefined,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Unset or `1`: every chartable type; `0`: none; otherwise a comma-separated list of types.
|
|
62
|
+
const chartsRaw = (env.MD2NATIVEDOCX_NATIVE_CHARTS ?? '').trim();
|
|
63
|
+
const nativeCharts = chartsRaw === '' || chartsRaw === '1' ? true : chartsRaw === '0' ? false : chartsRaw.split(',').map((t) => t.trim());
|
|
64
|
+
|
|
65
|
+
const tocDepth = Number(env.MD2NATIVEDOCX_TOC_DEPTH);
|
|
66
|
+
// A reference document that does not exist is ignored (the bundled one is used), as it always was.
|
|
67
|
+
const referenceDoc = env.MD2NATIVEDOCX_REFERENCE_DOC && existsSync(env.MD2NATIVEDOCX_REFERENCE_DOC) ? env.MD2NATIVEDOCX_REFERENCE_DOC : undefined;
|
|
68
|
+
|
|
69
|
+
/** @type {import('./convert.d.mts').ConvertOptions} */
|
|
70
|
+
const options = {
|
|
71
|
+
layout,
|
|
72
|
+
toc: env.MD2NATIVEDOCX_TOC === '1',
|
|
73
|
+
emojiFont: env.MD2NATIVEDOCX_EMOJI_FONT !== '0',
|
|
74
|
+
// SmartArt and native charts are on by default, as in the VS Code extension; `0` turns them off.
|
|
75
|
+
smartArt: env.MD2NATIVEDOCX_ENABLE_SMARTART !== '0',
|
|
76
|
+
smartArtDrawing: env.MD2NATIVEDOCX_SMARTART_DRAWING !== '0',
|
|
77
|
+
nativeCharts,
|
|
78
|
+
};
|
|
79
|
+
if (Number.isFinite(tocDepth)) options.tocDepth = tocDepth;
|
|
80
|
+
if (referenceDoc) options.referenceDoc = referenceDoc;
|
|
81
|
+
if (env.MD2NATIVEDOCX_SMARTART_STYLE !== undefined) options.smartArtStyle = env.MD2NATIVEDOCX_SMARTART_STYLE;
|
|
82
|
+
const maxDrawingCx = positiveInt('MD2NATIVEDOCX_MAX_DRAWING_CX');
|
|
83
|
+
const maxDrawingCy = positiveInt('MD2NATIVEDOCX_MAX_DRAWING_CY');
|
|
84
|
+
if (maxDrawingCx !== undefined) options.maxDrawingCx = maxDrawingCx;
|
|
85
|
+
if (maxDrawingCy !== undefined) options.maxDrawingCy = maxDrawingCy;
|
|
86
|
+
if (env.MD2NATIVEDOCX_PANDOC_BIN) options.pandocBin = env.MD2NATIVEDOCX_PANDOC_BIN;
|
|
87
|
+
return options;
|
|
88
|
+
}
|