@uniweb/semantic-parser 1.0.13 → 1.0.15
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 +20 -0
- package/package.json +1 -1
- package/src/processors/sequence.js +24 -4
package/README.md
CHANGED
|
@@ -322,10 +322,30 @@ Inline formatting is preserved as HTML tags:
|
|
|
322
322
|
// Input: Text with bold mark
|
|
323
323
|
// Output: "Text with <strong>bold</strong>"
|
|
324
324
|
|
|
325
|
+
// Input: Text with italic mark
|
|
326
|
+
// Output: "Text with <em>emphasis</em>"
|
|
327
|
+
|
|
325
328
|
// Input: Link mark
|
|
326
329
|
// Output: "Click <a href=\"/docs\">here</a>"
|
|
330
|
+
|
|
331
|
+
// Input: Span mark (bracketed spans)
|
|
332
|
+
// Output: "This is <span class=\"highlight\">highlighted</span> text"
|
|
327
333
|
```
|
|
328
334
|
|
|
335
|
+
### Span Marks
|
|
336
|
+
|
|
337
|
+
Bracketed spans (`[text]{.class}`) are converted to `<span>` elements with their attributes:
|
|
338
|
+
|
|
339
|
+
```js
|
|
340
|
+
// Input mark
|
|
341
|
+
{ type: "span", attrs: { class: "highlight", id: "note-1" } }
|
|
342
|
+
|
|
343
|
+
// Output HTML
|
|
344
|
+
'<span class="highlight" id="note-1">text</span>'
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Spans can have classes, IDs, and custom attributes. They combine with other marks—a span with bold becomes `<strong><span class="...">text</span></strong>`.
|
|
348
|
+
|
|
329
349
|
## Documentation
|
|
330
350
|
|
|
331
351
|
- **[Content Writing Guide](./docs/guide.md)**: Learn how to structure content for optimal parsing
|
package/package.json
CHANGED
|
@@ -282,6 +282,26 @@ function getTextContent(content, options = {}) {
|
|
|
282
282
|
styledText = `<span style="background-color: var(--highlight)">${styledText}</span>`;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
// span (bracketed spans with class/id/attributes)
|
|
286
|
+
if (marks.some((mark) => mark.type === "span")) {
|
|
287
|
+
const spanMark = marks.find((mark) => mark.type === "span");
|
|
288
|
+
const attrs = spanMark?.attrs || {};
|
|
289
|
+
const attrParts = [];
|
|
290
|
+
|
|
291
|
+
if (attrs.class) attrParts.push(`class="${attrs.class}"`);
|
|
292
|
+
if (attrs.id) attrParts.push(`id="${attrs.id}"`);
|
|
293
|
+
|
|
294
|
+
// Add any other custom attributes (data-*, etc.)
|
|
295
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
296
|
+
if (key !== 'class' && key !== 'id') {
|
|
297
|
+
attrParts.push(`${key}="${value}"`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const attrString = attrParts.length > 0 ? ` ${attrParts.join(' ')}` : '';
|
|
302
|
+
styledText = `<span${attrString}>${styledText}</span>`;
|
|
303
|
+
}
|
|
304
|
+
|
|
285
305
|
// bold
|
|
286
306
|
if (marks.some((mark) => mark.type === "bold")) {
|
|
287
307
|
styledText = `<strong>${styledText}</strong>`;
|
|
@@ -358,7 +378,7 @@ function processInlineElements(content) {
|
|
|
358
378
|
items.push({
|
|
359
379
|
type: "link",
|
|
360
380
|
attrs: {
|
|
361
|
-
|
|
381
|
+
...linkMark.attrs, // Preserve all link attributes (role, target, etc.)
|
|
362
382
|
label: item.text || "",
|
|
363
383
|
},
|
|
364
384
|
});
|
|
@@ -600,7 +620,7 @@ function isLink(item) {
|
|
|
600
620
|
}
|
|
601
621
|
|
|
602
622
|
return {
|
|
603
|
-
|
|
623
|
+
...mark?.attrs, // Preserve all link attributes (role, target, etc.)
|
|
604
624
|
label: contentItem?.text || "",
|
|
605
625
|
iconBefore,
|
|
606
626
|
iconAfter,
|
|
@@ -653,14 +673,14 @@ function isOnlyLinks(item) {
|
|
|
653
673
|
|
|
654
674
|
if (!allLinks) return false;
|
|
655
675
|
|
|
656
|
-
// Extract links
|
|
676
|
+
// Extract links with all their attributes
|
|
657
677
|
// Icons in this paragraph go to body.icons separately (no association)
|
|
658
678
|
return textContent.map((c) => {
|
|
659
679
|
const linkMark = c.marks.find((m) => m.type === "link");
|
|
660
680
|
return {
|
|
661
681
|
type: "link",
|
|
662
682
|
attrs: {
|
|
663
|
-
|
|
683
|
+
...linkMark?.attrs, // Preserve all link attributes (role, target, etc.)
|
|
664
684
|
label: c.text || "",
|
|
665
685
|
},
|
|
666
686
|
};
|