@lexical/mdast 0.0.0-bootstrap.0 → 0.47.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 +207 -2
- package/dist/LexicalMdast.dev.js +2620 -0
- package/dist/LexicalMdast.dev.mjs +2594 -0
- package/dist/LexicalMdast.js +11 -0
- package/dist/LexicalMdast.js.flow +228 -0
- package/dist/LexicalMdast.mjs +36 -0
- package/dist/LexicalMdast.node.mjs +34 -0
- package/dist/LexicalMdast.prod.js +11 -0
- package/dist/LexicalMdast.prod.mjs +11 -0
- package/dist/MdastExport.d.ts +20 -0
- package/dist/MdastExportExtension.d.ts +80 -0
- package/dist/MdastExtension.d.ts +21 -0
- package/dist/MdastGfmExtension.d.ts +20 -0
- package/dist/MdastImport.d.ts +48 -0
- package/dist/MdastImportExtension.d.ts +264 -0
- package/dist/MdastShortcuts.d.ts +27 -0
- package/dist/MdastStream.d.ts +70 -0
- package/dist/MdastTableExtension.d.ts +29 -0
- package/dist/compile.d.ts +18 -0
- package/dist/handlers.d.ts +84 -0
- package/dist/index.d.ts +15 -0
- package/dist/state.d.ts +58 -0
- package/dist/types.d.ts +165 -0
- package/dist/typescript-too-old.d.ts +18 -0
- package/package.json +90 -6
- package/src/MdastExport.ts +545 -0
- package/src/MdastExportExtension.ts +122 -0
- package/src/MdastExtension.ts +30 -0
- package/src/MdastGfmExtension.ts +38 -0
- package/src/MdastImport.ts +236 -0
- package/src/MdastImportExtension.ts +635 -0
- package/src/MdastShortcuts.ts +453 -0
- package/src/MdastStream.ts +187 -0
- package/src/MdastTableExtension.ts +144 -0
- package/src/compile.ts +44 -0
- package/src/handlers.ts +648 -0
- package/src/index.ts +69 -0
- package/src/state.ts +124 -0
- package/src/types.ts +197 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { ElementNode, LexicalNode } from 'lexical';
|
|
9
|
+
import type { BlockContent, Nodes as MdastNode, Parent as MdastParent, PhrasingContent } from 'mdast';
|
|
10
|
+
import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown';
|
|
11
|
+
import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown';
|
|
12
|
+
import type { Extension as MicromarkExtension } from 'micromark-util-types';
|
|
13
|
+
export type { FromMarkdownExtension, MdastNode, MdastParent, MicromarkExtension, ToMarkdownExtension, };
|
|
14
|
+
declare module 'mdast' {
|
|
15
|
+
interface BreakData {
|
|
16
|
+
/** The hard-break marker: `'\\'`, trailing spaces, or `''` for soft. */
|
|
17
|
+
mdastBreak?: string;
|
|
18
|
+
}
|
|
19
|
+
interface CodeData {
|
|
20
|
+
/** The literal fence the code block used (e.g. ``` or ~~~). */
|
|
21
|
+
mdastFence?: string;
|
|
22
|
+
}
|
|
23
|
+
interface HeadingData {
|
|
24
|
+
/** Present (true) when the heading was written in setext style. */
|
|
25
|
+
mdastSetext?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface LinkData {
|
|
28
|
+
/** The syntax the link was written in. */
|
|
29
|
+
mdastLinkStyle?: 'autolink' | 'inline' | 'literal';
|
|
30
|
+
}
|
|
31
|
+
interface ListData {
|
|
32
|
+
/** The bullet character an unordered list used (`-`, `*`, `+`). */
|
|
33
|
+
mdastBullet?: '*' | '+' | '-';
|
|
34
|
+
/** The delimiter an ordered list used (`.` or `)`). */
|
|
35
|
+
mdastBulletOrdered?: ')' | '.';
|
|
36
|
+
}
|
|
37
|
+
interface ThematicBreakData {
|
|
38
|
+
/** The marker character the thematic break used (`-`, `*`, `_`). */
|
|
39
|
+
mdastRule?: string;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The context passed to {@link MdastImportHandler}s while an mdast tree is
|
|
44
|
+
* being walked and converted into Lexical nodes.
|
|
45
|
+
* @experimental
|
|
46
|
+
*/
|
|
47
|
+
export interface MdastImportContext {
|
|
48
|
+
/**
|
|
49
|
+
* The accumulated text-format bitmask for the current inline position
|
|
50
|
+
* (e.g. inside `strong` > `emphasis` this carries the bold + italic bits).
|
|
51
|
+
* Block handlers can ignore this; inline handlers should pass it along to
|
|
52
|
+
* {@link createText} and the recursion helpers.
|
|
53
|
+
*/
|
|
54
|
+
readonly format: number;
|
|
55
|
+
/**
|
|
56
|
+
* The original Markdown source being imported, or `''` when importing a
|
|
57
|
+
* pre-parsed mdast tree. Handlers slice this by `node.position` to recover
|
|
58
|
+
* the literal syntax (list marker, code fence, hard-break style) for
|
|
59
|
+
* round-trip preservation.
|
|
60
|
+
*/
|
|
61
|
+
readonly source: string;
|
|
62
|
+
/**
|
|
63
|
+
* Convert every child of `parent` into Lexical nodes, optionally layering an
|
|
64
|
+
* additional text-format bitmask on top of the current {@link format}.
|
|
65
|
+
*/
|
|
66
|
+
importChildren(parent: MdastParent, format?: number): LexicalNode[];
|
|
67
|
+
/**
|
|
68
|
+
* Convert a single mdast node (and its descendants) into Lexical nodes.
|
|
69
|
+
*/
|
|
70
|
+
importNode(node: MdastNode, format?: number): LexicalNode[];
|
|
71
|
+
/**
|
|
72
|
+
* Create text nodes for `value` with the current (or supplied) format
|
|
73
|
+
* bitmask; `\n` becomes a `LineBreakNode` and `\t` a `TabNode`.
|
|
74
|
+
*/
|
|
75
|
+
createText(value: string, format?: number): LexicalNode[];
|
|
76
|
+
/**
|
|
77
|
+
* Resolves a link/image reference `identifier` (already normalized by
|
|
78
|
+
* mdast) against the document's definitions (`[id]: url "title"`).
|
|
79
|
+
*/
|
|
80
|
+
getDefinition(identifier: string): {
|
|
81
|
+
url: string;
|
|
82
|
+
title?: string | null;
|
|
83
|
+
} | undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Converts an mdast node of a particular `type` into one or more Lexical
|
|
87
|
+
* nodes. Returning `null` defers to the next registered handler.
|
|
88
|
+
* @experimental
|
|
89
|
+
*/
|
|
90
|
+
export type MdastImportHandler<T extends MdastNode = MdastNode> = (node: T, context: MdastImportContext) => LexicalNode | LexicalNode[] | null;
|
|
91
|
+
/**
|
|
92
|
+
* The context passed to {@link MdastExportHandler}s while a Lexical tree is
|
|
93
|
+
* converted back into an mdast tree.
|
|
94
|
+
* @experimental
|
|
95
|
+
*/
|
|
96
|
+
export interface MdastExportContext {
|
|
97
|
+
/**
|
|
98
|
+
* Convert the children of `node` into mdast nodes by dispatching each child
|
|
99
|
+
* through the registered export handlers.
|
|
100
|
+
*/
|
|
101
|
+
exportChildren(node: ElementNode): MdastNode[];
|
|
102
|
+
/**
|
|
103
|
+
* Convert the inline children of `node` into mdast phrasing content,
|
|
104
|
+
* grouping bare line breaks as mdast `break` nodes.
|
|
105
|
+
*/
|
|
106
|
+
exportInline(node: ElementNode): PhrasingContent[];
|
|
107
|
+
/**
|
|
108
|
+
* Convert the inline children of `node` into one or more mdast block nodes
|
|
109
|
+
* (paragraphs), splitting on hard line breaks. Used by containers such as
|
|
110
|
+
* block quotes and list items whose Lexical children are inline but whose
|
|
111
|
+
* mdast children must be block-level.
|
|
112
|
+
*/
|
|
113
|
+
exportBlocks(node: ElementNode): BlockContent[];
|
|
114
|
+
/**
|
|
115
|
+
* Whether `node` belongs in the current export: always `true` for a
|
|
116
|
+
* whole-document export; during a selection export, `true` when the node
|
|
117
|
+
* or any descendant is selected. The `exportChildren`/`exportInline`/
|
|
118
|
+
* `exportBlocks` walks apply this automatically — handlers only need it
|
|
119
|
+
* when they iterate children manually (e.g. list items, table rows) to
|
|
120
|
+
* skip structural children the selection does not reach.
|
|
121
|
+
*/
|
|
122
|
+
isIncluded(node: LexicalNode): boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Converts a Lexical node into one or more mdast nodes. Returning `null`
|
|
126
|
+
* defers to the next registered handler.
|
|
127
|
+
* @experimental
|
|
128
|
+
*/
|
|
129
|
+
export type MdastExportHandler<T extends LexicalNode = LexicalNode> = (node: T, context: MdastExportContext) => MdastNode | MdastNode[] | null;
|
|
130
|
+
/**
|
|
131
|
+
* A single import mapping: which mdast node `type` it handles and how. The
|
|
132
|
+
* unit an extension contributes (alongside the micromark/mdast extensions that
|
|
133
|
+
* tokenize the construct) to {@link MdastImportExtension}'s `importRules` config.
|
|
134
|
+
* @experimental
|
|
135
|
+
*/
|
|
136
|
+
export interface MdastImportRule {
|
|
137
|
+
/** The mdast node `type` this rule handles (e.g. `'heading'`). */
|
|
138
|
+
type: string;
|
|
139
|
+
$import: MdastImportHandler<any>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A single export mapping: which Lexical node `getType()` it handles and how.
|
|
143
|
+
* @experimental
|
|
144
|
+
*/
|
|
145
|
+
export interface MdastExportRule {
|
|
146
|
+
/** The Lexical node `getType()` this rule handles (e.g. `'heading'`). */
|
|
147
|
+
type: string;
|
|
148
|
+
$export: MdastExportHandler<any>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The compiled registry produced from {@link MdastConfig} at editor build
|
|
152
|
+
* time and consumed by the importer, exporter, and shortcut scanner.
|
|
153
|
+
* @experimental
|
|
154
|
+
*/
|
|
155
|
+
export interface CompiledMdast {
|
|
156
|
+
importHandlers: Map<string, MdastImportHandler>;
|
|
157
|
+
exportHandlers: Map<string, MdastExportHandler>;
|
|
158
|
+
micromarkExtensions: MicromarkExtension[];
|
|
159
|
+
mdastExtensions: FromMarkdownExtension[];
|
|
160
|
+
toMarkdownExtensions: ToMarkdownExtension[];
|
|
161
|
+
/** mdast inline `type`s eligible for streaming shortcut materialization. */
|
|
162
|
+
inlineShortcutTypes: Set<string>;
|
|
163
|
+
/** Characters that can close an inline construct and trigger a re-scan. */
|
|
164
|
+
inlineShortcutTriggers: Set<string>;
|
|
165
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// You are seeing this declaration file because your TypeScript cannot read
|
|
10
|
+
// Lexical's types through the package.json "exports" field.
|
|
11
|
+
//
|
|
12
|
+
// Lexical requires TypeScript >= 5.2 with "moduleResolution" set to
|
|
13
|
+
// "bundler", "node16", or "nodenext". To fix this:
|
|
14
|
+
// 1. Upgrade TypeScript to >= 5.2.
|
|
15
|
+
// 2. In tsconfig.json set "moduleResolution" to "bundler" (recommended for
|
|
16
|
+
// apps/bundlers) or "node16" / "nodenext", and a matching "module".
|
|
17
|
+
import 'Lexical requires TypeScript >=5.2 with moduleResolution bundler, node16, or nodenext';
|
|
18
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,11 +1,95 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "Placeholder published to claim the npm name during trusted publishing setup. Do not install.",
|
|
3
|
-
"homepage": "https://lexical.dev",
|
|
4
|
-
"license": "MIT",
|
|
5
2
|
"name": "@lexical/mdast",
|
|
3
|
+
"description": "Experimental micromark/mdast-based Markdown support for Lexical, configured through extensions.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"lexical",
|
|
6
|
+
"editor",
|
|
7
|
+
"rich-text",
|
|
8
|
+
"markdown",
|
|
9
|
+
"mdast",
|
|
10
|
+
"micromark"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"version": "0.47.0",
|
|
14
|
+
"main": "./dist/LexicalMdast.js",
|
|
15
|
+
"types": "./dist/typescript-too-old.d.ts",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@types/mdast": "^4.0.4",
|
|
18
|
+
"mdast-util-from-markdown": "^2.0.3",
|
|
19
|
+
"mdast-util-gfm-autolink-literal": "^2.0.1",
|
|
20
|
+
"mdast-util-gfm-strikethrough": "^2.0.0",
|
|
21
|
+
"mdast-util-gfm-table": "^2.0.0",
|
|
22
|
+
"mdast-util-gfm-task-list-item": "^2.0.0",
|
|
23
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
24
|
+
"mdast-util-to-string": "^4.0.0",
|
|
25
|
+
"micromark-extension-gfm-autolink-literal": "^2.1.0",
|
|
26
|
+
"micromark-extension-gfm-strikethrough": "^2.1.0",
|
|
27
|
+
"micromark-extension-gfm-table": "^2.1.1",
|
|
28
|
+
"micromark-extension-gfm-task-list-item": "^2.1.0",
|
|
29
|
+
"micromark-util-types": "^2.0.2",
|
|
30
|
+
"@lexical/code-core": "0.47.0",
|
|
31
|
+
"@lexical/list": "0.47.0",
|
|
32
|
+
"@lexical/extension": "0.47.0",
|
|
33
|
+
"@lexical/rich-text": "0.47.0",
|
|
34
|
+
"@lexical/link": "0.47.0",
|
|
35
|
+
"@lexical/selection": "0.47.0",
|
|
36
|
+
"@lexical/table": "0.47.0",
|
|
37
|
+
"@lexical/utils": "0.47.0",
|
|
38
|
+
"lexical": "0.47.0"
|
|
39
|
+
},
|
|
6
40
|
"repository": {
|
|
7
41
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/facebook/lexical.git"
|
|
42
|
+
"url": "git+https://github.com/facebook/lexical.git",
|
|
43
|
+
"directory": "packages/lexical-mdast"
|
|
44
|
+
},
|
|
45
|
+
"module": "./dist/LexicalMdast.mjs",
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"exports": {
|
|
48
|
+
".": {
|
|
49
|
+
"source": "./src/index.ts",
|
|
50
|
+
"import": {
|
|
51
|
+
"types@<5.2": "./dist/typescript-too-old.d.ts",
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"development": "./dist/LexicalMdast.dev.mjs",
|
|
54
|
+
"production": "./dist/LexicalMdast.prod.mjs",
|
|
55
|
+
"node": "./dist/LexicalMdast.node.mjs",
|
|
56
|
+
"default": "./dist/LexicalMdast.mjs"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types@<5.2": "./dist/typescript-too-old.d.ts",
|
|
60
|
+
"types": "./dist/index.d.ts",
|
|
61
|
+
"development": "./dist/LexicalMdast.dev.js",
|
|
62
|
+
"production": "./dist/LexicalMdast.prod.js",
|
|
63
|
+
"default": "./dist/LexicalMdast.js"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"dist",
|
|
69
|
+
"src",
|
|
70
|
+
"!src/__tests__",
|
|
71
|
+
"!src/__bench__",
|
|
72
|
+
"!src/__mocks__",
|
|
73
|
+
"!src/**/*.test.ts",
|
|
74
|
+
"!src/**/*.test.tsx",
|
|
75
|
+
"!src/**/*.bench.ts",
|
|
76
|
+
"!src/**/*.bench.tsx",
|
|
77
|
+
"README.md",
|
|
78
|
+
"LICENSE"
|
|
79
|
+
],
|
|
80
|
+
"typesVersions": {
|
|
81
|
+
"*": {
|
|
82
|
+
"*": [
|
|
83
|
+
"./dist/typescript-too-old.d.ts"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"peerDependencies": {
|
|
88
|
+
"typescript": ">=5.2"
|
|
9
89
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"typescript": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|