@localess/richtext 4.0.0-dev.20260905085556 → 4.0.0-dev.20260906124410
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/SKILL.md +35 -0
- package/dist/html-parser/index.d.ts +29 -0
- package/dist/html-parser/index.js +491 -0
- package/dist/html-parser/index.mjs +489 -0
- package/dist/html-parser/to-model.d.ts +11 -0
- package/dist/html-parser/tokenizer.d.ts +32 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -44
- package/dist/index.mjs +2 -38
- package/dist/markdown-parser/block.d.ts +11 -0
- package/dist/markdown-parser/index.d.ts +32 -0
- package/dist/markdown-parser/index.js +442 -0
- package/dist/markdown-parser/index.mjs +440 -0
- package/dist/markdown-parser/inline.d.ts +13 -0
- package/dist/parse-common-C-dAtFji.mjs +100 -0
- package/dist/parse-common-DEYhfKnK.js +135 -0
- package/dist/parse-common.d.ts +71 -0
- package/package.json +15 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { LocalessRichTextDocument } from './model';
|
|
2
|
+
/**
|
|
3
|
+
* What to do with input that has no representation in the Localess rich text
|
|
4
|
+
* model — the model is closed and matches the Studio editor exactly, so a
|
|
5
|
+
* `<table>` or a blockquote has nowhere to go.
|
|
6
|
+
*
|
|
7
|
+
* - `unwrap` — keep the text content, drop the wrapper (default)
|
|
8
|
+
* - `skip` — drop the element and everything inside it
|
|
9
|
+
* - `throw` — throw {@link RichTextParseError} naming the element
|
|
10
|
+
*/
|
|
11
|
+
export type RichTextUnsupportedPolicy = 'unwrap' | 'skip' | 'throw';
|
|
12
|
+
/** Options accepted by both parsers. */
|
|
13
|
+
export interface RichTextParseOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Handling for elements the model cannot represent.
|
|
16
|
+
*
|
|
17
|
+
* @default 'unwrap'
|
|
18
|
+
*/
|
|
19
|
+
unsupported?: RichTextUnsupportedPolicy;
|
|
20
|
+
}
|
|
21
|
+
/** One unsupported element type, and what the parser did with it. */
|
|
22
|
+
export interface RichTextUnsupportedReport {
|
|
23
|
+
/** Element or construct name, e.g. `table`, `blockquote`, `img`. */
|
|
24
|
+
element: string;
|
|
25
|
+
action: 'unwrapped' | 'skipped';
|
|
26
|
+
/** How many times it occurred in this parse. */
|
|
27
|
+
count: number;
|
|
28
|
+
}
|
|
29
|
+
/** What both parsers return. */
|
|
30
|
+
export interface RichTextParseResult {
|
|
31
|
+
doc: LocalessRichTextDocument;
|
|
32
|
+
/**
|
|
33
|
+
* Every element that could not be represented, with its handling and count.
|
|
34
|
+
* Empty when the input was fully representable.
|
|
35
|
+
*
|
|
36
|
+
* Returned rather than only warned so a migration can surface "347 tables
|
|
37
|
+
* were unwrapped" and decide whether to proceed before committing a write.
|
|
38
|
+
*/
|
|
39
|
+
unsupported: RichTextUnsupportedReport[];
|
|
40
|
+
}
|
|
41
|
+
/** Thrown by both parsers when `unsupported: 'throw'` meets an unrepresentable element. */
|
|
42
|
+
export declare class RichTextParseError extends Error {
|
|
43
|
+
/** The element that could not be represented. */
|
|
44
|
+
readonly element: string;
|
|
45
|
+
constructor(element: string);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Records unsupported elements for the result report, warns once per element
|
|
49
|
+
* type per parse, and applies the configured policy.
|
|
50
|
+
*
|
|
51
|
+
* Mirrors the renderer's forward-compat behaviour, which warns once per unknown
|
|
52
|
+
* type per render and stays silent in production.
|
|
53
|
+
*/
|
|
54
|
+
export declare class UnsupportedTracker {
|
|
55
|
+
private readonly policy;
|
|
56
|
+
private readonly counts;
|
|
57
|
+
private readonly warned;
|
|
58
|
+
constructor(options?: RichTextParseOptions);
|
|
59
|
+
/**
|
|
60
|
+
* Records one occurrence and returns whether the caller should keep the
|
|
61
|
+
* element's children.
|
|
62
|
+
*
|
|
63
|
+
* @throws {RichTextParseError} When the policy is `throw`.
|
|
64
|
+
*/
|
|
65
|
+
record(element: string): 'unwrap' | 'skip';
|
|
66
|
+
/** The report, in first-seen order. */
|
|
67
|
+
report(): RichTextUnsupportedReport[];
|
|
68
|
+
private warn;
|
|
69
|
+
}
|
|
70
|
+
/** An empty document — what both parsers return for empty, `null`, or `undefined` input. */
|
|
71
|
+
export declare function emptyDocument(): LocalessRichTextDocument;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localess/richtext",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.20260906124410",
|
|
4
4
|
"description": "Framework-neutral rich text model and renderer for Localess's TipTap JSON content.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localess",
|
|
@@ -30,6 +30,16 @@
|
|
|
30
30
|
"types": "./dist/test-utils/index.d.ts",
|
|
31
31
|
"import": "./dist/test-utils/index.mjs",
|
|
32
32
|
"require": "./dist/test-utils/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./html-parser": {
|
|
35
|
+
"types": "./dist/html-parser/index.d.ts",
|
|
36
|
+
"import": "./dist/html-parser/index.mjs",
|
|
37
|
+
"require": "./dist/html-parser/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./markdown-parser": {
|
|
40
|
+
"types": "./dist/markdown-parser/index.d.ts",
|
|
41
|
+
"import": "./dist/markdown-parser/index.mjs",
|
|
42
|
+
"require": "./dist/markdown-parser/index.js"
|
|
33
43
|
}
|
|
34
44
|
},
|
|
35
45
|
"repository": {
|
|
@@ -48,7 +58,7 @@
|
|
|
48
58
|
},
|
|
49
59
|
"license": "MIT",
|
|
50
60
|
"dependencies": {
|
|
51
|
-
"@localess/model": "4.0.0-dev.
|
|
61
|
+
"@localess/model": "4.0.0-dev.20260906124410"
|
|
52
62
|
},
|
|
53
63
|
"devDependencies": {
|
|
54
64
|
"@tiptap/extension-bold": "^3.22.5",
|
|
@@ -67,7 +77,10 @@
|
|
|
67
77
|
"@tiptap/extension-text": "^3.22.5",
|
|
68
78
|
"@tiptap/extension-underline": "^3.22.5",
|
|
69
79
|
"@tiptap/html": "^3.22.5",
|
|
80
|
+
"@types/markdown-it": "^14.1.2",
|
|
70
81
|
"@types/node": "^24",
|
|
82
|
+
"happy-dom": "^20.9.0",
|
|
83
|
+
"markdown-it": "^14.1.0",
|
|
71
84
|
"typescript": "^5.9.3",
|
|
72
85
|
"vite": "^8.0.16",
|
|
73
86
|
"vite-plugin-dts": "^5.0.0"
|