@uniweb/semantic-parser 1.1.11 → 1.1.13

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/README.md CHANGED
@@ -229,6 +229,29 @@ Bracketed spans (`[text]{.class}`) are converted to `<span>` elements with their
229
229
 
230
230
  Spans can have classes, IDs, and custom attributes. They combine with other marks—a span with bold becomes `<strong><span class="...">text</span></strong>`.
231
231
 
232
+ ### Inline Insets and Cross-references
233
+
234
+ The parser handles inline `inset_placeholder` nodes — generated by
235
+ `@uniweb/build`'s content collector when it pulls
236
+ `![alt](@Component){k=v}`, `[text](@Component){k=v}`, `[@key]{k=v}`,
237
+ or `[#id]{k=v}` references out of paragraph content. Two artifacts
238
+ ship to consumers:
239
+
240
+ 1. **`children` carries an `inset` entry per placeholder** — each
241
+ carrying the `refId` and `embedKind` (`'text'` for textual sugars
242
+ like `[@key]` / `[#id]` / `[text](@Component)`; `'visual'` for
243
+ `![alt](@Component)`). Renderers that walk `paragraph.children`
244
+ pick these up alongside icons, math, and links.
245
+
246
+ 2. **`text` carries a `<uniweb-inset data-ref-id="…"></uniweb-inset>`
247
+ marker** at the placeholder position — useful for renderers that
248
+ read `paragraph.text` as a flat HTML string (kit's `<Prose>` is the
249
+ canonical example; it splits on the marker and intersperses
250
+ React-rendered insets via the framework's child-block renderer).
251
+
252
+ The two views stay in lockstep — both record every inline inset the
253
+ parser sees, in source order.
254
+
232
255
  ## Use Cases
233
256
 
234
257
  - **Component-based websites**: Extract structured data for React/Vue components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/semantic-parser",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "Semantic parser for ProseMirror/TipTap content structures",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -404,6 +404,17 @@ function getTextContent(content, options = {}) {
404
404
  // dangerouslySetInnerHTML. The HTML5 parser handles <math>
405
405
  // as MathML natively — zero runtime math library needed.
406
406
  return prev + (curr.attrs?.mathml || "");
407
+ } else if (type === "inset_placeholder") {
408
+ // Inline inset (e.g. a `[@key]{...}` cite). Emit a marker
409
+ // tag the renderer can split on; the actual inset is
410
+ // rendered via React from `block.getInset(refId)`. The
411
+ // paragraph's `children` array also carries an ordered
412
+ // record of inset entries (see processInlineElements) so
413
+ // consumers that don't want to substring-walk the HTML
414
+ // have an alternative path.
415
+ const refId = curr.attrs?.refId;
416
+ if (!refId) return prev;
417
+ return prev + `<uniweb-inset data-ref-id="${refId}"></uniweb-inset>`;
407
418
  } else if (type === "hardBreak") {
408
419
  return prev + "<br>";
409
420
  } else {
@@ -425,8 +436,18 @@ function processInlineElements(content) {
425
436
  type: "icon",
426
437
  attrs: parseUniwebIcon(item.attrs),
427
438
  });
428
- } else if (item.type === "math-inline") {
439
+ } else if (item.type === "math-inline" || item.type === "math_inline") {
429
440
  items.push(item);
441
+ } else if (item.type === "inset_placeholder") {
442
+ // Inline inset (e.g., a `[@key]{...}` cite or a mid-prose
443
+ // visual inset). The Render path looks the actual block up
444
+ // via block.getInset(refId); we just carry the marker here so
445
+ // its position in the text flow is preserved.
446
+ items.push({
447
+ type: "inset",
448
+ refId: item.attrs?.refId,
449
+ embedKind: item.attrs?.embedKind || "visual",
450
+ });
430
451
  } else if (item.type === "text" && item.marks) {
431
452
  // Extract links from text nodes with link marks
432
453
  const linkMark = item.marks.find((m) => m.type === "link");
@@ -618,16 +639,24 @@ function parseVideoBlock(itemAttrs) {
618
639
  function stripTags(htmlString) {
619
640
  if (!htmlString || typeof htmlString !== "string") return "";
620
641
 
621
- // Remove HTML tags using regular expression
642
+ // Remove HTML tags using regular expression.
622
643
  const plainString = htmlString.replace(/<[^>]*>/g, "");
623
644
 
624
- // Decode HTML entities
625
- const decodedString = new DOMParser().parseFromString(
626
- plainString,
627
- "text/html"
628
- ).body.textContent;
629
-
630
- return decodedString;
645
+ // Decode the HTML entity subset citestyle / content-reader / kit emit.
646
+ // The previous DOMParser-based path covered every entity in the spec,
647
+ // but DOMParser is browser-only and crashes Node SSR (which the
648
+ // unipress compile pipeline runs in). The regex below covers the
649
+ // entities that actually appear in this codebase's emitted HTML.
650
+ return plainString
651
+ .replace(/&amp;/g, "&")
652
+ .replace(/&lt;/g, "<")
653
+ .replace(/&gt;/g, ">")
654
+ .replace(/&quot;/g, '"')
655
+ .replace(/&#39;/g, "'")
656
+ .replace(/&apos;/g, "'")
657
+ .replace(/&nbsp;/g, " ")
658
+ .replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
659
+ .replace(/&#x([0-9a-fA-F]+);/g, (_, n) => String.fromCharCode(parseInt(n, 16)));
631
660
  }
632
661
 
633
662
  function isLink(item) {