@uniweb/semantic-parser 1.3.0 → 1.4.0
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 +2 -2
- package/package.json +2 -4
- package/src/processors/groups.js +14 -9
- package/src/processors/sequence.js +17 -54
package/README.md
CHANGED
|
@@ -162,7 +162,7 @@ When a group begins with headings, the parser reads one **headline stack** with
|
|
|
162
162
|
2. **One step smaller** — the next line of the headline: the subtitle first, then further subtitle lines (`subtitle` is a string for one line, an array for several — a three-line header like name / role / affiliation fits in one headline).
|
|
163
163
|
3. **Two or more steps smaller, or a step back up** — the stack ends; the rest of the run starts a new group (an item), read the same way.
|
|
164
164
|
|
|
165
|
-
Before the title, `#>` label lines (headings carrying `role: "pretitle"`) and smaller
|
|
165
|
+
Before the title, `#>` label lines (headings carrying `role: "pretitle"`) and every smaller heading stacked above the most important one — in whatever order — join the `pretitle`. A label line anywhere names the block it sits in; a label with no following heading labels an untitled block.
|
|
166
166
|
|
|
167
167
|
### Main content vs items
|
|
168
168
|
|
|
@@ -180,7 +180,7 @@ This is the mechanism that creates repeating content groups (cards, features, FA
|
|
|
180
180
|
Two spellings fill the `pretitle` slot:
|
|
181
181
|
|
|
182
182
|
- **A `#>` label line** — a heading with `role: "pretitle"`. It names the block that starts next, at any depth, with no level arithmetic; the hash count is carried for round-tripping and means nothing.
|
|
183
|
-
- **Position** — headings
|
|
183
|
+
- **Position** — smaller headings stacked above the most important heading of a run (H3 before H1, H6 before H5, …), in any order. `#### / ### / # Title` and `## / ### / # Title` both yield a two-line pretitle.
|
|
184
184
|
|
|
185
185
|
### Banner image
|
|
186
186
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/semantic-parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Semantic parser for ProseMirror/TipTap content structures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -30,9 +30,7 @@
|
|
|
30
30
|
"directories": {
|
|
31
31
|
"test": "tests"
|
|
32
32
|
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"yaml": "^2.8.2"
|
|
35
|
-
},
|
|
33
|
+
"dependencies": {},
|
|
36
34
|
"scripts": {
|
|
37
35
|
"test": "vitest run",
|
|
38
36
|
"test-report": "vitest run --reporter=json --outputFile=test-results.json",
|
package/src/processors/groups.js
CHANGED
|
@@ -232,15 +232,20 @@ function readStack(sequence, startIdx, options = {}) {
|
|
|
232
232
|
i++;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
235
|
+
// Positional pretitle: the title is the FIRST occurrence of the run's most
|
|
236
|
+
// important level; every smaller heading stacked above it joins the
|
|
237
|
+
// pretitle, in whatever order they were written (#### / ### / # and
|
|
238
|
+
// ## / ### / # both give a two-line pretitle). An ascending-only walk
|
|
239
|
+
// read a descending stack as a bodiless headline followed by a bigger
|
|
240
|
+
// heading, which demoted the real title into the items.
|
|
241
|
+
let best = i;
|
|
242
|
+
for (let k = i; k < sequence.length; k++) {
|
|
243
|
+
const el = sequence[k];
|
|
244
|
+
if (el.type !== "heading") break;
|
|
245
|
+
if (isLabel(el)) continue;
|
|
246
|
+
if (el.level < sequence[best].level || isLabel(sequence[best])) best = k;
|
|
247
|
+
}
|
|
248
|
+
while (i < best) {
|
|
244
249
|
pre.push(sequence[i]);
|
|
245
250
|
i++;
|
|
246
251
|
}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import { parse as parseYaml } from "yaml";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get code block data - prefers pre-parsed attrs.data, falls back to parsing text
|
|
5
|
-
*
|
|
6
|
-
* Content can come from two sources:
|
|
7
|
-
* 1. Pre-parsed at build time: attrs.data contains parsed JS object
|
|
8
|
-
* 2. Legacy/runtime: text needs to be parsed based on language
|
|
9
|
-
*
|
|
10
|
-
* @param {string} text - Raw code block text
|
|
11
|
-
* @param {Object} attrs - Code block attributes (language, tag, data)
|
|
12
|
-
* @returns {*} Parsed data or raw text
|
|
13
|
-
*/
|
|
14
1
|
/**
|
|
15
2
|
* HTML-attribute encoding for values placed inside double-quoted
|
|
16
3
|
* attributes. Backslashes and braces (common in LaTeX) pass through
|
|
@@ -28,42 +15,6 @@ function escapeAttr(s) {
|
|
|
28
15
|
.replace(/>/g, ">");
|
|
29
16
|
}
|
|
30
17
|
|
|
31
|
-
function getCodeBlockData(text, attrs) {
|
|
32
|
-
const { language, tag, data } = attrs || {};
|
|
33
|
-
|
|
34
|
-
// Only process tagged blocks
|
|
35
|
-
if (!tag) {
|
|
36
|
-
return text;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Prefer pre-parsed data from build time (attrs.data)
|
|
40
|
-
if (data !== undefined) {
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Fallback: parse text at runtime (for backwards compatibility)
|
|
45
|
-
const lang = (language || "").toLowerCase();
|
|
46
|
-
|
|
47
|
-
if (lang === "json") {
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(text);
|
|
50
|
-
} catch {
|
|
51
|
-
return text;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (lang === "yaml" || lang === "yml") {
|
|
56
|
-
try {
|
|
57
|
-
return parseYaml(text);
|
|
58
|
-
} catch {
|
|
59
|
-
return text;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Unknown language - return raw text
|
|
64
|
-
return text;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
18
|
/**
|
|
68
19
|
* Check if an inline node is an icon.
|
|
69
20
|
* TipTap editor uses type "UniwebIcon"; markdown pipeline uses type "image" with role "icon".
|
|
@@ -172,9 +123,10 @@ function createSequenceElement(node, options = {}) {
|
|
|
172
123
|
// to a text string and lose the author's prose.
|
|
173
124
|
//
|
|
174
125
|
// No markdown is parsed here and none may ever be: this package
|
|
175
|
-
//
|
|
176
|
-
// put content-reader inside the
|
|
177
|
-
// this node; the job here is only
|
|
126
|
+
// parses NOTHING and has no parser dependency at all, and reaching
|
|
127
|
+
// for a markdown parser would put content-reader inside the
|
|
128
|
+
// runtime. The reader already built this node; the job here is only
|
|
129
|
+
// to WALK it.
|
|
178
130
|
//
|
|
179
131
|
// `options` rides along so nested content is sequenced under the
|
|
180
132
|
// same options as its parent. (`inset_block` and `blockquote` used
|
|
@@ -198,12 +150,23 @@ function createSequenceElement(node, options = {}) {
|
|
|
198
150
|
|
|
199
151
|
case "codeBlock": {
|
|
200
152
|
const codeText = getTextContent(content, options);
|
|
201
|
-
// Tagged code blocks are semantically data blocks, not code
|
|
153
|
+
// Tagged code blocks are semantically data blocks, not code — the
|
|
154
|
+
// tag is what routes them to `data[tag]`, so the routing holds even
|
|
155
|
+
// though the payload here is raw text.
|
|
156
|
+
//
|
|
157
|
+
// ⛔ NOTHING IS PARSED HERE, and nothing may be. A tagged block the
|
|
158
|
+
// reader could parse arrives as a `dataBlock` carrying `attrs.data`
|
|
159
|
+
// (the case above); content-reader emits THIS shape only when
|
|
160
|
+
// `parseCodeBlockData` already returned null — i.e. the text is not
|
|
161
|
+
// valid JSON or YAML. Re-running a parser on it in the browser
|
|
162
|
+
// cannot succeed, and it used to cost every site the whole `yaml`
|
|
163
|
+
// package: 98 KB minified, ~29 KB gzip, pinned into the bundle by a
|
|
164
|
+
// static import that no bundler could shake. Removed 2026-09-01.
|
|
202
165
|
if (attrs?.tag) {
|
|
203
166
|
return {
|
|
204
167
|
type: "dataBlock",
|
|
205
168
|
tag: attrs.tag,
|
|
206
|
-
data:
|
|
169
|
+
data: codeText,
|
|
207
170
|
};
|
|
208
171
|
}
|
|
209
172
|
return {
|