@unified-latex/unified-latex-cli 1.0.11 → 1.1.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/index.cjs +768 -0
- package/index.cjs.map +2 -2
- package/index.js +96 -41
- package/index.js.map +2 -2
- package/package.json +12 -12
- package/unified-latex-cli.mjs +97 -41
- package/unified-latex-cli.mjs.map +2 -2
package/index.cjs
ADDED
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
|
|
21
|
+
// libs/unified-latex.ts
|
|
22
|
+
var import_unified = require("unified");
|
|
23
|
+
var import_unified_latex_util_parse = require("@unified-latex/unified-latex-util-parse");
|
|
24
|
+
var import_unified_latex_util_to_string = require("@unified-latex/unified-latex-util-to-string");
|
|
25
|
+
var processLatexViaUnified = (options2) => {
|
|
26
|
+
return (0, import_unified.unified)().use(import_unified_latex_util_parse.unifiedLatexFromString).use(
|
|
27
|
+
import_unified_latex_util_to_string.unifiedLatexStringCompiler,
|
|
28
|
+
Object.assign({ pretty: true, forceNewlineEnding: true }, options2)
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// libs/unified-args/index.ts
|
|
33
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
34
|
+
var import_node_stream = __toESM(require("node:stream"), 1);
|
|
35
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
36
|
+
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
37
|
+
var import_unified_engine = require("unified-engine");
|
|
38
|
+
var import_unified_latex_to_hast = require("@unified-latex/unified-latex-to-hast");
|
|
39
|
+
|
|
40
|
+
// libs/unified-args/options.ts
|
|
41
|
+
var import_text_table = __toESM(require("text-table"), 1);
|
|
42
|
+
var import_camelcase = __toESM(require("camelcase"), 1);
|
|
43
|
+
var import_minimist = __toESM(require("minimist"), 1);
|
|
44
|
+
var import_json52 = __toESM(require("json5"), 1);
|
|
45
|
+
var import_fault = require("fault");
|
|
46
|
+
|
|
47
|
+
// libs/lints/index.ts
|
|
48
|
+
var import_unified_latex_lint = require("@unified-latex/unified-latex-lint");
|
|
49
|
+
var availableLints = Object.fromEntries(
|
|
50
|
+
Object.values(import_unified_latex_lint.lints).map((lint) => [
|
|
51
|
+
lint.name.replace(/^unified-latex-lint:/, ""),
|
|
52
|
+
lint
|
|
53
|
+
])
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// libs/unified-args/schema.ts
|
|
57
|
+
var schema = [
|
|
58
|
+
{
|
|
59
|
+
long: "help",
|
|
60
|
+
description: "Output usage information",
|
|
61
|
+
short: "h",
|
|
62
|
+
type: "boolean",
|
|
63
|
+
default: false
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
long: "version",
|
|
67
|
+
description: "Output version number",
|
|
68
|
+
short: "v",
|
|
69
|
+
type: "boolean",
|
|
70
|
+
default: false
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
long: "output",
|
|
74
|
+
description: "Specify output location",
|
|
75
|
+
short: "o",
|
|
76
|
+
value: "[path]"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
long: "rc-path",
|
|
80
|
+
description: "Specify configuration file",
|
|
81
|
+
short: "r",
|
|
82
|
+
type: "string",
|
|
83
|
+
value: "<path>"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
long: "ignore-path",
|
|
87
|
+
description: "Specify ignore file",
|
|
88
|
+
short: "i",
|
|
89
|
+
type: "string",
|
|
90
|
+
value: "<path>"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
long: "ext",
|
|
94
|
+
description: "Specify extensions",
|
|
95
|
+
type: "string",
|
|
96
|
+
value: "<extensions>"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
long: "lint",
|
|
100
|
+
description: `Lint rules to apply. Use multiple times to specify multiple lints. Available rules: ${Object.keys(
|
|
101
|
+
availableLints
|
|
102
|
+
).join(", ")}`,
|
|
103
|
+
short: "l",
|
|
104
|
+
type: "string",
|
|
105
|
+
value: "<rule>"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
long: "lint-all",
|
|
109
|
+
description: `Apply all available lint rules`,
|
|
110
|
+
type: "boolean",
|
|
111
|
+
default: false
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
long: "fix-all",
|
|
115
|
+
description: "Apply fixes for all applied lints",
|
|
116
|
+
type: "boolean",
|
|
117
|
+
default: false
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
long: "watch",
|
|
121
|
+
description: "Watch for changes and reprocess",
|
|
122
|
+
short: "w",
|
|
123
|
+
type: "boolean",
|
|
124
|
+
default: false
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
long: "macro",
|
|
128
|
+
description: "Attach arguments of the specified macro (by default, unrecognized macros are parsed as having no arguments). Accepts a string of the form `\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`",
|
|
129
|
+
short: "m",
|
|
130
|
+
type: "string",
|
|
131
|
+
value: "<rule>"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
long: "expand-macro",
|
|
135
|
+
description: "Expand the specified macro. Accepts a string of the form `\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`",
|
|
136
|
+
short: "e",
|
|
137
|
+
type: "string",
|
|
138
|
+
value: "<rule>"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
long: "frail",
|
|
142
|
+
description: "Exit with 1 on warnings",
|
|
143
|
+
type: "boolean",
|
|
144
|
+
default: false
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
long: "tree",
|
|
148
|
+
description: "Specify input and output as syntax tree",
|
|
149
|
+
type: "boolean",
|
|
150
|
+
default: false
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
long: "report",
|
|
154
|
+
description: "Specify reporter",
|
|
155
|
+
type: "string",
|
|
156
|
+
value: "<reporter>"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
long: "file-path",
|
|
160
|
+
description: "Specify path to process as",
|
|
161
|
+
type: "string",
|
|
162
|
+
value: "<path>"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
long: "ignore-path-resolve-from",
|
|
166
|
+
description: "Resolve patterns in `ignore-path` from its directory or cwd",
|
|
167
|
+
type: "string",
|
|
168
|
+
value: "dir|cwd",
|
|
169
|
+
default: "dir"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
long: "ignore-pattern",
|
|
173
|
+
description: "Specify ignore patterns",
|
|
174
|
+
type: "string",
|
|
175
|
+
value: "<globs>"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
long: "silently-ignore",
|
|
179
|
+
description: "Do not fail when given ignored files",
|
|
180
|
+
type: "boolean"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
long: "tree-in",
|
|
184
|
+
description: "Specify input as syntax tree",
|
|
185
|
+
type: "boolean"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
long: "tree-out",
|
|
189
|
+
description: "Output syntax tree",
|
|
190
|
+
type: "boolean"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
long: "inspect",
|
|
194
|
+
description: "Output formatted syntax tree",
|
|
195
|
+
type: "boolean"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
long: "stats",
|
|
199
|
+
description: "Show information about the processed file",
|
|
200
|
+
type: "boolean",
|
|
201
|
+
default: false
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
long: "stats-json",
|
|
205
|
+
description: "Show information about the processed file and output the information as JSON",
|
|
206
|
+
type: "boolean",
|
|
207
|
+
default: false
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
long: "html",
|
|
211
|
+
description: "Convert the output to HTML. Note, for math to render properly, you will need to add a library like MathJax or KaTeX to your HTMl source; you should also expand/replace any macros not recognized by the converter",
|
|
212
|
+
type: "boolean",
|
|
213
|
+
default: false
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
long: "stdout",
|
|
217
|
+
description: "[Don't] write the processed file's contents to stdout",
|
|
218
|
+
type: "boolean",
|
|
219
|
+
truelike: true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
long: "color",
|
|
223
|
+
description: "Specify color in report",
|
|
224
|
+
type: "boolean",
|
|
225
|
+
default: true
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
long: "config",
|
|
229
|
+
description: "Search for configuration files",
|
|
230
|
+
type: "boolean",
|
|
231
|
+
default: true
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
long: "ignore",
|
|
235
|
+
description: "Search for ignore files",
|
|
236
|
+
type: "boolean",
|
|
237
|
+
default: true
|
|
238
|
+
}
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
// libs/macros/parse-macro-expansion.ts
|
|
242
|
+
var import_json5 = __toESM(require("json5"), 1);
|
|
243
|
+
var import_unified_latex_util_macros = require("@unified-latex/unified-latex-util-macros");
|
|
244
|
+
var import_unified_latex_util_parse2 = require("@unified-latex/unified-latex-util-parse");
|
|
245
|
+
function parseMacroExpansion(def) {
|
|
246
|
+
if (def.startsWith("\\")) {
|
|
247
|
+
const macro = (0, import_unified_latex_util_parse2.parse)(def).content[0];
|
|
248
|
+
const name = (0, import_unified_latex_util_macros.newcommandMacroToName)(macro);
|
|
249
|
+
if (!name) {
|
|
250
|
+
throw new Error(
|
|
251
|
+
`Could extract macro definition from "${def}"; expected the macro to be defined via \\newcommand or similar syntax`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
const signature = (0, import_unified_latex_util_macros.newcommandMacroToSpec)(macro);
|
|
255
|
+
const body = (0, import_unified_latex_util_macros.newcommandMacroToSubstitutionAst)(macro);
|
|
256
|
+
return { name, signature, body };
|
|
257
|
+
}
|
|
258
|
+
const parsedSpec = import_json5.default.parse(def);
|
|
259
|
+
if (parsedSpec.name == null || parsedSpec.body == null) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
`Expected a "name" field and a "body" field to be defined on ${def}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
parsedSpec.signature = parsedSpec.signature || "";
|
|
265
|
+
return {
|
|
266
|
+
name: parsedSpec.name,
|
|
267
|
+
signature: parsedSpec.signature,
|
|
268
|
+
body: (0, import_unified_latex_util_parse2.parse)(parsedSpec.body).content
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// libs/unified-args/options.ts
|
|
273
|
+
var own = {}.hasOwnProperty;
|
|
274
|
+
var minischema = {
|
|
275
|
+
unknown: handleUnknownArgument,
|
|
276
|
+
default: {},
|
|
277
|
+
alias: {},
|
|
278
|
+
string: [],
|
|
279
|
+
boolean: []
|
|
280
|
+
};
|
|
281
|
+
var index = -1;
|
|
282
|
+
while (++index < schema.length) {
|
|
283
|
+
addEach(schema[index]);
|
|
284
|
+
}
|
|
285
|
+
function options(flags, configuration) {
|
|
286
|
+
const extension = configuration.extensions[0];
|
|
287
|
+
const name = configuration.name;
|
|
288
|
+
const config = toCamelCase((0, import_minimist.default)(flags, minischema));
|
|
289
|
+
let index2 = -1;
|
|
290
|
+
while (++index2 < schema.length) {
|
|
291
|
+
const option = schema[index2];
|
|
292
|
+
if (option.type === "string" && config[option.long] === "") {
|
|
293
|
+
throw (0, import_fault.fault)("Missing value:%s", inspect(option).join(" "));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const ext = commaSeparated(config.ext);
|
|
297
|
+
const report = reporter(config.report);
|
|
298
|
+
const help = [
|
|
299
|
+
inspectAll(schema),
|
|
300
|
+
"",
|
|
301
|
+
"Examples:",
|
|
302
|
+
"",
|
|
303
|
+
" # Process `input." + extension + "`",
|
|
304
|
+
" $ " + name + " input." + extension + " -o output." + extension,
|
|
305
|
+
"",
|
|
306
|
+
" # Pipe",
|
|
307
|
+
" $ " + name + " < input." + extension + " > output." + extension,
|
|
308
|
+
"",
|
|
309
|
+
" # Rewrite all applicable files",
|
|
310
|
+
" $ " + name + " . -o",
|
|
311
|
+
"",
|
|
312
|
+
" # Lint files and display the lint output (but not the processed file)",
|
|
313
|
+
" $ " + name + " . --lint-all --no-stdout"
|
|
314
|
+
].join("\n");
|
|
315
|
+
const settings = parseSettings(config.setting);
|
|
316
|
+
if (config.html && config.statsJson) {
|
|
317
|
+
throw new Error("Both --html and --stats-json were specified; only one may be used at a time.");
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
helpMessage: help,
|
|
321
|
+
cwd: configuration.cwd,
|
|
322
|
+
processor: configuration.processor,
|
|
323
|
+
help: config.help,
|
|
324
|
+
version: config.version,
|
|
325
|
+
files: config._,
|
|
326
|
+
filePath: config.filePath,
|
|
327
|
+
watch: config.watch,
|
|
328
|
+
extensions: ext.length === 0 ? configuration.extensions : ext,
|
|
329
|
+
output: config.output,
|
|
330
|
+
out: config.stdout,
|
|
331
|
+
tree: config.tree,
|
|
332
|
+
treeIn: config.treeIn,
|
|
333
|
+
treeOut: config.treeOut,
|
|
334
|
+
inspect: config.inspect,
|
|
335
|
+
rcName: configuration.rcName,
|
|
336
|
+
packageField: configuration.packageField,
|
|
337
|
+
rcPath: config.rcPath,
|
|
338
|
+
detectConfig: config.config,
|
|
339
|
+
settings,
|
|
340
|
+
ignoreName: configuration.ignoreName,
|
|
341
|
+
ignorePath: config.ignorePath,
|
|
342
|
+
ignorePathResolveFrom: config.ignorePathResolveFrom,
|
|
343
|
+
ignorePatterns: commaSeparated(config.ignorePattern),
|
|
344
|
+
silentlyIgnore: config.silentlyIgnore,
|
|
345
|
+
detectIgnore: config.ignore,
|
|
346
|
+
pluginPrefix: configuration.pluginPrefix,
|
|
347
|
+
plugins: [],
|
|
348
|
+
lints: normalizeLints(config.lint, config),
|
|
349
|
+
reporter: report[0],
|
|
350
|
+
reporterOptions: report[1],
|
|
351
|
+
color: config.color,
|
|
352
|
+
silent: config.silent,
|
|
353
|
+
quiet: config.quiet,
|
|
354
|
+
frail: config.frail,
|
|
355
|
+
stats: config.stats,
|
|
356
|
+
statsJson: config.statsJson,
|
|
357
|
+
expandMacro: normalizeToArray(config.expandMacro).map(
|
|
358
|
+
parseMacroExpansion
|
|
359
|
+
),
|
|
360
|
+
macro: normalizeToArray(config.macro).map(
|
|
361
|
+
parseMacroExpansion
|
|
362
|
+
),
|
|
363
|
+
html: config.html
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function addEach(option) {
|
|
367
|
+
const value = option.default;
|
|
368
|
+
minischema.default[option.long] = value === void 0 ? null : value;
|
|
369
|
+
if (option.type && option.type in minischema) {
|
|
370
|
+
minischema[option.type].push(option.long);
|
|
371
|
+
}
|
|
372
|
+
if (option.short) {
|
|
373
|
+
minischema.alias[option.short] = option.long;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function commaSeparated(value) {
|
|
377
|
+
return normalizeToArray(value).flatMap((d) => splitOnComma(d));
|
|
378
|
+
}
|
|
379
|
+
function normalizeLints(value, config) {
|
|
380
|
+
const normalized = normalizeToArray(value).map(splitOnEquals);
|
|
381
|
+
validateLintNames(normalized);
|
|
382
|
+
if (config.lintAll) {
|
|
383
|
+
normalized.push(...Object.keys(availableLints).map((v) => [v]));
|
|
384
|
+
}
|
|
385
|
+
const result = Object.fromEntries(
|
|
386
|
+
normalized.map((value2) => {
|
|
387
|
+
let params = value2[1] ? parseConfig(value2[1], {}) : void 0;
|
|
388
|
+
if (config.fixAll) {
|
|
389
|
+
if (params) {
|
|
390
|
+
Object.assign(params, { fix: true });
|
|
391
|
+
} else {
|
|
392
|
+
params = { fix: true };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return [value2[0], params];
|
|
396
|
+
})
|
|
397
|
+
);
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
function reporter(value) {
|
|
401
|
+
const all = normalizeToArray(value).map(splitOnEquals).map((value2) => [
|
|
402
|
+
value2[0],
|
|
403
|
+
value2[1] ? parseConfig(value2[1], {}) : void 0
|
|
404
|
+
]);
|
|
405
|
+
return all[all.length - 1] || [];
|
|
406
|
+
}
|
|
407
|
+
function parseSettings(value) {
|
|
408
|
+
const normalized = normalizeToArray(value);
|
|
409
|
+
const cache = {};
|
|
410
|
+
for (const value2 of normalized) {
|
|
411
|
+
parseConfig(value2, cache);
|
|
412
|
+
}
|
|
413
|
+
return cache;
|
|
414
|
+
}
|
|
415
|
+
function parseConfig(value, cache) {
|
|
416
|
+
let flags;
|
|
417
|
+
let flag;
|
|
418
|
+
try {
|
|
419
|
+
flags = toCamelCase(parseJSON(value));
|
|
420
|
+
} catch (error) {
|
|
421
|
+
const exception = error;
|
|
422
|
+
throw (0, import_fault.fault)(
|
|
423
|
+
"Cannot parse `%s` as JSON: %s",
|
|
424
|
+
value,
|
|
425
|
+
exception.message.replace(/at(?= position)/, "around")
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
for (flag in flags) {
|
|
429
|
+
if (own.call(flags, flag)) {
|
|
430
|
+
cache[flag] = flags[flag];
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return cache;
|
|
434
|
+
}
|
|
435
|
+
function validateLintNames(lints2) {
|
|
436
|
+
for (const lint of lints2) {
|
|
437
|
+
const name = lint[0];
|
|
438
|
+
if (!availableLints[name]) {
|
|
439
|
+
const known = Object.keys(availableLints);
|
|
440
|
+
throw (0, import_fault.fault)(
|
|
441
|
+
"Unknown lint rule `%s`, available rules are:\n%s",
|
|
442
|
+
name,
|
|
443
|
+
" " + known.join("\n ")
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
function handleUnknownArgument(flag) {
|
|
450
|
+
if (flag.charAt(0) === "-") {
|
|
451
|
+
if (flag.charAt(1) === "-") {
|
|
452
|
+
throw (0, import_fault.fault)(
|
|
453
|
+
"Unknown option `%s`, expected:\n%s",
|
|
454
|
+
flag,
|
|
455
|
+
inspectAll(schema)
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
const found = flag.slice(1).split("");
|
|
459
|
+
const known = schema.filter((d) => d.short);
|
|
460
|
+
const knownKeys = new Set(known.map((d) => d.short));
|
|
461
|
+
let index2 = -1;
|
|
462
|
+
while (++index2 < found.length) {
|
|
463
|
+
const key = found[index2];
|
|
464
|
+
if (!knownKeys.has(key)) {
|
|
465
|
+
throw (0, import_fault.fault)(
|
|
466
|
+
"Unknown short option `-%s`, expected:\n%s",
|
|
467
|
+
key,
|
|
468
|
+
inspectAll(known)
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
function inspectAll(options2) {
|
|
476
|
+
return (0, import_text_table.default)(options2.map((d) => inspect(d)));
|
|
477
|
+
}
|
|
478
|
+
function inspect(option) {
|
|
479
|
+
let description = option.description;
|
|
480
|
+
let long = option.long;
|
|
481
|
+
if (option.default === true || option.truelike) {
|
|
482
|
+
description += " (on by default)";
|
|
483
|
+
long = "[no-]" + long;
|
|
484
|
+
}
|
|
485
|
+
return [
|
|
486
|
+
"",
|
|
487
|
+
option.short ? "-" + option.short : "",
|
|
488
|
+
"--" + long + (option.value ? " " + option.value : ""),
|
|
489
|
+
description
|
|
490
|
+
];
|
|
491
|
+
}
|
|
492
|
+
function normalizeToArray(value) {
|
|
493
|
+
if (!value) {
|
|
494
|
+
return [];
|
|
495
|
+
}
|
|
496
|
+
if (typeof value === "string") {
|
|
497
|
+
return [value];
|
|
498
|
+
}
|
|
499
|
+
return value;
|
|
500
|
+
}
|
|
501
|
+
function splitOnEquals(value) {
|
|
502
|
+
return value.split("=");
|
|
503
|
+
}
|
|
504
|
+
function splitOnComma(value) {
|
|
505
|
+
return value.split(",");
|
|
506
|
+
}
|
|
507
|
+
function toCamelCase(object) {
|
|
508
|
+
const result = {};
|
|
509
|
+
let key;
|
|
510
|
+
for (key in object) {
|
|
511
|
+
if (own.call(object, key)) {
|
|
512
|
+
let value = object[key];
|
|
513
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
514
|
+
value = toCamelCase(value);
|
|
515
|
+
}
|
|
516
|
+
result[(0, import_camelcase.default)(key)] = value;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
521
|
+
function parseJSON(value) {
|
|
522
|
+
return import_json52.default.parse("{" + value + "}");
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// libs/stats/index.ts
|
|
526
|
+
var import_unified_latex_util_packages = require("@unified-latex/unified-latex-util-packages");
|
|
527
|
+
var import_unified_latex_util_macros2 = require("@unified-latex/unified-latex-util-macros");
|
|
528
|
+
var import_unified_latex_util_print_raw = require("@unified-latex/unified-latex-util-print-raw");
|
|
529
|
+
|
|
530
|
+
// libs/stats/enclosing-position.ts
|
|
531
|
+
function enclosingPosition(nodes) {
|
|
532
|
+
var _a, _b, _c, _d;
|
|
533
|
+
let start = { line: 1, column: 1, offset: 0 };
|
|
534
|
+
let end = { line: 1, column: 1, offset: 0 };
|
|
535
|
+
for (const node of nodes) {
|
|
536
|
+
if (Number((_a = node.position) == null ? void 0 : _a.start.offset) < Number(start.offset)) {
|
|
537
|
+
start = (_b = node.position) == null ? void 0 : _b.start;
|
|
538
|
+
}
|
|
539
|
+
if (Number((_c = node.position) == null ? void 0 : _c.end.offset) > Number(end.offset)) {
|
|
540
|
+
end = (_d = node.position) == null ? void 0 : _d.end;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return { start, end };
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// libs/stats/index.ts
|
|
547
|
+
var statsPlugin = function() {
|
|
548
|
+
return (tree, file) => {
|
|
549
|
+
const packages = (0, import_unified_latex_util_packages.listPackages)(tree);
|
|
550
|
+
const packageNames = packages.map((s) => (0, import_unified_latex_util_print_raw.printRaw)(s));
|
|
551
|
+
if (packages.length > 0) {
|
|
552
|
+
file.info(
|
|
553
|
+
`Found ${packages.length} imported packages: ${packageNames.join(", ")}`
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
const newcommands = (0, import_unified_latex_util_macros2.listNewcommands)(tree);
|
|
557
|
+
if (newcommands.length > 0) {
|
|
558
|
+
file.info(
|
|
559
|
+
`Found ${newcommands.length} defined commands: ${newcommands.map((c) => `\\${c.name}`).join(", ")}`,
|
|
560
|
+
enclosingPosition(newcommands.map((c) => c.definition))
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
var statsJsonPlugin = function() {
|
|
566
|
+
this.Compiler = (tree, file) => {
|
|
567
|
+
file.extname = ".json";
|
|
568
|
+
file.basename += "-stats";
|
|
569
|
+
const packages = (0, import_unified_latex_util_packages.listPackages)(tree).map((s) => (0, import_unified_latex_util_print_raw.printRaw)(s));
|
|
570
|
+
const newcommands = (0, import_unified_latex_util_macros2.listNewcommands)(tree).map((c) => ({
|
|
571
|
+
name: c.name,
|
|
572
|
+
signature: c.signature,
|
|
573
|
+
body: (0, import_unified_latex_util_print_raw.printRaw)(c.body),
|
|
574
|
+
definition: (0, import_unified_latex_util_print_raw.printRaw)(c.definition)
|
|
575
|
+
}));
|
|
576
|
+
return JSON.stringify({ packages, newcommands }, null, 4) + "\n";
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// libs/macros/expand-macros-plugin.ts
|
|
581
|
+
var import_unified_latex_util_macros3 = require("@unified-latex/unified-latex-util-macros");
|
|
582
|
+
var import_unified_latex_util_arguments = require("@unified-latex/unified-latex-util-arguments");
|
|
583
|
+
var expandMacrosPlugin = function(options2) {
|
|
584
|
+
const { macros = [] } = options2 || {};
|
|
585
|
+
const macroInfo = Object.fromEntries(
|
|
586
|
+
macros.map((m) => [m.name, { signature: m.signature }])
|
|
587
|
+
);
|
|
588
|
+
return (tree) => {
|
|
589
|
+
(0, import_unified_latex_util_arguments.attachMacroArgs)(tree, macroInfo);
|
|
590
|
+
(0, import_unified_latex_util_macros3.expandMacros)(tree, macros);
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// libs/macros/attach-macro-args-plugin.ts
|
|
595
|
+
var import_unified_latex_util_arguments2 = require("@unified-latex/unified-latex-util-arguments");
|
|
596
|
+
var attachMacroArgsPlugin = function(options2) {
|
|
597
|
+
const { macros = [] } = options2 || {};
|
|
598
|
+
const macroInfo = Object.fromEntries(
|
|
599
|
+
macros.map((m) => [m.name, { signature: m.signature }])
|
|
600
|
+
);
|
|
601
|
+
return (tree) => {
|
|
602
|
+
(0, import_unified_latex_util_arguments2.attachMacroArgs)(tree, macroInfo);
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// libs/html/format.ts
|
|
607
|
+
var import_rehype_stringify = __toESM(require("rehype-stringify"), 1);
|
|
608
|
+
var import_prettier = __toESM(require("prettier"), 1);
|
|
609
|
+
var import_unified2 = require("unified");
|
|
610
|
+
var prettyPrintHtmlPlugin = function() {
|
|
611
|
+
const processor = (0, import_unified2.unified)().use(import_rehype_stringify.default);
|
|
612
|
+
this.Compiler = (tree, file) => {
|
|
613
|
+
file.extname = ".html";
|
|
614
|
+
const html = processor.stringify(tree, file);
|
|
615
|
+
try {
|
|
616
|
+
return import_prettier.default.format(html, { parser: "html", useTabs: true });
|
|
617
|
+
} catch {
|
|
618
|
+
}
|
|
619
|
+
return html;
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
// libs/unified-args/index.ts
|
|
624
|
+
var ttyStream = Object.assign(new import_node_stream.default.Readable(), { isTTY: true });
|
|
625
|
+
var exitStatus = 0;
|
|
626
|
+
import_node_process.default.on("exit", onexit);
|
|
627
|
+
import_node_process.default.on("uncaughtException", fail);
|
|
628
|
+
function unifiedArgs(cliConfig) {
|
|
629
|
+
let config;
|
|
630
|
+
let watcher;
|
|
631
|
+
let output;
|
|
632
|
+
try {
|
|
633
|
+
config = options(import_node_process.default.argv.slice(2), cliConfig);
|
|
634
|
+
} catch (error) {
|
|
635
|
+
const exception = error;
|
|
636
|
+
return fail(exception, true);
|
|
637
|
+
}
|
|
638
|
+
if (config.help) {
|
|
639
|
+
import_node_process.default.stdout.write(
|
|
640
|
+
[
|
|
641
|
+
"Usage: " + cliConfig.name + " [options] [path | glob ...]",
|
|
642
|
+
"",
|
|
643
|
+
" " + cliConfig.description,
|
|
644
|
+
"",
|
|
645
|
+
"Options:",
|
|
646
|
+
"",
|
|
647
|
+
config.helpMessage,
|
|
648
|
+
""
|
|
649
|
+
].join("\n"),
|
|
650
|
+
noop
|
|
651
|
+
);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (config.version) {
|
|
655
|
+
import_node_process.default.stdout.write(cliConfig.version + "\n", noop);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
if (config.watch) {
|
|
659
|
+
output = config.output;
|
|
660
|
+
config.streamIn = ttyStream;
|
|
661
|
+
config.out = false;
|
|
662
|
+
import_node_process.default.stderr.write(
|
|
663
|
+
import_chalk.default.bold("Watching...") + " (press CTRL+C to exit)\n",
|
|
664
|
+
noop
|
|
665
|
+
);
|
|
666
|
+
if (output === true) {
|
|
667
|
+
config.output = false;
|
|
668
|
+
import_node_process.default.stderr.write(
|
|
669
|
+
import_chalk.default.yellow("Note") + ": Ignoring `--output` until exit.\n",
|
|
670
|
+
noop
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (config.lints) {
|
|
675
|
+
for (const [lintName, lintArgs] of Object.entries(config.lints)) {
|
|
676
|
+
const lint = availableLints[lintName];
|
|
677
|
+
if (!lint) {
|
|
678
|
+
throw new Error(
|
|
679
|
+
`Could not find lint named "${lintName}"; available lints are ${Object.keys(
|
|
680
|
+
availableLints
|
|
681
|
+
).join(", ")}`
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
config.plugins.push([lint, lintArgs]);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (config.stats) {
|
|
688
|
+
config.plugins.push([statsPlugin]);
|
|
689
|
+
}
|
|
690
|
+
if (config.macro.length > 0) {
|
|
691
|
+
config.plugins.push([attachMacroArgsPlugin, { macros: config.macro }]);
|
|
692
|
+
}
|
|
693
|
+
if (config.expandMacro.length > 0) {
|
|
694
|
+
config.plugins.push([
|
|
695
|
+
expandMacrosPlugin,
|
|
696
|
+
{ macros: config.expandMacro }
|
|
697
|
+
]);
|
|
698
|
+
}
|
|
699
|
+
if (config.statsJson) {
|
|
700
|
+
config.plugins.push([statsJsonPlugin]);
|
|
701
|
+
}
|
|
702
|
+
if (config.html) {
|
|
703
|
+
config.plugins.push([import_unified_latex_to_hast.unifiedLatexToHast]);
|
|
704
|
+
config.plugins.push([prettyPrintHtmlPlugin]);
|
|
705
|
+
}
|
|
706
|
+
const done = function done2(error, code, context) {
|
|
707
|
+
if (error) {
|
|
708
|
+
clean();
|
|
709
|
+
fail(error);
|
|
710
|
+
} else {
|
|
711
|
+
exitStatus = code || 0;
|
|
712
|
+
if (config.watch && !watcher && context) {
|
|
713
|
+
subscribe(context);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
function clean() {
|
|
718
|
+
if (watcher) {
|
|
719
|
+
watcher.close();
|
|
720
|
+
watcher = void 0;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function subscribe(context) {
|
|
724
|
+
var _a;
|
|
725
|
+
watcher = import_chokidar.default.watch(((_a = context.fileSet) == null ? void 0 : _a.origins) || [], {
|
|
726
|
+
cwd: config.cwd,
|
|
727
|
+
ignoreInitial: true
|
|
728
|
+
}).on("error", done).on("change", (filePath) => {
|
|
729
|
+
config.files = [filePath];
|
|
730
|
+
(0, import_unified_engine.engine)(config, done);
|
|
731
|
+
});
|
|
732
|
+
import_node_process.default.on("SIGINT", onsigint);
|
|
733
|
+
function onsigint() {
|
|
734
|
+
import_node_process.default.stderr.write("\n", noop);
|
|
735
|
+
clean();
|
|
736
|
+
if (output === true) {
|
|
737
|
+
config.output = output;
|
|
738
|
+
config.watch = false;
|
|
739
|
+
(0, import_unified_engine.engine)(config, done);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
(0, import_unified_engine.engine)(config, done);
|
|
744
|
+
}
|
|
745
|
+
function fail(error, pretty) {
|
|
746
|
+
const message = String((pretty ? error : error.stack) || error);
|
|
747
|
+
exitStatus = 1;
|
|
748
|
+
import_node_process.default.stderr.write(message.trim() + "\n", noop);
|
|
749
|
+
}
|
|
750
|
+
function onexit() {
|
|
751
|
+
import_node_process.default.exit(exitStatus);
|
|
752
|
+
}
|
|
753
|
+
function noop() {
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// index.ts
|
|
757
|
+
unifiedArgs({
|
|
758
|
+
processor: processLatexViaUnified,
|
|
759
|
+
name: "unified-latex",
|
|
760
|
+
description: "LaTeX processor powered by unified-latex",
|
|
761
|
+
version: "1.0.8",
|
|
762
|
+
extensions: ["tex"],
|
|
763
|
+
ignoreName: ".unifiedlatexignore",
|
|
764
|
+
packageField: "unifiedLatexConfig",
|
|
765
|
+
rcName: ".unifiedlatexrc",
|
|
766
|
+
pluginPrefix: "@unified-latex/"
|
|
767
|
+
});
|
|
768
|
+
//# sourceMappingURL=index.cjs.map
|