@uniweb/semantic-parser 1.3.1 → 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/package.json +2 -4
- package/src/processors/sequence.js +17 -54
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",
|
|
@@ -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 {
|