@uniweb/semantic-parser 1.1.12 → 1.1.14
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 +23 -0
- package/package.json +1 -1
- package/src/processors/sequence.js +19 -8
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
|
+
`{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
|
+
``). 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
|
@@ -572,6 +572,8 @@ function parseImgBlock(itemAttrs) {
|
|
|
572
572
|
theme,
|
|
573
573
|
role,
|
|
574
574
|
credit = "",
|
|
575
|
+
id, // {#fig-id} cross-reference label — preserved so Press
|
|
576
|
+
// adapters can emit \label{id} (LaTeX) / <id> (Typst).
|
|
575
577
|
} = itemAttrs;
|
|
576
578
|
|
|
577
579
|
let { contentType, viewType, contentId, identifier } = imgInfo || {};
|
|
@@ -605,6 +607,7 @@ function parseImgBlock(itemAttrs) {
|
|
|
605
607
|
theme,
|
|
606
608
|
role,
|
|
607
609
|
credit,
|
|
610
|
+
id: id || undefined,
|
|
608
611
|
};
|
|
609
612
|
}
|
|
610
613
|
|
|
@@ -639,16 +642,24 @@ function parseVideoBlock(itemAttrs) {
|
|
|
639
642
|
function stripTags(htmlString) {
|
|
640
643
|
if (!htmlString || typeof htmlString !== "string") return "";
|
|
641
644
|
|
|
642
|
-
// Remove HTML tags using regular expression
|
|
645
|
+
// Remove HTML tags using regular expression.
|
|
643
646
|
const plainString = htmlString.replace(/<[^>]*>/g, "");
|
|
644
647
|
|
|
645
|
-
// Decode HTML
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
648
|
+
// Decode the HTML entity subset citestyle / content-reader / kit emit.
|
|
649
|
+
// The previous DOMParser-based path covered every entity in the spec,
|
|
650
|
+
// but DOMParser is browser-only and crashes Node SSR (which the
|
|
651
|
+
// unipress compile pipeline runs in). The regex below covers the
|
|
652
|
+
// entities that actually appear in this codebase's emitted HTML.
|
|
653
|
+
return plainString
|
|
654
|
+
.replace(/&/g, "&")
|
|
655
|
+
.replace(/</g, "<")
|
|
656
|
+
.replace(/>/g, ">")
|
|
657
|
+
.replace(/"/g, '"')
|
|
658
|
+
.replace(/'/g, "'")
|
|
659
|
+
.replace(/'/g, "'")
|
|
660
|
+
.replace(/ /g, " ")
|
|
661
|
+
.replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
|
|
662
|
+
.replace(/&#x([0-9a-fA-F]+);/g, (_, n) => String.fromCharCode(parseInt(n, 16)));
|
|
652
663
|
}
|
|
653
664
|
|
|
654
665
|
function isLink(item) {
|