@haklex/rich-litexml 0.0.100 → 0.0.101
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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +127 -5
- package/dist/readers/custom.d.ts.map +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/writers/custom.d.ts.map +1 -1
- package/dist/xml-utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { registerCustomReaders } from './readers/custom';
|
|
|
5
5
|
export { LitexmlRegistry } from './registry';
|
|
6
6
|
export type { XmlSerializerOptions } from './serializer';
|
|
7
7
|
export { serializeNodesToXml, serializeToXml } from './serializer';
|
|
8
|
-
export type { ReaderContext, WriterContext, XmlContent, XmlElement, XmlReaderFn, XmlWriterFn, } from './types';
|
|
8
|
+
export type { ReaderContext, WriterContext, XmlCdata, XmlContent, XmlElement, XmlReaderFn, XmlWriterFn, } from './types';
|
|
9
9
|
export { registerBuiltinWriters } from './writers/builtin';
|
|
10
10
|
export { registerCustomWriters } from './writers/custom';
|
|
11
11
|
export type { XmlRenderOptions } from './xml-utils';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EACV,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EACV,aAAa,EACb,aAAa,EACb,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -162,6 +162,17 @@ function numAttr(el, name) {
|
|
|
162
162
|
const v = el.getAttribute(name);
|
|
163
163
|
return v !== null ? Number(v) : void 0;
|
|
164
164
|
}
|
|
165
|
+
function extractCdataText(el) {
|
|
166
|
+
for (const child of el.childNodes) {
|
|
167
|
+
if (child.nodeType === 8) {
|
|
168
|
+
const val = child.nodeValue ?? "";
|
|
169
|
+
if (val.startsWith("[CDATA[") && val.endsWith("]]")) {
|
|
170
|
+
return val.slice(7, -2);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return el.textContent?.trim() ?? "";
|
|
175
|
+
}
|
|
165
176
|
function registerCustomReaders(registry) {
|
|
166
177
|
registry.registerReader("img", (el) => {
|
|
167
178
|
if (el.parentElement?.tagName.toLowerCase() === "gallery") return false;
|
|
@@ -424,6 +435,51 @@ function registerCustomReaders(registry) {
|
|
|
424
435
|
version: 1
|
|
425
436
|
};
|
|
426
437
|
});
|
|
438
|
+
registry.registerReader(
|
|
439
|
+
"excalidraw",
|
|
440
|
+
(el) => ({
|
|
441
|
+
type: "excalidraw",
|
|
442
|
+
...extractBlockId(el),
|
|
443
|
+
snapshot: extractCdataText(el) || el.getAttribute("snapshot") || "",
|
|
444
|
+
version: 1
|
|
445
|
+
})
|
|
446
|
+
);
|
|
447
|
+
registry.registerReader("grid", (el, ctx) => {
|
|
448
|
+
const cells = [];
|
|
449
|
+
for (const child of el.children) {
|
|
450
|
+
if (child.tagName.toLowerCase() === "cell") {
|
|
451
|
+
const children = ctx.parseChildren(child);
|
|
452
|
+
cells.push({
|
|
453
|
+
root: {
|
|
454
|
+
type: "root",
|
|
455
|
+
children,
|
|
456
|
+
direction: "ltr",
|
|
457
|
+
format: "",
|
|
458
|
+
indent: 0,
|
|
459
|
+
version: 1
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
type: "grid-container",
|
|
466
|
+
...extractBlockId(el),
|
|
467
|
+
cols: numAttr(el, "cols") ?? 2,
|
|
468
|
+
gap: el.getAttribute("gap") ?? "16px",
|
|
469
|
+
cells,
|
|
470
|
+
version: 1
|
|
471
|
+
};
|
|
472
|
+
});
|
|
473
|
+
registry.registerReader(
|
|
474
|
+
"agentdiff",
|
|
475
|
+
(el) => ({
|
|
476
|
+
type: "agent-diff",
|
|
477
|
+
...extractBlockId(el),
|
|
478
|
+
opType: el.getAttribute("op") ?? "insert",
|
|
479
|
+
diffEntryId: el.getAttribute("entry") ?? "",
|
|
480
|
+
version: 1
|
|
481
|
+
})
|
|
482
|
+
);
|
|
427
483
|
registry.registerReader("codesnippet", (el) => {
|
|
428
484
|
const files = [];
|
|
429
485
|
for (const child of el.children) {
|
|
@@ -673,6 +729,45 @@ function registerCustomWriters(registry) {
|
|
|
673
729
|
children: ctx.serializeNestedState(n.content ?? n.contentState)
|
|
674
730
|
};
|
|
675
731
|
});
|
|
732
|
+
registry.registerWriter("excalidraw", (node) => {
|
|
733
|
+
const n = node;
|
|
734
|
+
if (!n.snapshot) {
|
|
735
|
+
return {
|
|
736
|
+
tag: "excalidraw",
|
|
737
|
+
attrs: optAttr(blockId(n)),
|
|
738
|
+
selfClosing: true
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
return {
|
|
742
|
+
tag: "excalidraw",
|
|
743
|
+
attrs: optAttr(blockId(n)),
|
|
744
|
+
children: [{ cdata: n.snapshot }]
|
|
745
|
+
};
|
|
746
|
+
});
|
|
747
|
+
registry.registerWriter("grid-container", (node, ctx) => {
|
|
748
|
+
const n = node;
|
|
749
|
+
const cells = (n.cells ?? []).map((cellState) => ({
|
|
750
|
+
tag: "cell",
|
|
751
|
+
children: ctx.serializeNestedState(cellState)
|
|
752
|
+
}));
|
|
753
|
+
return {
|
|
754
|
+
tag: "grid",
|
|
755
|
+
attrs: optAttr({
|
|
756
|
+
...blockId(n),
|
|
757
|
+
cols: n.cols != null ? String(n.cols) : void 0,
|
|
758
|
+
gap: n.gap
|
|
759
|
+
}),
|
|
760
|
+
children: cells
|
|
761
|
+
};
|
|
762
|
+
});
|
|
763
|
+
registry.registerWriter("agent-diff", (node) => {
|
|
764
|
+
const n = node;
|
|
765
|
+
return {
|
|
766
|
+
tag: "agentdiff",
|
|
767
|
+
attrs: optAttr({ ...blockId(n), op: n.opType, entry: n.diffEntryId }),
|
|
768
|
+
selfClosing: true
|
|
769
|
+
};
|
|
770
|
+
});
|
|
676
771
|
registry.registerWriter("details", (node, ctx) => {
|
|
677
772
|
const n = node;
|
|
678
773
|
return {
|
|
@@ -842,7 +937,10 @@ const BLOCK_TAGS = /* @__PURE__ */ new Set([
|
|
|
842
937
|
"nesteddoc",
|
|
843
938
|
"gallery",
|
|
844
939
|
"codesnippet",
|
|
845
|
-
"footnotesection"
|
|
940
|
+
"footnotesection",
|
|
941
|
+
"grid",
|
|
942
|
+
"cell",
|
|
943
|
+
"excalidraw"
|
|
846
944
|
]);
|
|
847
945
|
function isBlockContainer(element) {
|
|
848
946
|
return BLOCK_TAGS.has(element.tagName.toLowerCase());
|
|
@@ -949,11 +1047,19 @@ function buildAttrs(attrs) {
|
|
|
949
1047
|
const parts = Object.entries(attrs).filter(([, v]) => v !== void 0 && v !== "").map(([k, v]) => ` ${k}="${escapeXml(v)}"`);
|
|
950
1048
|
return parts.join("");
|
|
951
1049
|
}
|
|
1050
|
+
function isCdata(item) {
|
|
1051
|
+
return typeof item === "object" && "cdata" in item;
|
|
1052
|
+
}
|
|
1053
|
+
function renderCdata(item) {
|
|
1054
|
+
return `<![CDATA[${item.cdata}]]>`;
|
|
1055
|
+
}
|
|
952
1056
|
function renderXml(content, indent = 0, options = {}) {
|
|
953
1057
|
const lines = [];
|
|
954
1058
|
for (const item of content) {
|
|
955
1059
|
if (typeof item === "string") {
|
|
956
1060
|
lines.push(escapeXml(item));
|
|
1061
|
+
} else if (isCdata(item)) {
|
|
1062
|
+
lines.push(renderCdata(item));
|
|
957
1063
|
} else {
|
|
958
1064
|
lines.push(renderElement(item, indent, options));
|
|
959
1065
|
}
|
|
@@ -971,18 +1077,30 @@ function renderElement(el, indent, options) {
|
|
|
971
1077
|
return compact ? `<${el.tag}${attrs} />` : `${pad(indent)}<${el.tag}${attrs} />
|
|
972
1078
|
`;
|
|
973
1079
|
}
|
|
974
|
-
const allInline = el.children.every(
|
|
1080
|
+
const allInline = el.children.every(
|
|
1081
|
+
(c) => typeof c === "string" || isCdata(c) || isInlineElement(c)
|
|
1082
|
+
);
|
|
975
1083
|
if (allInline) {
|
|
976
|
-
const inner2 = el.children.map((c) =>
|
|
1084
|
+
const inner2 = el.children.map((c) => {
|
|
1085
|
+
if (typeof c === "string") return escapeXml(c);
|
|
1086
|
+
if (isCdata(c)) return renderCdata(c);
|
|
1087
|
+
return renderInline(c);
|
|
1088
|
+
}).join("");
|
|
977
1089
|
return compact ? `<${el.tag}${attrs}>${inner2}</${el.tag}>` : `${pad(indent)}<${el.tag}${attrs}>${inner2}</${el.tag}>
|
|
978
1090
|
`;
|
|
979
1091
|
}
|
|
980
1092
|
if (compact) {
|
|
981
|
-
const inner2 = el.children.map((c) =>
|
|
1093
|
+
const inner2 = el.children.map((c) => {
|
|
1094
|
+
if (typeof c === "string") return escapeXml(c);
|
|
1095
|
+
if (isCdata(c)) return renderCdata(c);
|
|
1096
|
+
return renderElement(c, indent + 1, options);
|
|
1097
|
+
}).join("");
|
|
982
1098
|
return `<${el.tag}${attrs}>${inner2}</${el.tag}>`;
|
|
983
1099
|
}
|
|
984
1100
|
const inner = el.children.map((c) => {
|
|
985
1101
|
if (typeof c === "string") return `${pad(indent + 1)}${escapeXml(c)}
|
|
1102
|
+
`;
|
|
1103
|
+
if (isCdata(c)) return `${pad(indent + 1)}${renderCdata(c)}
|
|
986
1104
|
`;
|
|
987
1105
|
return renderElement(c, indent + 1, options);
|
|
988
1106
|
}).join("");
|
|
@@ -995,7 +1113,11 @@ function renderInline(el) {
|
|
|
995
1113
|
if (el.selfClosing || !el.children || el.children.length === 0) {
|
|
996
1114
|
return `<${el.tag}${attrs} />`;
|
|
997
1115
|
}
|
|
998
|
-
const inner = el.children.map((c) =>
|
|
1116
|
+
const inner = el.children.map((c) => {
|
|
1117
|
+
if (typeof c === "string") return escapeXml(c);
|
|
1118
|
+
if (isCdata(c)) return renderCdata(c);
|
|
1119
|
+
return renderInline(c);
|
|
1120
|
+
}).join("");
|
|
999
1121
|
return `<${el.tag}${attrs}>${inner}</${el.tag}>`;
|
|
1000
1122
|
}
|
|
1001
1123
|
function isInlineElement(el) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/readers/custom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/readers/custom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA6BnD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CA2XrE"}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,8 +6,12 @@ export interface XmlElement {
|
|
|
6
6
|
selfClosing?: boolean;
|
|
7
7
|
tag: string;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
9
|
+
/** CDATA wrapper — rendered as <![CDATA[...]]> without escaping */
|
|
10
|
+
export interface XmlCdata {
|
|
11
|
+
cdata: string;
|
|
12
|
+
}
|
|
13
|
+
/** XML content: either a structured element, raw text (will be escaped), or CDATA */
|
|
14
|
+
export type XmlContent = XmlElement | XmlCdata | string;
|
|
11
15
|
/** Context provided to writer functions */
|
|
12
16
|
export interface WriterContext {
|
|
13
17
|
/** Serialize an array of child nodes into XML content */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE5E,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,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,MAAM,MAAM,WAAW,GAAG,CACxB,IAAI,EAAE,qBAAqB,EAC3B,GAAG,EAAE,aAAa,KACf,UAAU,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,aAAa,KACf,qBAAqB,GAAG,qBAAqB,EAAE,GAAG,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/writers/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAenD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/writers/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAenD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAsQrE"}
|
package/dist/xml-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-utils.d.ts","sourceRoot":"","sources":["../src/xml-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"xml-utils.d.ts","sourceRoot":"","sources":["../src/xml-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,UAAU,EAAc,MAAM,SAAS,CAAC;AAEhE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAUD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAKhE;AAUD,4CAA4C;AAC5C,wBAAgB,SAAS,CACvB,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,GAAE,MAAU,EAClB,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CAYR"}
|