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