@haklex/rich-litexml-cli 0.15.4 → 0.15.5

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +59 -1
  2. 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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-litexml-cli",
3
- "version": "0.15.4",
3
+ "version": "0.15.5",
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.4",
22
- "@haklex/rich-litexml": "0.15.4",
23
- "@haklex/rich-headless": "0.15.4"
21
+ "@haklex/rich-litexml": "0.15.5",
22
+ "@haklex/rich-compose": "0.15.5",
23
+ "@haklex/rich-headless": "0.15.5"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "25.6.0",