@haklex/rich-litexml 0.11.0 → 0.13.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/dist/index.mjs +1139 -1
- package/dist/readers/builtin.d.ts.map +1 -1
- package/dist/writers/builtin.d.ts.map +1 -1
- package/package.json +1 -4
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.mjs +0 -73
- package/dist/deserializer-CfdlNh2e.js +0 -1125
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin.d.ts","sourceRoot":"","sources":["../../src/readers/builtin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAgBnD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"builtin.d.ts","sourceRoot":"","sources":["../../src/readers/builtin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAgBnD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAiLtE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin.d.ts","sourceRoot":"","sources":["../../src/writers/builtin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"builtin.d.ts","sourceRoot":"","sources":["../../src/writers/builtin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAOnD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAwHtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-litexml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Bidirectional Lexical SerializedNode <-> XML conversion with plugin registry",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.mjs",
|
|
19
|
-
"bin": {
|
|
20
|
-
"litexml-to-lexical": "./dist/cli.mjs"
|
|
21
|
-
},
|
|
22
19
|
"files": [
|
|
23
20
|
"dist"
|
|
24
21
|
],
|
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { i as createDefaultRegistry, t as deserializeFromXml } from "./deserializer-CfdlNh2e.js";
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
//#region src/cli.ts
|
|
6
|
-
var HELP = `Usage:
|
|
7
|
-
litexml-to-lexical <file.xml>
|
|
8
|
-
litexml-to-lexical '<p>Hello</p>'
|
|
9
|
-
litexml-to-lexical - < input.xml
|
|
10
|
-
|
|
11
|
-
Options:
|
|
12
|
-
-o, --output <file> Write JSON to a file instead of stdout.
|
|
13
|
-
--compact Emit compact JSON instead of pretty JSON.
|
|
14
|
-
-h, --help Show this help message.
|
|
15
|
-
`;
|
|
16
|
-
function parseArgs(args) {
|
|
17
|
-
const options = { compact: false };
|
|
18
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
19
|
-
const arg = args[i];
|
|
20
|
-
switch (arg) {
|
|
21
|
-
case "--compact":
|
|
22
|
-
options.compact = true;
|
|
23
|
-
break;
|
|
24
|
-
case "-o":
|
|
25
|
-
case "--output": {
|
|
26
|
-
const output = args[i + 1];
|
|
27
|
-
if (!output) throw new Error(`Missing value for ${arg}.`);
|
|
28
|
-
options.output = output;
|
|
29
|
-
i += 1;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
case "-h":
|
|
33
|
-
case "--help":
|
|
34
|
-
process.stdout.write(HELP);
|
|
35
|
-
process.exit(0);
|
|
36
|
-
break;
|
|
37
|
-
default:
|
|
38
|
-
if (arg.startsWith("-") && arg !== "-") throw new Error(`Unknown option: ${arg}.`);
|
|
39
|
-
if (options.input) throw new Error("Expected a single LightXML input argument.");
|
|
40
|
-
options.input = arg;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return options;
|
|
44
|
-
}
|
|
45
|
-
function hasElementTag(value) {
|
|
46
|
-
return /<[!/]?[a-z][\w:-]*(?:\s|>|\/>)/i.test(value);
|
|
47
|
-
}
|
|
48
|
-
function readInput(input) {
|
|
49
|
-
if (!input || input === "-") return readFileSync(0, "utf8");
|
|
50
|
-
if (existsSync(input)) return readFileSync(input, "utf8");
|
|
51
|
-
return input;
|
|
52
|
-
}
|
|
53
|
-
function convertLiteXmlToLexicalJson(xml, compact) {
|
|
54
|
-
const trimmed = xml.trim();
|
|
55
|
-
if (!trimmed) throw new Error("LightXML input is empty.");
|
|
56
|
-
if (!hasElementTag(trimmed)) throw new Error("Input does not look like LightXML. Pass a file path, stdin, or an XML string.");
|
|
57
|
-
const editorState = deserializeFromXml(trimmed, createDefaultRegistry());
|
|
58
|
-
return JSON.stringify(editorState, null, compact ? 0 : 2);
|
|
59
|
-
}
|
|
60
|
-
function main() {
|
|
61
|
-
try {
|
|
62
|
-
const options = parseArgs(process.argv.slice(2));
|
|
63
|
-
const output = convertLiteXmlToLexicalJson(readInput(options.input), options.compact) + "\n";
|
|
64
|
-
if (options.output) writeFileSync(options.output, output);
|
|
65
|
-
else process.stdout.write(output);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
68
|
-
process.stderr.write(`${path.basename(process.argv[1])}: ${message}\n\n${HELP}`);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
main();
|
|
73
|
-
//#endregion
|