@uniweb/semantic-parser 1.1.10 → 1.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/semantic-parser",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "Semantic parser for ProseMirror/TipTap content structures",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -5,7 +5,7 @@
5
5
  */
6
6
  function flattenGroup(group) {
7
7
  if (!group) return null;
8
- return {
8
+ const flat = {
9
9
  title: group.header.title || '',
10
10
  pretitle: group.header.pretitle || '',
11
11
  subtitle: group.header.subtitle || '',
@@ -21,6 +21,11 @@ function flattenGroup(group) {
21
21
  quotes: group.body.quotes || [],
22
22
  headings: group.body.headings || [],
23
23
  };
24
+ // Only attach rare collections when present so we don't pay the cost
25
+ // on every page (math is <1% of content in practice; authors who need
26
+ // ordering should use content.sequence anyway).
27
+ if (group.body.math && group.body.math.length) flat.math = group.body.math;
28
+ return flat;
24
29
  }
25
30
 
26
31
  /**
@@ -240,6 +245,9 @@ function processGroupContent(elements) {
240
245
  data: {},
241
246
  quotes: [],
242
247
  headings: [],
248
+ // `math` is lazily added in the math_display case when encountered —
249
+ // avoids allocating an empty array on every group (math is rare; most
250
+ // consumers that care about ordering should use content.sequence).
243
251
  };
244
252
 
245
253
  const metadata = {
@@ -370,6 +378,23 @@ function processGroupContent(elements) {
370
378
  });
371
379
  break;
372
380
 
381
+ case "math_display":
382
+ // Block-level math from $$...$$ on its own line or ```math
383
+ // fence. The mathml string is pre-compiled at parse time;
384
+ // foundations render it by setting dangerouslySetInnerHTML
385
+ // on the mathml field. The optional id enables numbered
386
+ // cross-references (see @uniweb/scholar/math).
387
+ // For ordered rendering alongside paragraphs, prefer
388
+ // `content.sequence` — this flat collection is convenience
389
+ // sugar when order doesn't matter. Allocate lazily so
390
+ // pages without math pay nothing.
391
+ (body.math ||= []).push({
392
+ id: element.id || null,
393
+ latex: element.latex || '',
394
+ mathml: element.mathml || '',
395
+ });
396
+ break;
397
+
373
398
  case "inset":
374
399
  body.insets.push({ refId: element.refId });
375
400
  break;
@@ -167,16 +167,33 @@ function createSequenceElement(node, options = {}) {
167
167
  type: "inset",
168
168
  refId: attrs.refId,
169
169
  };
170
+
171
+ case "math_display":
172
+ // Block-level math. The mathml string is pre-compiled at parse
173
+ // time (content-reader) and renders natively via kit's HTML
174
+ // renderers. Foundations can read el.mathml from content.sequence.
175
+ // The optional id enables numbered cross-references via
176
+ // @uniweb/scholar/math's <EquationRef>.
177
+ return {
178
+ type: "math_display",
179
+ id: node.attrs?.id || null,
180
+ latex: node.attrs?.latex || "",
181
+ mathml: node.attrs?.mathml || "",
182
+ attrs,
183
+ };
170
184
  case "ImageBlock":
171
185
  return {
172
186
  type: "image",
173
187
  attrs: parseImgBlock(attrs),
174
188
  };
175
189
  case "image":
176
- // Standard ProseMirror image node - wrap attrs like ImageBlock
190
+ // Standard ProseMirror image node - resolve attrs the same way as
191
+ // ImageBlock so info.identifier lands as a CDN URL. CLI-deployed
192
+ // content uses this node type; without parseImgBlock the url
193
+ // wouldn't be populated and components render an empty slot.
177
194
  return {
178
195
  type: "image",
179
- attrs: attrs || {},
196
+ attrs: parseImgBlock(attrs || {}),
180
197
  };
181
198
  case "Video":
182
199
  return {
@@ -381,6 +398,12 @@ function getTextContent(content, options = {}) {
381
398
  }
382
399
 
383
400
  return prev + styledText;
401
+ } else if (type === "math_inline") {
402
+ // Pre-compiled MathML string rides straight into the
403
+ // paragraph's HTML and reaches kit's Text via
404
+ // dangerouslySetInnerHTML. The HTML5 parser handles <math>
405
+ // as MathML natively — zero runtime math library needed.
406
+ return prev + (curr.attrs?.mathml || "");
384
407
  } else if (type === "hardBreak") {
385
408
  return prev + "<br>";
386
409
  } else {