@haklex/rich-litexml-cli 0.15.4 → 0.15.6
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/cli.mjs +83 -12
- package/package.json +4 -4
package/dist/cli.mjs
CHANGED
|
@@ -22283,8 +22283,66 @@ function getFormatBit(tagName) {
|
|
|
22283
22283
|
}
|
|
22284
22284
|
//#endregion
|
|
22285
22285
|
//#region ../rich-litexml/src/deserializer.ts
|
|
22286
|
+
/**
|
|
22287
|
+
* HTML5 void elements — tags the HTML parser already treats as self-closing
|
|
22288
|
+
* regardless of `/>` syntax. Custom or non-void tags written as `<tag … />`
|
|
22289
|
+
* are otherwise interpreted as opening tags by the HTML parser, which then
|
|
22290
|
+
* swallows all following siblings as children until a matching close tag (or
|
|
22291
|
+
* end of document) is found. We expand those into explicit `<tag …></tag>`
|
|
22292
|
+
* before handing the string to linkedom / DOMParser.
|
|
22293
|
+
*/
|
|
22294
|
+
var HTML_VOID_ELEMENTS = new Set([
|
|
22295
|
+
"area",
|
|
22296
|
+
"base",
|
|
22297
|
+
"br",
|
|
22298
|
+
"col",
|
|
22299
|
+
"embed",
|
|
22300
|
+
"hr",
|
|
22301
|
+
"img",
|
|
22302
|
+
"input",
|
|
22303
|
+
"link",
|
|
22304
|
+
"meta",
|
|
22305
|
+
"param",
|
|
22306
|
+
"source",
|
|
22307
|
+
"track",
|
|
22308
|
+
"wbr"
|
|
22309
|
+
]);
|
|
22310
|
+
var SELF_CLOSING_RE = /<([\w-]+)((?:\s+[\w-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'))?)*)\s*\/>/g;
|
|
22311
|
+
var CDATA_OPEN = "<![CDATA[";
|
|
22312
|
+
var CDATA_CLOSE = "]]>";
|
|
22313
|
+
function expandSelfClosing(chunk) {
|
|
22314
|
+
return chunk.replaceAll(SELF_CLOSING_RE, (match, tag, attrs) => {
|
|
22315
|
+
if (HTML_VOID_ELEMENTS.has(tag.toLowerCase())) return match;
|
|
22316
|
+
return `<${tag}${attrs}></${tag}>`;
|
|
22317
|
+
});
|
|
22318
|
+
}
|
|
22319
|
+
/**
|
|
22320
|
+
* Expand `<custom-tag … />` to `<custom-tag …></custom-tag>` outside CDATA.
|
|
22321
|
+
* Leaves HTML void elements and already-paired tags untouched. CDATA content
|
|
22322
|
+
* is sliced out verbatim with `indexOf` to avoid regex pitfalls around `]]>`.
|
|
22323
|
+
*/
|
|
22324
|
+
function normalizeSelfClosingTags(xml) {
|
|
22325
|
+
const out = [];
|
|
22326
|
+
let cursor = 0;
|
|
22327
|
+
while (cursor < xml.length) {
|
|
22328
|
+
const start = xml.indexOf(CDATA_OPEN, cursor);
|
|
22329
|
+
if (start < 0) {
|
|
22330
|
+
out.push(expandSelfClosing(xml.slice(cursor)));
|
|
22331
|
+
break;
|
|
22332
|
+
}
|
|
22333
|
+
out.push(expandSelfClosing(xml.slice(cursor, start)));
|
|
22334
|
+
const end = xml.indexOf(CDATA_CLOSE, start + 9);
|
|
22335
|
+
if (end < 0) {
|
|
22336
|
+
out.push(xml.slice(start));
|
|
22337
|
+
break;
|
|
22338
|
+
}
|
|
22339
|
+
out.push(xml.slice(start, end + 3));
|
|
22340
|
+
cursor = end + 3;
|
|
22341
|
+
}
|
|
22342
|
+
return out.join("");
|
|
22343
|
+
}
|
|
22286
22344
|
function parseXml(xml) {
|
|
22287
|
-
return parseHTML(`<!DOCTYPE html><html><body>${xml}</body></html>`);
|
|
22345
|
+
return parseHTML(`<!DOCTYPE html><html><body>${normalizeSelfClosingTags(xml)}</body></html>`);
|
|
22288
22346
|
}
|
|
22289
22347
|
function deserializeFromXml(xml, registry) {
|
|
22290
22348
|
const doc = parseXml(xml);
|
|
@@ -22328,16 +22386,24 @@ function createReaderContext(registry) {
|
|
|
22328
22386
|
parseChildren(element) {
|
|
22329
22387
|
const blockLevel = isBlockContainer(element);
|
|
22330
22388
|
const nodes = [];
|
|
22331
|
-
|
|
22332
|
-
|
|
22333
|
-
if (
|
|
22334
|
-
if (
|
|
22335
|
-
|
|
22336
|
-
|
|
22389
|
+
let pendingText = "";
|
|
22390
|
+
const flushText = () => {
|
|
22391
|
+
if (pendingText === "") return;
|
|
22392
|
+
if (blockLevel && pendingText.trim() === "") {
|
|
22393
|
+
pendingText = "";
|
|
22394
|
+
return;
|
|
22395
|
+
}
|
|
22396
|
+
nodes.push(makeTextNode(pendingText, 0));
|
|
22397
|
+
pendingText = "";
|
|
22398
|
+
};
|
|
22399
|
+
for (const child of element.childNodes) if (child.nodeType === 3) pendingText += child.textContent ?? "";
|
|
22400
|
+
else if (child.nodeType === 1) {
|
|
22401
|
+
flushText();
|
|
22337
22402
|
const parsed = parseElement(child, registry, ctx, 0);
|
|
22338
22403
|
if (parsed) if (Array.isArray(parsed)) nodes.push(...parsed);
|
|
22339
22404
|
else nodes.push(parsed);
|
|
22340
22405
|
}
|
|
22406
|
+
flushText();
|
|
22341
22407
|
return nodes;
|
|
22342
22408
|
},
|
|
22343
22409
|
parseNestedState(xml) {
|
|
@@ -22363,15 +22429,20 @@ function parseElement(element, registry, ctx, inheritedFormat) {
|
|
|
22363
22429
|
}
|
|
22364
22430
|
function parseInlineChildren(element, registry, ctx, format) {
|
|
22365
22431
|
const nodes = [];
|
|
22366
|
-
|
|
22367
|
-
|
|
22368
|
-
if (
|
|
22369
|
-
nodes.push(makeTextNode(
|
|
22370
|
-
|
|
22432
|
+
let pendingText = "";
|
|
22433
|
+
const flushText = () => {
|
|
22434
|
+
if (pendingText === "") return;
|
|
22435
|
+
nodes.push(makeTextNode(pendingText, format));
|
|
22436
|
+
pendingText = "";
|
|
22437
|
+
};
|
|
22438
|
+
for (const child of element.childNodes) if (child.nodeType === 3) pendingText += child.textContent ?? "";
|
|
22439
|
+
else if (child.nodeType === 1) {
|
|
22440
|
+
flushText();
|
|
22371
22441
|
const parsed = parseElement(child, registry, ctx, format);
|
|
22372
22442
|
if (parsed) if (Array.isArray(parsed)) nodes.push(...parsed);
|
|
22373
22443
|
else nodes.push(parsed);
|
|
22374
22444
|
}
|
|
22445
|
+
flushText();
|
|
22375
22446
|
return nodes;
|
|
22376
22447
|
}
|
|
22377
22448
|
function parseFallbackNode(element) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-litexml-cli",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.6",
|
|
4
4
|
"description": "Unified CLI for haklex LiteXML: convert LiteXML or Lexical JSON to HTML, JSON, or Markdown.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@lexical/headless": "^0.44.0",
|
|
20
20
|
"lexical": "^0.44.0",
|
|
21
|
-
"@haklex/rich-compose": "0.15.
|
|
22
|
-
"@haklex/rich-litexml": "0.15.
|
|
23
|
-
"@haklex/rich-headless": "0.15.
|
|
21
|
+
"@haklex/rich-compose": "0.15.6",
|
|
22
|
+
"@haklex/rich-litexml": "0.15.6",
|
|
23
|
+
"@haklex/rich-headless": "0.15.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "25.6.0",
|