@uniweb/semantic-parser 1.0.1 → 1.0.3
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @uniweb/semantic-parser
|
|
2
2
|
|
|
3
3
|
A semantic parser for ProseMirror/TipTap content structures that helps bridge the gap between natural content writing and component-based web development.
|
|
4
4
|
|
|
@@ -13,13 +13,13 @@ The parser transforms rich text editor content (ProseMirror/TipTap) into structu
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm install @
|
|
16
|
+
npm install @uniweb/semantic-parser
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
import { parseContent } from "@
|
|
22
|
+
import { parseContent } from "@uniweb/semantic-parser";
|
|
23
23
|
|
|
24
24
|
// Your ProseMirror/TipTap document
|
|
25
25
|
const doc = {
|
|
@@ -231,7 +231,7 @@ const data = mappers.extractBySchema(parsed, schema, { mode: 'build' });
|
|
|
231
231
|
### Using Pre-Built Extractors
|
|
232
232
|
|
|
233
233
|
```js
|
|
234
|
-
import { parseContent, mappers } from "@
|
|
234
|
+
import { parseContent, mappers } from "@uniweb/semantic-parser";
|
|
235
235
|
|
|
236
236
|
const parsed = parseContent(doc);
|
|
237
237
|
|
|
@@ -298,7 +298,7 @@ After extracting content, render it using a Text component that handles paragrap
|
|
|
298
298
|
### Text Component Pattern
|
|
299
299
|
|
|
300
300
|
```jsx
|
|
301
|
-
import { parseContent, mappers } from '@
|
|
301
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
302
302
|
import { H1, P } from './components/Text';
|
|
303
303
|
|
|
304
304
|
const parsed = parseContent(doc);
|
|
@@ -324,7 +324,7 @@ See **[Text Component Reference](./docs/text-component-reference.md)** for imple
|
|
|
324
324
|
Sanitize content at the engine level (during data preparation), not in components:
|
|
325
325
|
|
|
326
326
|
```javascript
|
|
327
|
-
import { parseContent, mappers } from '@
|
|
327
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
328
328
|
|
|
329
329
|
function prepareData(parsed) {
|
|
330
330
|
const hero = mappers.extractors.hero(parsed);
|
package/docs/api.md
CHANGED
|
@@ -7,7 +7,7 @@ Parses a ProseMirror/TipTap document into three semantic views.
|
|
|
7
7
|
### Import
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
import { parseContent } from '@
|
|
10
|
+
import { parseContent } from '@uniweb/semantic-parser';
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### Parameters
|
|
@@ -243,7 +243,7 @@ byType.getElementsByHeadingContext((heading) => heading.level === 2)
|
|
|
243
243
|
### Basic Usage
|
|
244
244
|
|
|
245
245
|
```js
|
|
246
|
-
import { parseContent } from "@
|
|
246
|
+
import { parseContent } from "@uniweb/semantic-parser";
|
|
247
247
|
|
|
248
248
|
const doc = {
|
|
249
249
|
type: "doc",
|
package/docs/mapping-patterns.md
CHANGED
|
@@ -263,7 +263,7 @@ const componentData = mappers.extractBySchema(parsed, componentSchema);
|
|
|
263
263
|
## Quick Start
|
|
264
264
|
|
|
265
265
|
```js
|
|
266
|
-
import { parseContent, mappers } from "@
|
|
266
|
+
import { parseContent, mappers } from "@uniweb/semantic-parser";
|
|
267
267
|
|
|
268
268
|
const parsed = parseContent(doc);
|
|
269
269
|
|
|
@@ -712,7 +712,7 @@ A Text component handles all these cases automatically.
|
|
|
712
712
|
#### Quick Example
|
|
713
713
|
|
|
714
714
|
```jsx
|
|
715
|
-
import { parseContent, mappers } from '@
|
|
715
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
716
716
|
import { H1, P } from './components/Text'; // See docs/text-component-reference.md
|
|
717
717
|
|
|
718
718
|
const parsed = parseContent(doc);
|
|
@@ -736,7 +736,7 @@ Extractors now return paragraph arrays to preserve structure:
|
|
|
736
736
|
// Renders: <p>First para</p><p>Second para</p>
|
|
737
737
|
|
|
738
738
|
// If you need a single string, use joinParagraphs
|
|
739
|
-
import { joinParagraphs } from '@
|
|
739
|
+
import { joinParagraphs } from '@uniweb/semantic-parser/mappers/helpers';
|
|
740
740
|
|
|
741
741
|
<P text={joinParagraphs(hero.description, '\n\n')} />
|
|
742
742
|
// Renders: <p>First para\n\nSecond para</p>
|
|
@@ -755,7 +755,7 @@ import { joinParagraphs } from '@uniwebcms/semantic-parser/mappers/helpers';
|
|
|
755
755
|
#### Complete Integration Example
|
|
756
756
|
|
|
757
757
|
```jsx
|
|
758
|
-
import { parseContent, mappers } from '@
|
|
758
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
759
759
|
import { H1, H2, H3, P } from './components/Text';
|
|
760
760
|
|
|
761
761
|
function HeroSection({ document }) {
|
|
@@ -808,7 +808,7 @@ function FeaturesList({ document }) {
|
|
|
808
808
|
|
|
809
809
|
```javascript
|
|
810
810
|
// ✅ Good - sanitize during data preparation
|
|
811
|
-
import { sanitizeHtml } from '@
|
|
811
|
+
import { sanitizeHtml } from '@uniweb/semantic-parser/mappers/types';
|
|
812
812
|
|
|
813
813
|
function prepareHeroData(parsed) {
|
|
814
814
|
const hero = mappers.extractors.hero(parsed);
|
|
@@ -850,7 +850,7 @@ import {
|
|
|
850
850
|
joinParagraphs,
|
|
851
851
|
excerptFromParagraphs,
|
|
852
852
|
countWords
|
|
853
|
-
} from '@
|
|
853
|
+
} from '@uniweb/semantic-parser/mappers/helpers';
|
|
854
854
|
|
|
855
855
|
// Join paragraphs for single-string display
|
|
856
856
|
const singlePara = joinParagraphs(hero.description, ' ');
|
|
@@ -21,7 +21,7 @@ cp reference/Text.js src/components/Text.js
|
|
|
21
21
|
**4. Use in your components:**
|
|
22
22
|
```jsx
|
|
23
23
|
import Text, { H1, P } from './components/Text';
|
|
24
|
-
import { parseContent, mappers } from '@
|
|
24
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
25
25
|
|
|
26
26
|
const parsed = parseContent(doc);
|
|
27
27
|
const hero = mappers.extractors.hero(parsed);
|
|
@@ -164,8 +164,8 @@ export const Div = (props) => <Text {...props} as="div" />;
|
|
|
164
164
|
### Basic Examples
|
|
165
165
|
|
|
166
166
|
```jsx
|
|
167
|
-
import { parseContent } from '@
|
|
168
|
-
import { extractors } from '@
|
|
167
|
+
import { parseContent } from '@uniweb/semantic-parser';
|
|
168
|
+
import { extractors } from '@uniweb/semantic-parser/mappers';
|
|
169
169
|
import { H1, P, Text } from './components/Text';
|
|
170
170
|
|
|
171
171
|
// Parse content
|
|
@@ -192,7 +192,7 @@ The parser's extractors now return paragraph arrays by default:
|
|
|
192
192
|
// Renders: <p>Para 1</p><p>Para 2</p>
|
|
193
193
|
|
|
194
194
|
// If you need a single string, use joinParagraphs helper
|
|
195
|
-
import { joinParagraphs } from '@
|
|
195
|
+
import { joinParagraphs } from '@uniweb/semantic-parser/mappers/helpers';
|
|
196
196
|
|
|
197
197
|
<P text={joinParagraphs(hero.description)} />
|
|
198
198
|
// Renders: <p>Para 1 Para 2</p>
|
|
@@ -224,7 +224,7 @@ const title = "Welcome to <mark class='brand'>Our Platform</mark>";
|
|
|
224
224
|
|
|
225
225
|
```javascript
|
|
226
226
|
// In your engine, when sanitizing
|
|
227
|
-
import { sanitizeHtml } from '@
|
|
227
|
+
import { sanitizeHtml } from '@uniweb/semantic-parser/mappers/types';
|
|
228
228
|
|
|
229
229
|
const safeTitleContent = sanitizeHtml(titleContent, {
|
|
230
230
|
allowedTags: ['strong', 'em', 'mark', 'span'],
|
|
@@ -249,7 +249,7 @@ The component automatically filters empty content:
|
|
|
249
249
|
### With Extractors
|
|
250
250
|
|
|
251
251
|
```jsx
|
|
252
|
-
import { parseContent, mappers } from '@
|
|
252
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
253
253
|
const { extractors, helpers } = mappers;
|
|
254
254
|
|
|
255
255
|
const parsed = parseContent(doc);
|
|
@@ -271,7 +271,7 @@ function Card({ data }) {
|
|
|
271
271
|
### With Custom Schemas
|
|
272
272
|
|
|
273
273
|
```jsx
|
|
274
|
-
import { getByPath, extractBySchema } from '@
|
|
274
|
+
import { getByPath, extractBySchema } from '@uniweb/semantic-parser/mappers/accessor';
|
|
275
275
|
|
|
276
276
|
const schema = {
|
|
277
277
|
title: { path: 'groups.main.header.title' },
|
|
@@ -333,7 +333,7 @@ mark.brand {
|
|
|
333
333
|
The parser exports sanitization utilities for use in your engine:
|
|
334
334
|
|
|
335
335
|
```javascript
|
|
336
|
-
import { sanitizeHtml, stripMarkup } from '@
|
|
336
|
+
import { sanitizeHtml, stripMarkup } from '@uniweb/semantic-parser/mappers/types';
|
|
337
337
|
|
|
338
338
|
// Sanitize HTML content
|
|
339
339
|
const safe = sanitizeHtml(content, {
|
package/package.json
CHANGED
package/reference/README.md
CHANGED
|
@@ -34,7 +34,7 @@ This component assumes content is **already sanitized by your engine**. It does
|
|
|
34
34
|
4. **Use in your components:**
|
|
35
35
|
```jsx
|
|
36
36
|
import Text, { H1, P } from './components/Text';
|
|
37
|
-
import { parseContent, mappers } from '@
|
|
37
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
38
38
|
|
|
39
39
|
function MyComponent({ document }) {
|
|
40
40
|
const parsed = parseContent(document);
|
|
@@ -95,8 +95,8 @@ export const Div: React.FC<Omit<TextProps, 'as'>>;
|
|
|
95
95
|
Use the parser's built-in utilities in your engine:
|
|
96
96
|
|
|
97
97
|
```javascript
|
|
98
|
-
import { sanitizeHtml } from '@
|
|
99
|
-
import { parseContent, mappers } from '@
|
|
98
|
+
import { sanitizeHtml } from '@uniweb/semantic-parser/mappers/types';
|
|
99
|
+
import { parseContent, mappers } from '@uniweb/semantic-parser';
|
|
100
100
|
|
|
101
101
|
// In your engine (NOT in the component)
|
|
102
102
|
function prepareHeroData(document) {
|
|
@@ -323,7 +323,7 @@ function gallery(parsed, options = {}) {
|
|
|
323
323
|
* @returns {Object} Legacy format { main, items }
|
|
324
324
|
*
|
|
325
325
|
* @example
|
|
326
|
-
* const { parseContent, mappers } = require('@
|
|
326
|
+
* const { parseContent, mappers } = require('@uniweb/semantic-parser');
|
|
327
327
|
* const parsed = parseContent(doc, { pretitleLevel: 2, parseCodeAsJson: true });
|
|
328
328
|
* const legacy = mappers.extractors.legacy(parsed);
|
|
329
329
|
* // Returns: { main: {...}, items: [...] }
|
|
@@ -101,6 +101,12 @@ function createSequenceElement(node, options = {}) {
|
|
|
101
101
|
type: "image",
|
|
102
102
|
attrs: parseImgBlock(attrs),
|
|
103
103
|
};
|
|
104
|
+
case "image":
|
|
105
|
+
// Standard ProseMirror image node - spread attrs at top level
|
|
106
|
+
return {
|
|
107
|
+
type: "image",
|
|
108
|
+
...attrs,
|
|
109
|
+
};
|
|
104
110
|
case "Video":
|
|
105
111
|
return {
|
|
106
112
|
type: "video",
|