@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.
@@ -0,0 +1,11 @@
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
+ 'use strict'
10
+ const LexicalMdast = process.env.NODE_ENV !== 'production' ? require('./LexicalMdast.dev.js') : require('./LexicalMdast.prod.js');
11
+ module.exports = LexicalMdast;
@@ -0,0 +1,228 @@
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
+ * @flow strict
8
+ */
9
+
10
+ import type {
11
+ BaseSelection,
12
+ ElementNode,
13
+ ExtensionConfigBase,
14
+ LexicalExtension,
15
+ LexicalNode,
16
+ } from 'lexical';
17
+ import type {NamedSignalsOutput} from '@lexical/extension';
18
+
19
+ // mdast / micromark structures stay `unknown` rather than opaque: Flow
20
+ // consumers receive them from untyped remark/unified tooling and construct
21
+ // mdast literals in custom export handlers, so an opaque type would force
22
+ // suppressions at every producer.
23
+ export type MdastNode = unknown;
24
+ export type MdastParent = unknown;
25
+
26
+ // The compiled registry is a pure handle: consumers only receive it from
27
+ // `MdastImportExtensionOutput` and hand it back to `@lexical/mdast` APIs,
28
+ // never construct or introspect it — exactly what opaque models.
29
+ declare export opaque type CompiledMdast;
30
+
31
+ export type MdastImportContext = {
32
+ readonly format: number,
33
+ readonly source: string,
34
+ importChildren(parent: MdastParent, format?: number): LexicalNode[],
35
+ importNode(node: MdastNode, format?: number): LexicalNode[],
36
+ createText(value: string, format?: number): LexicalNode[],
37
+ getDefinition(
38
+ identifier: string,
39
+ ): {url: string, title?: string | null} | void,
40
+ };
41
+
42
+ export type MdastExportContext = {
43
+ exportChildren(node: ElementNode): MdastNode[],
44
+ exportInline(node: ElementNode): MdastNode[],
45
+ exportBlocks(node: ElementNode): MdastNode[],
46
+ isIncluded(node: LexicalNode): boolean,
47
+ };
48
+
49
+ export type MdastImportHandler = (
50
+ node: MdastNode,
51
+ context: MdastImportContext,
52
+ ) => LexicalNode | LexicalNode[] | null;
53
+
54
+ export type MdastExportHandler = (
55
+ node: LexicalNode,
56
+ context: MdastExportContext,
57
+ ) => MdastNode | MdastNode[] | null;
58
+
59
+ export type MdastImportRule = {
60
+ readonly type: string,
61
+ readonly $import: MdastImportHandler,
62
+ };
63
+
64
+ export type MdastExportRule = {
65
+ readonly type: string,
66
+ readonly $export: MdastExportHandler,
67
+ };
68
+
69
+ export type MdastConfig = {
70
+ readonly importRules: ReadonlyArray<MdastImportRule>,
71
+ readonly exportRules: ReadonlyArray<MdastExportRule>,
72
+ readonly micromarkExtensions: ReadonlyArray<unknown>,
73
+ readonly mdastExtensions: ReadonlyArray<unknown>,
74
+ readonly toMarkdownExtensions: ReadonlyArray<unknown>,
75
+ readonly inlineShortcutTypes: ReadonlyArray<string>,
76
+ readonly inlineShortcutTriggers: ReadonlyArray<string>,
77
+ };
78
+
79
+ export type MdastShortcutsConfig = {
80
+ readonly disabled: boolean,
81
+ };
82
+
83
+ export type MdastImportExtensionOutput = {
84
+ $convertFromMarkdownString(markdown: string, node?: ElementNode): void,
85
+ $convertFromMdast(tree: unknown, node?: ElementNode): void,
86
+ $generateNodesFromMarkdownString(markdown: string): LexicalNode[],
87
+ $generateNodesFromMdast(tree: unknown): LexicalNode[],
88
+ readonly registry: CompiledMdast,
89
+ };
90
+
91
+ export type MdastExportExtensionOutput = {
92
+ $convertToMarkdownString(node?: ElementNode): string,
93
+ $convertToMdast(node?: ElementNode): unknown,
94
+ $convertSelectionToMarkdownString(selection?: BaseSelection | null): string,
95
+ };
96
+
97
+ declare export function $convertFromMarkdownString(
98
+ markdown: string,
99
+ node?: ElementNode,
100
+ ): void;
101
+
102
+ declare export function $convertToMarkdownString(node?: ElementNode): string;
103
+
104
+ declare export function $convertFromMdast(
105
+ tree: unknown,
106
+ node?: ElementNode,
107
+ ): void;
108
+
109
+ declare export function $convertToMdast(node?: ElementNode): unknown;
110
+
111
+ declare export function $generateNodesFromMarkdownString(
112
+ markdown: string,
113
+ ): LexicalNode[];
114
+
115
+ declare export function $generateNodesFromMdast(tree: unknown): LexicalNode[];
116
+
117
+ declare export function $convertSelectionToMarkdownString(
118
+ selection?: BaseSelection | null,
119
+ ): string;
120
+
121
+ declare export var MdastImportExtension: LexicalExtension<
122
+ MdastConfig,
123
+ '@lexical/mdast/Import',
124
+ MdastImportExtensionOutput,
125
+ void,
126
+ >;
127
+ declare export var MdastExtension: LexicalExtension<
128
+ ExtensionConfigBase,
129
+ '@lexical/mdast/Mdast',
130
+ void,
131
+ void,
132
+ >;
133
+ declare export var MdastHeadingExtension: LexicalExtension<
134
+ ExtensionConfigBase,
135
+ '@lexical/mdast/Heading',
136
+ void,
137
+ void,
138
+ >;
139
+ declare export var MdastBlockquoteExtension: LexicalExtension<
140
+ ExtensionConfigBase,
141
+ '@lexical/mdast/Blockquote',
142
+ void,
143
+ void,
144
+ >;
145
+ declare export var MdastRichTextExtension: LexicalExtension<
146
+ ExtensionConfigBase,
147
+ '@lexical/mdast/RichText',
148
+ void,
149
+ void,
150
+ >;
151
+ declare export var MdastListExtension: LexicalExtension<
152
+ ExtensionConfigBase,
153
+ '@lexical/mdast/List',
154
+ void,
155
+ void,
156
+ >;
157
+ declare export var MdastTaskListExtension: LexicalExtension<
158
+ ExtensionConfigBase,
159
+ '@lexical/mdast/TaskList',
160
+ void,
161
+ void,
162
+ >;
163
+ declare export var MdastCodeExtension: LexicalExtension<
164
+ ExtensionConfigBase,
165
+ '@lexical/mdast/Code',
166
+ void,
167
+ void,
168
+ >;
169
+ declare export var MdastLinkExtension: LexicalExtension<
170
+ ExtensionConfigBase,
171
+ '@lexical/mdast/Link',
172
+ void,
173
+ void,
174
+ >;
175
+ declare export var MdastAutolinkLiteralExtension: LexicalExtension<
176
+ ExtensionConfigBase,
177
+ '@lexical/mdast/AutolinkLiteral',
178
+ void,
179
+ void,
180
+ >;
181
+ declare export var MdastExportExtension: LexicalExtension<
182
+ ExtensionConfigBase,
183
+ '@lexical/mdast/Export',
184
+ MdastExportExtensionOutput,
185
+ void,
186
+ >;
187
+ declare export var MdastStrikethroughExtension: LexicalExtension<
188
+ ExtensionConfigBase,
189
+ '@lexical/mdast/Strikethrough',
190
+ void,
191
+ void,
192
+ >;
193
+ declare export var MdastHorizontalRuleExtension: LexicalExtension<
194
+ ExtensionConfigBase,
195
+ '@lexical/mdast/HorizontalRule',
196
+ void,
197
+ void,
198
+ >;
199
+ declare export var MdastShadowRootQuoteExtension: LexicalExtension<
200
+ ExtensionConfigBase,
201
+ '@lexical/mdast/ShadowRootQuote',
202
+ void,
203
+ void,
204
+ >;
205
+ declare export var MdastCommonMarkExtension: LexicalExtension<
206
+ ExtensionConfigBase,
207
+ '@lexical/mdast/CommonMark',
208
+ void,
209
+ void,
210
+ >;
211
+ declare export var MdastTableExtension: LexicalExtension<
212
+ ExtensionConfigBase,
213
+ '@lexical/mdast/Table',
214
+ void,
215
+ void,
216
+ >;
217
+ declare export var MdastGfmExtension: LexicalExtension<
218
+ ExtensionConfigBase,
219
+ '@lexical/mdast/Gfm',
220
+ void,
221
+ void,
222
+ >;
223
+ declare export var MdastShortcutsExtension: LexicalExtension<
224
+ MdastShortcutsConfig,
225
+ '@lexical/mdast/Shortcuts',
226
+ NamedSignalsOutput<MdastShortcutsConfig>,
227
+ void,
228
+ >;
@@ -0,0 +1,36 @@
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
+ import * as modDev from './LexicalMdast.dev.mjs';
10
+ import * as modProd from './LexicalMdast.prod.mjs';
11
+ const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
12
+ export const $convertFromMarkdownString = mod.$convertFromMarkdownString;
13
+ export const $convertFromMdast = mod.$convertFromMdast;
14
+ export const $convertSelectionToMarkdownString = mod.$convertSelectionToMarkdownString;
15
+ export const $convertToMarkdownString = mod.$convertToMarkdownString;
16
+ export const $convertToMdast = mod.$convertToMdast;
17
+ export const $generateNodesFromMarkdownString = mod.$generateNodesFromMarkdownString;
18
+ export const $generateNodesFromMdast = mod.$generateNodesFromMdast;
19
+ export const MdastAutolinkLiteralExtension = mod.MdastAutolinkLiteralExtension;
20
+ export const MdastBlockquoteExtension = mod.MdastBlockquoteExtension;
21
+ export const MdastCodeExtension = mod.MdastCodeExtension;
22
+ export const MdastCommonMarkExtension = mod.MdastCommonMarkExtension;
23
+ export const MdastExportExtension = mod.MdastExportExtension;
24
+ export const MdastExtension = mod.MdastExtension;
25
+ export const MdastGfmExtension = mod.MdastGfmExtension;
26
+ export const MdastHeadingExtension = mod.MdastHeadingExtension;
27
+ export const MdastHorizontalRuleExtension = mod.MdastHorizontalRuleExtension;
28
+ export const MdastImportExtension = mod.MdastImportExtension;
29
+ export const MdastLinkExtension = mod.MdastLinkExtension;
30
+ export const MdastListExtension = mod.MdastListExtension;
31
+ export const MdastRichTextExtension = mod.MdastRichTextExtension;
32
+ export const MdastShadowRootQuoteExtension = mod.MdastShadowRootQuoteExtension;
33
+ export const MdastShortcutsExtension = mod.MdastShortcutsExtension;
34
+ export const MdastStrikethroughExtension = mod.MdastStrikethroughExtension;
35
+ export const MdastTableExtension = mod.MdastTableExtension;
36
+ export const MdastTaskListExtension = mod.MdastTaskListExtension;
@@ -0,0 +1,34 @@
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
+ const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalMdast.dev.mjs') : import('./LexicalMdast.prod.mjs'));
10
+ export const $convertFromMarkdownString = mod.$convertFromMarkdownString;
11
+ export const $convertFromMdast = mod.$convertFromMdast;
12
+ export const $convertSelectionToMarkdownString = mod.$convertSelectionToMarkdownString;
13
+ export const $convertToMarkdownString = mod.$convertToMarkdownString;
14
+ export const $convertToMdast = mod.$convertToMdast;
15
+ export const $generateNodesFromMarkdownString = mod.$generateNodesFromMarkdownString;
16
+ export const $generateNodesFromMdast = mod.$generateNodesFromMdast;
17
+ export const MdastAutolinkLiteralExtension = mod.MdastAutolinkLiteralExtension;
18
+ export const MdastBlockquoteExtension = mod.MdastBlockquoteExtension;
19
+ export const MdastCodeExtension = mod.MdastCodeExtension;
20
+ export const MdastCommonMarkExtension = mod.MdastCommonMarkExtension;
21
+ export const MdastExportExtension = mod.MdastExportExtension;
22
+ export const MdastExtension = mod.MdastExtension;
23
+ export const MdastGfmExtension = mod.MdastGfmExtension;
24
+ export const MdastHeadingExtension = mod.MdastHeadingExtension;
25
+ export const MdastHorizontalRuleExtension = mod.MdastHorizontalRuleExtension;
26
+ export const MdastImportExtension = mod.MdastImportExtension;
27
+ export const MdastLinkExtension = mod.MdastLinkExtension;
28
+ export const MdastListExtension = mod.MdastListExtension;
29
+ export const MdastRichTextExtension = mod.MdastRichTextExtension;
30
+ export const MdastShadowRootQuoteExtension = mod.MdastShadowRootQuoteExtension;
31
+ export const MdastShortcutsExtension = mod.MdastShortcutsExtension;
32
+ export const MdastStrikethroughExtension = mod.MdastStrikethroughExtension;
33
+ export const MdastTableExtension = mod.MdastTableExtension;
34
+ export const MdastTaskListExtension = mod.MdastTaskListExtension;
@@ -0,0 +1,11 @@
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
+ "use strict";var e=require("@lexical/extension"),t=require("lexical"),n=require("@lexical/selection"),o=require("mdast-util-to-markdown"),r=require("mdast-util-to-string"),i=require("@lexical/code-core"),s=require("@lexical/link"),a=require("@lexical/list"),l=require("@lexical/rich-text"),d=require("mdast-util-gfm-autolink-literal"),c=require("mdast-util-gfm-strikethrough"),u=require("mdast-util-gfm-task-list-item"),p=require("micromark-extension-gfm-autolink-literal"),f=require("micromark-extension-gfm-strikethrough"),m=require("micromark-extension-gfm-task-list-item"),h=require("mdast-util-from-markdown"),g=require("@lexical/table"),x=require("mdast-util-gfm-table"),$=require("micromark-extension-gfm-table");const k=/* @__PURE__ */t.createState("mdastListMarker",{parse:e=>"-"===e||"*"===e||"+"===e?e:"",resetOnCopyNode:!0}),T=/* @__PURE__ */t.createState("mdastOrderedMarker",{parse:e=>"."===e||")"===e?e:"",resetOnCopyNode:!0}),S=/* @__PURE__ */t.createState("mdastEmphasisMarker",{parse:e=>"_"===e?"_":"",resetOnCopyNode:!0}),y=/* @__PURE__ */t.createState("mdastStrongMarker",{parse:e=>"_"===e?"_":"",resetOnCopyNode:!0}),N=/* @__PURE__ */t.createState("mdastSetext",{parse:e=>!0===e,resetOnCopyNode:!0}),E=/* @__PURE__ */t.createState("mdastCodeFence",{parse:e=>"string"==typeof e&&/^(`{3,}|~{3,})$/.test(e)?e:"",resetOnCopyNode:!0}),C=/* @__PURE__ */t.createState("mdastCodeMeta",{parse:e=>"string"==typeof e?e:"",resetOnCopyNode:!0}),M=/* @__PURE__ */t.createState("mdastHardLineBreak",{parse:e=>"string"==typeof e&&/^(\\| {2,})$/.test(e)?e:"",resetOnCopyNode:!0}),R=/* @__PURE__ */t.createState("mdastParagraphBreak",{parse:e=>!0===e,resetOnCopyNode:!0}),w=/* @__PURE__ */t.createState("mdastHrMarker",{parse:e=>"-"===e||"*"===e||"_"===e?e:"",resetOnCopyNode:!0}),b=/* @__PURE__ */t.createState("mdastLinkStyle",{parse:e=>"inline"===e||"autolink"===e||"literal"===e?e:"",resetOnCopyNode:!0});function L(e,t){return e.splice(e.getChildrenSize(),0,t)}function v(e){return(t.$isElementNode(e)||t.$isDecoratorNode(e))&&!e.isInline()}function O(){return t.$setState(t.$createLineBreakNode(),R,!0)}const I=t.TEXT_TYPE_TO_FORMAT.bold,F=t.TEXT_TYPE_TO_FORMAT.italic,_=t.TEXT_TYPE_TO_FORMAT.strikethrough,H=t.TEXT_TYPE_TO_FORMAT.code,B=I|F|_|H;function q(e){if(e.ordered)return"number";for(const t of e.children)if("listItem"===t.type&&null!=t.checked)return"check";return"bullet"}function A(e,n){return(o,r)=>{const i=r.importChildren(o,e);if("_"===function(e,t){if(e.source&&t.position&&null!=t.position.start.offset)return e.source[t.position.start.offset]}(r,o))for(const e of i)t.$isTextNode(e)&&t.$setState(e,n,"_");return i}}const P=/* @__PURE__ */A(F,S),z=/* @__PURE__ */A(I,y),D={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function Q(e,n){const o=e.getListType(),r={children:[],ordered:"number"===o,spread:!1,start:"number"===o?e.getStart():void 0,type:"list"};if("number"===o){const n=t.$getState(e,T);n&&(r.data={mdastBulletOrdered:n})}else{const n=t.$getState(e,k);n&&(r.data={mdastBullet:n})}let i=null;for(const t of e.getChildren()){if(!a.$isListItemNode(t)||!n.isIncluded(t))continue;const e=t.getFirstChild();if(1===t.getChildrenSize()&&a.$isListNode(e)){const t=Q(e,n);i?i.children.push(t):r.children.push({children:[t],spread:!1,type:"listItem"});continue}const s={checked:"check"===o?t.getChecked()??!1:null,children:n.exportBlocks(t),spread:!1,type:"listItem"};r.children.push(s),i=s}return r}function Y(e,t){let n=t&H?{type:"inlineCode",value:e}:{type:"text",value:e};return t&F&&(n={children:[n],type:"emphasis"}),t&I&&(n={children:[n],type:"strong"}),t&_&&(n={children:[n],type:"delete"}),n}const G=e=>t.$isTextNode(e)?Y(e.getTextContent(),e.getFormat()&B):null,U=e=>t.$isLineBreakNode(e)?{data:{mdastBreak:t.$getState(e,M)},type:"break"}:null;function X(e,t,n){const{options:o}=e,r={};for(const e of Object.keys(t))r[e]=o[e],o[e]=t[e];try{return n()}finally{for(const e of Object.keys(r))o[e]=r[e]}}const K={handlers:{break(e,t,n,r){const i=o.defaultHandlers.break(e,t,n,r);if("\\\n"!==i)return i;const s=e.data&&e.data.mdastBreak;return s?/^ {2,}$/.test(s)?`${s}\n`:i:"\n"},code(e,t,n,r){const i=e.data&&e.data.mdastFence;return i?X(n,{fence:"~"===i[0]?"~":"`",fences:!0},()=>o.defaultHandlers.code(e,t,n,r)):o.defaultHandlers.code(e,t,n,r)},heading:(e,t,n,r)=>e.data&&!0===e.data.mdastSetext?X(n,{setext:!0},()=>o.defaultHandlers.heading(e,t,n,r)):o.defaultHandlers.heading(e,t,n,r),link(e,t,n,i){const s=e.data&&e.data.mdastLinkStyle;return"literal"===s&&null==e.title?r.toString(e):"inline"===s?X(n,{resourceLink:!0},()=>o.defaultHandlers.link(e,t,n,i)):o.defaultHandlers.link(e,t,n,i)},list(e,t,n,r){if(e.ordered){const i=e.data&&e.data.mdastBulletOrdered;return null==i?o.defaultHandlers.list(e,t,n,r):X(n,{bulletOrdered:i},()=>o.defaultHandlers.list(e,t,n,r))}const i=e.data&&e.data.mdastBullet;return null==i?o.defaultHandlers.list(e,t,n,r):X(n,{bullet:i,bulletOther:"-"===i?"*":"-"},()=>o.defaultHandlers.list(e,t,n,r))},thematicBreak(e,t,n){const r=e.data&&e.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?o.defaultHandlers.thematicBreak(e,t,n):X(n,{rule:r},()=>o.defaultHandlers.thematicBreak(e,t,n))}}};class j{format=-1;value="";push(e,n){if(!t.$isTextNode(e))return!1;const o=e.getFormat()&B;return o===this.format?this.value+=e.getTextContent():(this.flushInto(n),this.format=o,this.value=e.getTextContent()),!0}flushInto(e){this.format>=0&&e.push(Y(this.value,this.format)),this.format=-1,this.value=""}}function W(e,o=null){const{exportHandlers:r}=e;let i=0;function s(e){const t=r.get(e.getType());return void 0===t||t===G}function a(e){return null===o||t.$isElementNode(e)?e:e.isSelected(o)?(i++,t.$isTextNode(e)?n.$sliceSelectedTextNodeContent(o,e,"clone"):e):null}function l(e,t){const n=null!==o&&e.isSelected(o);n&&i++;const r=i,s=c(e);(null===o||n||i>r)&&t.push(...s)}const d={exportBlocks:e=>function(e){const n=[];let o=[];const r=new j,i=()=>{r.flushInto(o),o.length>0&&(n.push({children:o,type:"paragraph"}),o=[])};for(const d of e.getChildren()){const e=a(d);if(null!==e)if(t.$isLineBreakNode(e)){const n=U(e);t.$getState(e,R)||null===n?i():(r.flushInto(o),o.push(n))}else{if(s(e)&&r.push(e,o))continue;v(e)?(i(),t.$isElementNode(e)?l(e,n):n.push(...c(e))):t.$isElementNode(e)?(r.flushInto(o),l(e,o)):(r.flushInto(o),o.push(...c(e)))}}i(),0===n.length&&n.push({children:[],type:"paragraph"});return n}(e),exportChildren:e=>{const n=[];for(const o of e.getChildren()){const e=a(o);null!==e&&(t.$isElementNode(e)?l(e,n):n.push(...c(e)))}return n},exportInline:e=>function(e){const n=[],o=new j;for(const r of e.getChildren()){const e=a(r);null!==e&&(s(e)&&o.push(e,n)||(o.flushInto(n),t.$isElementNode(e)?l(e,n):n.push(...c(e))))}return o.flushInto(n),n}(e),isIncluded:function e(n){if(null===o||n.isSelected(o))return!0;if(t.$isElementNode(n))for(const t of n.getChildren())if(e(t))return!0;return!1}};function c(e){const n=r.get(e.getType());if(n){const t=n(e,d);if(null!=t)return Array.isArray(t)?t:[t]}const o=G(e);if(null!==o)return[o];const i=U(e);if(null!==i)return[i];if(t.$isElementNode(e))return d.exportChildren(e);const s=e.getTextContent();return s?[{type:"text",value:s}]:[]}return{exportChildren:d.exportChildren}}function J(e){const n=W(e),r=(e,t)=>({children:t.exportChildren(e),type:"root"}),i=(n,r)=>{const{emphasis:i,strong:s}=function(e){let n,o;const r=e=>{for(const i of e.getChildren())if(t.$isTextNode(i)?(void 0===n&&i.hasFormat("italic")&&"_"===t.$getState(i,S)&&(n="_"),void 0===o&&i.hasFormat("bold")&&"_"===t.$getState(i,y)&&(o="_")):t.$isElementNode(i)&&r(i),void 0!==n&&void 0!==o)return};return r(e),{emphasis:n,strong:o}}(r),a={bullet:"-"};i&&(a.emphasis=i),s&&(a.strong=s);return o.toMarkdown(n,{extensions:[a,...e.toMarkdownExtensions,K]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(n=t.$getSelection())=>{if(null===n||t.$isRangeSelection(n)&&n.isCollapsed())return"";const o=t.$getRoot();return i(r(o,W(e,n)),o)},$exportToMarkdown:e=>{const o=e||t.$getRoot();return i(r(o,n),o)},$exportToMdast:e=>r(e||t.$getRoot(),n)}}function V(e,n){const o=[];return t.tokenizeRawText(e,{linebreak:()=>o.push(t.$createLineBreakNode()),tab:()=>o.push(t.$createTabNode()),text:e=>{const r=t.$createTextNode(e);n&&r.setFormat(n),o.push(r)}}),o}const Z=new Map;function ee(e,t="",n=Z){const{importHandlers:o}=e,r=new Map;function i(e,a){const l=o.get(e.type);if(l){const o=l(e,function(e){let o=r.get(e);return void 0===o&&(o={createText:(t,n)=>V(t,null==n?e:n),format:e,getDefinition:e=>n.get(e),importChildren:(t,n)=>s(t,e|(n||0)),importNode:(t,n)=>i(t,e|(n||0)),source:t},r.set(e,o)),o}(a));return null==o?[]:Array.isArray(o)?o:[o]}return"children"in e?s(e,a):"value"in e&&"string"==typeof e.value?V(e.value,a):[]}function s(e,t){const n=[];for(const o of e.children)n.push(...i(o,t));return n}return{$importChildren:s,$importNode:i}}function te(e){const n=(n,o)=>{const{$importNode:r}=ee(e,o,function(e){const t=new Map,n=e=>{if("definition"===e.type&&(t.has(e.identifier)||t.set(e.identifier,{title:e.title,url:e.url})),"children"in e)for(const t of e.children)n(t)};return n(e),t}(n)),i=[];let s=null;const a=()=>{s&&(i.push(s),s=null)};for(const e of n.children)for(const n of r(e,0))v(n)?(a(),i.push(n)):(s||(s=t.$createParagraphNode()),L(s,[n]));return a(),i},o=t=>n(h.fromMarkdown(t,{extensions:e.micromarkExtensions,mdastExtensions:e.mdastExtensions}),t),r=e=>n(e,""),i=(e,n)=>{const o=n||t.$getRoot();var r,i;o.clear(),r=o,i=e.length>0?e:[t.$createParagraphNode()],r.splice(0,0,i),null!==t.$getSelection()&&o.selectStart()};return{$generateNodesFromMarkdown:o,$generateNodesFromMdast:r,$importMarkdown:(e,t)=>i(o(e),t),$importMdast:(e,t)=>i(r(e),t)}}function ne(e,t){let n=e;for(;;){if("heading"===n.type||"paragraph"===n.type){const e=n.children[0];return e&&e.position&&null!=e.position.start.offset?e.position.start.offset:t.length}if(!("children"in n)||0===n.children.length)return t.length;n=n.children[0]}}class oe{compiled;importNode;supportsTaskListItems;constructor(e){this.compiled=e,this.importNode=ee(e,"").$importNode;const t=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=t&&"list"===t.type&&!0===t.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(e){return h.fromMarkdown(e,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(e){return this.importNode(e,0)}scanBlock(e){if(""===e.trim())return null;const t=this.parse(e).children[0];if(!t||!this.compiled.importHandlers.has(t.type))return null;switch(t.type){case"heading":return{kind:"heading",markerLength:ne(t,e),node:t};case"blockquote":return{kind:"blockquote",markerLength:ne(t,e),node:t};case"list":return{kind:"list",markerLength:ne(t,e),node:t};case"code":return{kind:"code",markerLength:e.length,node:t};default:return null}}scanInline(e){if(0===e.length)return null;const t=this.parse(e),n=t.children[t.children.length-1];if(!n||"paragraph"!==n.type)return null;const o=n.children[n.children.length-1];if(!o||!o.position||o.position.end.offset!==e.length||!this.compiled.inlineShortcutTypes.has(o.type))return null;const r=o.position.start.offset??0,i=e[r];return r>0&&e[r-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:o}}function re(e,n){let o=n,r=e.getFirstChild();for(;o>0&&r&&t.$isTextNode(r);){const e=r.getTextContent();if(e.length<=o){const t=r.getNextSibling();o-=e.length,r.remove(),r=t}else r.setTextContent(e.slice(o)),o=0}}function ie(e,n){const o="code"===n.kind?e.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;re(e,n.markerLength);const r=e.getChildren();if("code"===n.kind){const s=i.$createCodeNode(n.node.lang||void 0);return o&&t.$setState(s,E,o[1]),n.node.meta&&t.$setState(s,C,n.node.meta),L(s,r),e.replace(s),s.selectStart(),!0}let s,d;if("heading"===n.kind){const e=L(l.$createHeadingNode(`h${n.node.depth}`),r);s=e,d=e}else if("blockquote"===n.kind){const e=L(l.$createQuoteNode(),r);s=e,d=e}else{const e=n.node,t=q(e),o=e.ordered&&null!=e.start?e.start:1,i=a.$createListNode(t,o),l=e.children[0],c=l&&"listItem"===l.type&&"boolean"==typeof l.checked?l.checked:void 0,u=L(a.$createListItemNode(c),r);L(i,[u]),s=i,d=u}return e.replace(s),d.selectStart(),!0}const se=/^\[([ xX])\]\s$/;function ae(e,n){return t.$isParagraphNode(e)&&t.$isRootOrShadowRoot(e.getParent())&&e.getFirstChild()===n}function le(e,n){const o=new oe(n),r=o.inlineTriggers,s=new Set([" ",...r]);return t.mergeRegister(e.registerUpdateListener(({tags:n,dirtyLeaves:l,editorState:d,prevEditorState:c})=>{if(0===l.size||n.has(t.COLLABORATION_TAG)||n.has(t.HISTORIC_TAG))return;if(e.isComposing())return;const u=n.has(t.COMPOSITION_END_TAG),p=d.read(t.$getSelection),f=c.read(t.$getSelection);if(!t.$isRangeSelection(p)||!t.$isRangeSelection(f)||!p.isCollapsed()||p.is(f)&&!u)return;const m=p.anchor.key,h=p.anchor.offset,g=d._nodeMap.get(m);if(!t.$isTextNode(g)||!l.has(m))return;if(!u&&1!==h&&(f.anchor.key!==m||h!==f.anchor.offset+1))return;const x=d.read(()=>g.getTextContent()),$=x[h-1];var k,T;u&&!s.has($)||(" "===$||r.has($))&&(" "===$||(k=x.slice(0,h),")"===(T=$)?k.lastIndexOf("](")>0:-1!==k.lastIndexOf(T,k.length-2)))&&e.update(()=>{const e=t.$getNodeByKey(m);if(!t.$isTextNode(e)||e.hasFormat("code"))return;const n=e.getParent();if(null===n||i.$isCodeNode(n))return;let r=!1;if(" "===$){if(o.supportsTaskListItems&&function(e,t,n){if(t.getFirstChild()!==e)return!1;const o=t.getTextContent().slice(0,n).match(se);if(!o)return!1;const r="x"===o[1].toLowerCase();if(a.$isListItemNode(t)){const e=t.getParent();return!(!a.$isListNode(e)||"number"===e.getListType()||(re(t,o[0].length),e.setListType("check"),t.setChecked(r),0))}if(ae(t,e)){re(t,o[0].length);const e=t.getChildren(),n=a.$createListNode("check"),i=L(a.$createListItemNode(r),e);return L(n,[i]),t.replace(n),i.selectStart(),!0}return!1}(e,n,h))r=!0;else if(h<=24&&ae(n,e)){const t=o.scanBlock(e.getTextContent().slice(0,h));t&&"code"!==t.kind&&t.markerLength===h&&(r=ie(n,t))}}else r=function(e,n,o){const r=e.getTextContent().slice(0,n),i=o.scanInline(r);if(!i||!i.position)return!1;const s=i.position.start.offset??0,a=n;let l;if(s<=0)[l]=e.splitText(a);else{const t=e.splitText(s,a);l=3===t.length?t[1]:t[t.length-1]}const d=o.importInline(i);if(0===d.length)return!1;let c=d[0];l.replace(c);for(let e=1;e<d.length;e++)c.insertAfter(d[e]),c=d[e];if(t.$isTextNode(c)){const e=c.getTextContentSize();c.select(e,e)}else c.selectNext(0,0);return!0}(e,h,o);r&&t.$addUpdateTag(t.HISTORY_PUSH_TAG)})}),e.registerCommand(t.KEY_ENTER_COMMAND,e=>{if(null!==e&&e.shiftKey)return!1;const n=t.$getSelection();if(!t.$isRangeSelection(n)||!n.isCollapsed())return!1;const r=n.anchor.getNode();if(!t.$isTextNode(r)||r.hasFormat("code"))return!1;const s=r.getParent(),a=n.anchor.offset;if(null===s||i.$isCodeNode(s)||!ae(s,r)||a!==r.getTextContentSize())return!1;const l=o.scanBlock(s.getTextContent());return!(!l||l.markerLength!==a||!ie(s,l))&&(null!==e&&e.preventDefault(),!0)},t.COMMAND_PRIORITY_BEFORE_EDITOR))}const de=[{$import:(e,n)=>L(t.$createParagraphNode(),n.importChildren(e)),type:"paragraph"},{$import:(e,t)=>t.createText(e.value),type:"text"},{$import:(e,t)=>t.createText(e.value),type:"html"},{$import:(e,t)=>t.createText(e.value,t.format|H),type:"inlineCode"},{$import:P,type:"emphasis"},{$import:z,type:"strong"},{$import:(e,n)=>{let o="\\";if(n.source&&e.position){const{start:t,end:r}=e.position;if(null!=t.offset&&null!=r.offset){const e=n.source.slice(t.offset,r.offset).replace(/\n$/,"");/^ {2,}$/.test(e)&&(o=e)}}return[t.$setState(t.$createLineBreakNode(),M,o)]},type:"break"}],ce=[{$export:(e,n)=>t.$isParagraphNode(e)?{children:n.exportInline(e),type:"paragraph"}:null,type:"paragraph"},{$export:G,type:"text"},{$export:U,type:"linebreak"},{$export:e=>t.$isTabNode(e)?{type:"text",value:"\t"}:null,type:"tab"}],ue=/* @__PURE__ */t.defineExtension({build(e,t){const n=function(e){const t=new Map,n=new Map;for(const n of e.importRules)t.has(n.type)||t.set(n.type,n.$import);for(const t of e.exportRules)n.has(t.type)||n.set(t.type,t.$export);return{exportHandlers:n,importHandlers:t,inlineShortcutTriggers:new Set(e.inlineShortcutTriggers),inlineShortcutTypes:new Set(e.inlineShortcutTypes),mdastExtensions:[...e.mdastExtensions],micromarkExtensions:[...e.micromarkExtensions],toMarkdownExtensions:[...e.toMarkdownExtensions]}}(t),{$generateNodesFromMarkdown:o,$generateNodesFromMdast:r,$importMarkdown:i,$importMdast:s}=te(n);return{$convertFromMarkdownString:i,$convertFromMdast:s,$generateNodesFromMarkdownString:o,$generateNodesFromMdast:r,registry:n}},config:/* @__PURE__ */t.safeCast({exportRules:ce,importRules:de,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]}),mergeConfig(e,n){function o(e,t){return e?[...e,...t]:t}return t.shallowMergeConfig(e,{exportRules:o(n.exportRules,e.exportRules),importRules:o(n.importRules,e.importRules),inlineShortcutTriggers:o(n.inlineShortcutTriggers,e.inlineShortcutTriggers),inlineShortcutTypes:o(n.inlineShortcutTypes,e.inlineShortcutTypes),mdastExtensions:o(n.mdastExtensions,e.mdastExtensions),micromarkExtensions:o(n.micromarkExtensions,e.micromarkExtensions),toMarkdownExtensions:o(n.toMarkdownExtensions,e.toMarkdownExtensions)})},name:"@lexical/mdast/Import"}),pe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,n)=>{if(!l.$isHeadingNode(e))return null;const o={children:n.exportInline(e),depth:D[e.getTag()],type:"heading"};return t.$getState(e,N)&&(o.data={mdastSetext:!0}),o},type:"heading"}],importRules:[{$import:(e,n)=>{const o=l.$createHeadingNode(`h${e.depth}`);if(n.source&&e.position&&(1===e.depth||2===e.depth)){const r=e.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(n.source.slice(r,r+10))||t.$setState(o,N,!0)}return L(o,n.importChildren(e))},type:"heading"}]})],name:"@lexical/mdast/Heading",nodes:[l.HeadingNode]}),fe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,t)=>l.$isQuoteNode(e)?{children:e.isShadowRoot()?t.exportChildren(e):t.exportBlocks(e),type:"blockquote"}:null,type:"quote"}],importRules:[{$import:(e,t)=>{const n=l.$createQuoteNode(),o=[];for(const n of e.children)"paragraph"===n.type?(o.length>0&&o.push(O()),o.push(...t.importChildren(n))):o.push(...t.importNode(n));return L(n,o)},type:"blockquote"}]})],name:"@lexical/mdast/Blockquote",nodes:[l.QuoteNode]}),me=/* @__PURE__ */t.defineExtension({dependencies:[pe,fe],name:"@lexical/mdast/RichText"}),he=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,t)=>a.$isListNode(e)?Q(e,t):null,type:"list"}],importRules:[{$import:(e,n)=>{const o=q(e),r=e.ordered&&null!=e.start?e.start:1,i=a.$createListNode(o,r),s=e.children[0],l=n.source&&s&&s.position?s.position.start.offset:void 0;if(null!=l){const e=n.source.slice(l,l+16);if("number"===o){const n=e.match(/^\s*\d+([.)])/),o=n&&n[1];"."!==o&&")"!==o||t.$setState(i,T,o)}else{const n=e.match(/^\s*([-*+])/),o=n&&n[1];"-"!==o&&"*"!==o&&"+"!==o||t.$setState(i,k,o)}}return L(i,e.children.flatMap(e=>n.importNode(e)))},type:"list"},{$import:(e,t)=>{const n=a.$createListItemNode("boolean"==typeof e.checked?e.checked:void 0),o=[];for(const r of e.children)"list"===r.type?o.push(L(a.$createListItemNode(),t.importNode(r))):"paragraph"===r.type?(n.getChildrenSize()>0&&L(n,[O()]),L(n,t.importChildren(r))):L(n,t.importNode(r));return[n,...o]},type:"listItem"}]})],name:"@lexical/mdast/List",nodes:[a.ListNode,a.ListItemNode]}),ge=/* @__PURE__ */t.defineExtension({dependencies:[he,/* @__PURE__ */t.configExtension(ue,{mdastExtensions:[/* @__PURE__ */u.gfmTaskListItemFromMarkdown()],micromarkExtensions:[/* @__PURE__ */m.gfmTaskListItem()],toMarkdownExtensions:[/* @__PURE__ */u.gfmTaskListItemToMarkdown()]})],name:"@lexical/mdast/TaskList"}),xe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:e=>{if(!i.$isCodeNode(e))return null;const n={lang:e.getLanguage()||null,type:"code",value:e.getTextContent()},o=t.$getState(e,C);o&&(n.meta=o);const r=t.$getState(e,E);return r&&(n.data={mdastFence:r}),n},type:"code"}],importRules:[{$import:(e,n)=>{const o=i.$createCodeNode(e.lang||void 0);if(n.source&&e.position&&null!=e.position.start.offset){const r=e.position.start.offset,i=n.source.indexOf("\n",r),s=n.source.slice(r,-1===i?void 0:i).match(/^[ \t]*(`{3,}|~{3,})/);s&&t.$setState(o,E,s[1])}return e.meta&&t.$setState(o,C,e.meta),e.value&&L(o,[t.$createTextNode(e.value)]),o},type:"code"}]})],name:"@lexical/mdast/Code",nodes:[i.CodeNode]}),$e=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o={children:n.exportInline(e),title:e.getTitle()??null,type:"link",url:e.getURL()},r=t.$getState(e,b);return r&&(o.data={mdastLinkStyle:r}),o},type:"link"}],importRules:[{$import:(e,n)=>{const o=L(s.$createLinkNode(e.url,{title:null==e.title?void 0:e.title}),n.importChildren(e));if(n.source&&e.position&&null!=e.position.start.offset){const r=n.source[e.position.start.offset];t.$setState(o,b,"["===r?"inline":"<"===r?"autolink":"literal")}return o},type:"link"},{$import:(e,t)=>{const n=t.getDefinition(e.identifier);if(n)return L(s.$createLinkNode(n.url,{title:null==n.title?void 0:n.title}),t.importChildren(e));const{position:o}=e;return t.source&&o&&null!=o.start.offset?t.createText(t.source.slice(o.start.offset,o.end.offset)):[...t.createText("["),...t.importChildren(e),...t.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]})],name:"@lexical/mdast/Link",nodes:[s.LinkNode]}),ke=/* @__PURE__ */t.defineExtension({dependencies:[$e,/* @__PURE__ */t.configExtension(ue,{mdastExtensions:[/* @__PURE__ */d.gfmAutolinkLiteralFromMarkdown()],micromarkExtensions:[/* @__PURE__ */p.gfmAutolinkLiteral()],toMarkdownExtensions:[/* @__PURE__ */d.gfmAutolinkLiteralToMarkdown()]})],name:"@lexical/mdast/AutolinkLiteral"}),Te=/* @__PURE__ */t.defineExtension({dependencies:[fe,
10
+ /* @__PURE__ */
11
+ t.configExtension(ue,{importRules:[{$import:(e,n)=>L(l.$createQuoteNode({shadowRoot:!0}),function(e,n){const o=[];let r=null;const i=()=>{r&&(o.push(r),r=null)};for(const s of e.children)for(const e of n.importNode(s))v(e)?(i(),o.push(e)):(r||(r=t.$createParagraphNode()),L(r,[e]));return i(),o}(e,n)),type:"blockquote"}]})],name:"@lexical/mdast/ShadowRootQuote"}),Se=/* @__PURE__ */t.defineExtension({dependencies:[e.HorizontalRuleExtension,/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:n=>{if(!e.$isHorizontalRuleNode(n))return null;const o={type:"thematicBreak"},r=t.$getState(n,w);return r&&(o.data={mdastRule:r}),o},type:"horizontalrule"}],importRules:[{$import:(n,o)=>{const r=e.$createHorizontalRuleNode();if(o.source&&n.position&&null!=n.position.start.offset){const e=o.source.slice(n.position.start.offset,n.position.start.offset+4).trimStart()[0];"-"!==e&&"*"!==e&&"_"!==e||t.$setState(r,w,e)}return r},type:"thematicBreak"}]})],name:"@lexical/mdast/HorizontalRule"}),ye=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{importRules:[{$import:(e,t)=>t.importChildren(e,_),type:"delete"}],inlineShortcutTriggers:["~"],inlineShortcutTypes:["delete"],mdastExtensions:[/* @__PURE__ */c.gfmStrikethroughFromMarkdown()],micromarkExtensions:[/* @__PURE__ */f.gfmStrikethrough()],toMarkdownExtensions:[/* @__PURE__ */c.gfmStrikethroughToMarkdown()]})],name:"@lexical/mdast/Strikethrough"}),Ne=/* @__PURE__ */t.defineExtension({dependencies:[me,he,xe,$e,Se],name:"@lexical/mdast/CommonMark"}),Ee=/* @__PURE__ */t.defineExtension({build:(t,n)=>e.namedSignals(n),config:/* @__PURE__ */t.safeCast({disabled:!1}),dependencies:[ue],name:"@lexical/mdast/Shortcuts",register:(t,n,o)=>{const{disabled:r}=o.getOutput();return e.effect(()=>{if(r.value)return;const{registry:n}=e.getExtensionDependencyFromEditor(t,ue).output;return le(t,n)})}});const Ce=/* @__PURE__ */t.defineExtension({build(e,t,n){const{registry:o}=n.getDependency(ue).output,{$exportSelectionToMarkdown:r,$exportToMdast:i,$exportToMarkdown:s}=J(o);return{$convertSelectionToMarkdownString:r,$convertToMarkdownString:s,$convertToMdast:i}},dependencies:[ue],name:"@lexical/mdast/Export"});const Me=/* @__PURE__ */t.defineExtension({dependencies:[ue,Ce],name:"@lexical/mdast/Mdast"}),Re=/* @__PURE__ */t.createState("mdastTableAlign",{parse:e=>Array.isArray(e)?e.map(e=>"center"===e||"left"===e||"right"===e?e:null):[],resetOnCopyNode:!0}),we=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */e.configExtension(ue,{exportRules:[{$export:(e,n)=>{if(!g.$isTableNode(e))return null;const o=[];for(const r of e.getChildren()){if(!g.$isTableRowNode(r)||!n.isIncluded(r))continue;const e=[];for(const o of r.getChildren()){if(!g.$isTableCellNode(o))continue;const r=[];for(const e of o.getChildren())t.$isElementNode(e)&&(r.length>0&&r.push({type:"break"}),r.push(...n.exportInline(e)));e.push({children:r,type:"tableCell"})}o.push({children:e,type:"tableRow"})}return{align:t.$getState(e,Re),children:o,type:"table"}},type:"table"}],importRules:[{$import:(e,n)=>{const o=g.$createTableNode();return e.align&&e.align.some(e=>null!=e)&&t.$setState(o,Re,e.align),e.children.forEach((e,r)=>{const i=g.$createTableRowNode();for(const o of e.children){const e=g.$createTableCellNode(0===r?g.TableCellHeaderStates.ROW:g.TableCellHeaderStates.NO_STATUS),s=t.$createParagraphNode();L(s,n.importChildren(o)),L(e,[s]),L(i,[e])}L(o,[i])}),o},type:"table"}],mdastExtensions:[/* @__PURE__ */x.gfmTableFromMarkdown()],micromarkExtensions:[/* @__PURE__ */$.gfmTable()],toMarkdownExtensions:[/* @__PURE__ */x.gfmTableToMarkdown()]})],name:"@lexical/mdast/Table",nodes:[g.TableNode,g.TableRowNode,g.TableCellNode]}),be=/* @__PURE__ */t.defineExtension({dependencies:[ye,ge,ke,we],name:"@lexical/mdast/Gfm"});exports.$convertFromMarkdownString=function(t,n){e.$getExtensionOutput(ue).$convertFromMarkdownString(t,n)},exports.$convertFromMdast=function(t,n){e.$getExtensionOutput(ue).$convertFromMdast(t,n)},exports.$convertSelectionToMarkdownString=function(t){return e.$getExtensionOutput(Ce).$convertSelectionToMarkdownString(t)},exports.$convertToMarkdownString=function(t){return e.$getExtensionOutput(Ce).$convertToMarkdownString(t)},exports.$convertToMdast=function(t){return e.$getExtensionOutput(Ce).$convertToMdast(t)},exports.$generateNodesFromMarkdownString=function(t){return e.$getExtensionOutput(ue).$generateNodesFromMarkdownString(t)},exports.$generateNodesFromMdast=function(t){return e.$getExtensionOutput(ue).$generateNodesFromMdast(t)},exports.MdastAutolinkLiteralExtension=ke,exports.MdastBlockquoteExtension=fe,exports.MdastCodeExtension=xe,exports.MdastCommonMarkExtension=Ne,exports.MdastExportExtension=Ce,exports.MdastExtension=Me,exports.MdastGfmExtension=be,exports.MdastHeadingExtension=pe,exports.MdastHorizontalRuleExtension=Se,exports.MdastImportExtension=ue,exports.MdastLinkExtension=$e,exports.MdastListExtension=he,exports.MdastRichTextExtension=me,exports.MdastShadowRootQuoteExtension=Te,exports.MdastShortcutsExtension=Ee,exports.MdastStrikethroughExtension=ye,exports.MdastTableExtension=we,exports.MdastTaskListExtension=ge;
@@ -0,0 +1,11 @@
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
+ import{HorizontalRuleExtension as t,effect as e,getExtensionDependencyFromEditor as n,namedSignals as r,$getExtensionOutput as o,$createHorizontalRuleNode as i,$isHorizontalRuleNode as s,configExtension as l}from"@lexical/extension";import{createState as a,$createParagraphNode as c,$setState as d,$createLineBreakNode as u,$isParagraphNode as p,$isTextNode as m,$isLineBreakNode as f,$getState as h,$isTabNode as g,$createTextNode as x,TEXT_TYPE_TO_FORMAT as k,$isElementNode as y,$isDecoratorNode as C,$getRoot as $,$isRangeSelection as T,$getSelection as S,tokenizeRawText as M,$createTabNode as v,mergeRegister as b,COLLABORATION_TAG as w,HISTORIC_TAG as E,COMPOSITION_END_TAG as R,$getNodeByKey as N,$addUpdateTag as I,HISTORY_PUSH_TAG as L,KEY_ENTER_COMMAND as F,COMMAND_PRIORITY_BEFORE_EDITOR as O,$isRootOrShadowRoot as B,defineExtension as _,shallowMergeConfig as A,safeCast as H,configExtension as q}from"lexical";import{$sliceSelectedTextNodeContent as z}from"@lexical/selection";import{toMarkdown as P,defaultHandlers as D}from"mdast-util-to-markdown";import{toString as U}from"mdast-util-to-string";import{$createCodeNode as j,$isCodeNode as G,CodeNode as K}from"@lexical/code-core";import{$createLinkNode as Q,$isLinkNode as W,$isAutoLinkNode as X,LinkNode as J}from"@lexical/link";import{$createListNode as V,$createListItemNode as Y,$isListNode as Z,$isListItemNode as tt,ListNode as et,ListItemNode as nt}from"@lexical/list";import{$createHeadingNode as rt,$isHeadingNode as ot,$createQuoteNode as it,$isQuoteNode as st,HeadingNode as lt,QuoteNode as at}from"@lexical/rich-text";import{gfmAutolinkLiteralToMarkdown as ct,gfmAutolinkLiteralFromMarkdown as dt}from"mdast-util-gfm-autolink-literal";import{gfmStrikethroughToMarkdown as ut,gfmStrikethroughFromMarkdown as pt}from"mdast-util-gfm-strikethrough";import{gfmTaskListItemToMarkdown as mt,gfmTaskListItemFromMarkdown as ft}from"mdast-util-gfm-task-list-item";import{gfmAutolinkLiteral as ht}from"micromark-extension-gfm-autolink-literal";import{gfmStrikethrough as gt}from"micromark-extension-gfm-strikethrough";import{gfmTaskListItem as xt}from"micromark-extension-gfm-task-list-item";import{fromMarkdown as kt}from"mdast-util-from-markdown";import{TableNode as yt,TableRowNode as Ct,TableCellNode as $t,$createTableNode as Tt,$createTableRowNode as St,$createTableCellNode as Mt,TableCellHeaderStates as vt,$isTableNode as bt,$isTableRowNode as wt,$isTableCellNode as Et}from"@lexical/table";import{gfmTableToMarkdown as Rt,gfmTableFromMarkdown as Nt}from"mdast-util-gfm-table";import{gfmTable as It}from"micromark-extension-gfm-table";const Lt=/* @__PURE__ */a("mdastListMarker",{parse:t=>"-"===t||"*"===t||"+"===t?t:"",resetOnCopyNode:!0}),Ft=/* @__PURE__ */a("mdastOrderedMarker",{parse:t=>"."===t||")"===t?t:"",resetOnCopyNode:!0}),Ot=/* @__PURE__ */a("mdastEmphasisMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),Bt=/* @__PURE__ */a("mdastStrongMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),_t=/* @__PURE__ */a("mdastSetext",{parse:t=>!0===t,resetOnCopyNode:!0}),At=/* @__PURE__ */a("mdastCodeFence",{parse:t=>"string"==typeof t&&/^(`{3,}|~{3,})$/.test(t)?t:"",resetOnCopyNode:!0}),Ht=/* @__PURE__ */a("mdastCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),qt=/* @__PURE__ */a("mdastHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0}),zt=/* @__PURE__ */a("mdastParagraphBreak",{parse:t=>!0===t,resetOnCopyNode:!0}),Pt=/* @__PURE__ */a("mdastHrMarker",{parse:t=>"-"===t||"*"===t||"_"===t?t:"",resetOnCopyNode:!0}),Dt=/* @__PURE__ */a("mdastLinkStyle",{parse:t=>"inline"===t||"autolink"===t||"literal"===t?t:"",resetOnCopyNode:!0});function Ut(t,e){return t.splice(t.getChildrenSize(),0,e)}function jt(t){return(y(t)||C(t))&&!t.isInline()}function Gt(){return d(u(),zt,!0)}const Kt=k.bold,Qt=k.italic,Wt=k.strikethrough,Xt=k.code,Jt=Kt|Qt|Wt|Xt;function Vt(t){if(t.ordered)return"number";for(const e of t.children)if("listItem"===e.type&&null!=e.checked)return"check";return"bullet"}function Yt(t,e){return(n,r)=>{const o=r.importChildren(n,t);if("_"===function(t,e){if(t.source&&e.position&&null!=e.position.start.offset)return t.source[e.position.start.offset]}(r,n))for(const t of o)m(t)&&d(t,e,"_");return o}}const Zt=/* @__PURE__ */Yt(Qt,Ot),te=/* @__PURE__ */Yt(Kt,Bt),ee={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function ne(t,e){const n=t.getListType(),r={children:[],ordered:"number"===n,spread:!1,start:"number"===n?t.getStart():void 0,type:"list"};if("number"===n){const e=h(t,Ft);e&&(r.data={mdastBulletOrdered:e})}else{const e=h(t,Lt);e&&(r.data={mdastBullet:e})}let o=null;for(const i of t.getChildren()){if(!tt(i)||!e.isIncluded(i))continue;const t=i.getFirstChild();if(1===i.getChildrenSize()&&Z(t)){const n=ne(t,e);o?o.children.push(n):r.children.push({children:[n],spread:!1,type:"listItem"});continue}const s={checked:"check"===n?i.getChecked()??!1:null,children:e.exportBlocks(i),spread:!1,type:"listItem"};r.children.push(s),o=s}return r}function re(t,e){let n=e&Xt?{type:"inlineCode",value:t}:{type:"text",value:t};return e&Qt&&(n={children:[n],type:"emphasis"}),e&Kt&&(n={children:[n],type:"strong"}),e&Wt&&(n={children:[n],type:"delete"}),n}const oe=t=>m(t)?re(t.getTextContent(),t.getFormat()&Jt):null,ie=t=>f(t)?{data:{mdastBreak:h(t,qt)},type:"break"}:null;function se(t,e,n){const{options:r}=t,o={};for(const t of Object.keys(e))o[t]=r[t],r[t]=e[t];try{return n()}finally{for(const t of Object.keys(o))r[t]=o[t]}}const le={handlers:{break(t,e,n,r){const o=D.break(t,e,n,r);if("\\\n"!==o)return o;const i=t.data&&t.data.mdastBreak;return i?/^ {2,}$/.test(i)?`${i}\n`:o:"\n"},code(t,e,n,r){const o=t.data&&t.data.mdastFence;return o?se(n,{fence:"~"===o[0]?"~":"`",fences:!0},()=>D.code(t,e,n,r)):D.code(t,e,n,r)},heading:(t,e,n,r)=>t.data&&!0===t.data.mdastSetext?se(n,{setext:!0},()=>D.heading(t,e,n,r)):D.heading(t,e,n,r),link(t,e,n,r){const o=t.data&&t.data.mdastLinkStyle;return"literal"===o&&null==t.title?U(t):"inline"===o?se(n,{resourceLink:!0},()=>D.link(t,e,n,r)):D.link(t,e,n,r)},list(t,e,n,r){if(t.ordered){const o=t.data&&t.data.mdastBulletOrdered;return null==o?D.list(t,e,n,r):se(n,{bulletOrdered:o},()=>D.list(t,e,n,r))}const o=t.data&&t.data.mdastBullet;return null==o?D.list(t,e,n,r):se(n,{bullet:o,bulletOther:"-"===o?"*":"-"},()=>D.list(t,e,n,r))},thematicBreak(t,e,n){const r=t.data&&t.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?D.thematicBreak(t,e,n):se(n,{rule:r},()=>D.thematicBreak(t,e,n))}}};class ae{format=-1;value="";push(t,e){if(!m(t))return!1;const n=t.getFormat()&Jt;return n===this.format?this.value+=t.getTextContent():(this.flushInto(e),this.format=n,this.value=t.getTextContent()),!0}flushInto(t){this.format>=0&&t.push(re(this.value,this.format)),this.format=-1,this.value=""}}function ce(t,e=null){const{exportHandlers:n}=t;let r=0;function o(t){const e=n.get(t.getType());return void 0===e||e===oe}function i(t){return null===e||y(t)?t:t.isSelected(e)?(r++,m(t)?z(e,t,"clone"):t):null}function s(t,n){const o=null!==e&&t.isSelected(e);o&&r++;const i=r,s=a(t);(null===e||o||r>i)&&n.push(...s)}const l={exportBlocks:t=>function(t){const e=[];let n=[];const r=new ae,l=()=>{r.flushInto(n),n.length>0&&(e.push({children:n,type:"paragraph"}),n=[])};for(const c of t.getChildren()){const t=i(c);if(null!==t)if(f(t)){const e=ie(t);h(t,zt)||null===e?l():(r.flushInto(n),n.push(e))}else{if(o(t)&&r.push(t,n))continue;jt(t)?(l(),y(t)?s(t,e):e.push(...a(t))):y(t)?(r.flushInto(n),s(t,n)):(r.flushInto(n),n.push(...a(t)))}}l(),0===e.length&&e.push({children:[],type:"paragraph"});return e}(t),exportChildren:t=>{const e=[];for(const n of t.getChildren()){const t=i(n);null!==t&&(y(t)?s(t,e):e.push(...a(t)))}return e},exportInline:t=>function(t){const e=[],n=new ae;for(const r of t.getChildren()){const t=i(r);null!==t&&(o(t)&&n.push(t,e)||(n.flushInto(e),y(t)?s(t,e):e.push(...a(t))))}return n.flushInto(e),e}(t),isIncluded:function t(n){if(null===e||n.isSelected(e))return!0;if(y(n))for(const e of n.getChildren())if(t(e))return!0;return!1}};function a(t){const e=n.get(t.getType());if(e){const n=e(t,l);if(null!=n)return Array.isArray(n)?n:[n]}const r=oe(t);if(null!==r)return[r];const o=ie(t);if(null!==o)return[o];if(y(t))return l.exportChildren(t);const i=t.getTextContent();return i?[{type:"text",value:i}]:[]}return{exportChildren:l.exportChildren}}function de(t){const e=ce(t),n=(t,e)=>({children:e.exportChildren(t),type:"root"}),r=(e,n)=>{const{emphasis:r,strong:o}=function(t){let e,n;const r=t=>{for(const o of t.getChildren())if(m(o)?(void 0===e&&o.hasFormat("italic")&&"_"===h(o,Ot)&&(e="_"),void 0===n&&o.hasFormat("bold")&&"_"===h(o,Bt)&&(n="_")):y(o)&&r(o),void 0!==e&&void 0!==n)return};return r(t),{emphasis:e,strong:n}}(n),i={bullet:"-"};r&&(i.emphasis=r),o&&(i.strong=o);return P(e,{extensions:[i,...t.toMarkdownExtensions,le]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(e=S())=>{if(null===e||T(e)&&e.isCollapsed())return"";const o=$();return r(n(o,ce(t,e)),o)},$exportToMarkdown:t=>{const o=t||$();return r(n(o,e),o)},$exportToMdast:t=>n(t||$(),e)}}function ue(t,e){const n=[];return M(t,{linebreak:()=>n.push(u()),tab:()=>n.push(v()),text:t=>{const r=x(t);e&&r.setFormat(e),n.push(r)}}),n}const pe=new Map;function me(t,e="",n=pe){const{importHandlers:r}=t,o=new Map;function i(t,l){const a=r.get(t.type);if(a){const r=a(t,function(t){let r=o.get(t);return void 0===r&&(r={createText:(e,n)=>ue(e,null==n?t:n),format:t,getDefinition:t=>n.get(t),importChildren:(e,n)=>s(e,t|(n||0)),importNode:(e,n)=>i(e,t|(n||0)),source:e},o.set(t,r)),r}(l));return null==r?[]:Array.isArray(r)?r:[r]}return"children"in t?s(t,l):"value"in t&&"string"==typeof t.value?ue(t.value,l):[]}function s(t,e){const n=[];for(const r of t.children)n.push(...i(r,e));return n}return{$importChildren:s,$importNode:i}}function fe(t){const e=(e,n)=>{const{$importNode:r}=me(t,n,function(t){const e=new Map,n=t=>{if("definition"===t.type&&(e.has(t.identifier)||e.set(t.identifier,{title:t.title,url:t.url})),"children"in t)for(const e of t.children)n(e)};return n(t),e}(e)),o=[];let i=null;const s=()=>{i&&(o.push(i),i=null)};for(const t of e.children)for(const e of r(t,0))jt(e)?(s(),o.push(e)):(i||(i=c()),Ut(i,[e]));return s(),o},n=n=>e(kt(n,{extensions:t.micromarkExtensions,mdastExtensions:t.mdastExtensions}),n),r=t=>e(t,""),o=(t,e)=>{const n=e||$();var r,o;n.clear(),r=n,o=t.length>0?t:[c()],r.splice(0,0,o),null!==S()&&n.selectStart()};return{$generateNodesFromMarkdown:n,$generateNodesFromMdast:r,$importMarkdown:(t,e)=>o(n(t),e),$importMdast:(t,e)=>o(r(t),e)}}function he(t,e){let n=t;for(;;){if("heading"===n.type||"paragraph"===n.type){const t=n.children[0];return t&&t.position&&null!=t.position.start.offset?t.position.start.offset:e.length}if(!("children"in n)||0===n.children.length)return e.length;n=n.children[0]}}class ge{compiled;importNode;supportsTaskListItems;constructor(t){this.compiled=t,this.importNode=me(t,"").$importNode;const e=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=e&&"list"===e.type&&!0===e.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(t){return kt(t,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(t){return this.importNode(t,0)}scanBlock(t){if(""===t.trim())return null;const e=this.parse(t).children[0];if(!e||!this.compiled.importHandlers.has(e.type))return null;switch(e.type){case"heading":return{kind:"heading",markerLength:he(e,t),node:e};case"blockquote":return{kind:"blockquote",markerLength:he(e,t),node:e};case"list":return{kind:"list",markerLength:he(e,t),node:e};case"code":return{kind:"code",markerLength:t.length,node:e};default:return null}}scanInline(t){if(0===t.length)return null;const e=this.parse(t),n=e.children[e.children.length-1];if(!n||"paragraph"!==n.type)return null;const r=n.children[n.children.length-1];if(!r||!r.position||r.position.end.offset!==t.length||!this.compiled.inlineShortcutTypes.has(r.type))return null;const o=r.position.start.offset??0,i=t[o];return o>0&&t[o-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:r}}function xe(t,e){let n=e,r=t.getFirstChild();for(;n>0&&r&&m(r);){const t=r.getTextContent();if(t.length<=n){const e=r.getNextSibling();n-=t.length,r.remove(),r=e}else r.setTextContent(t.slice(n)),n=0}}function ke(t,e){const n="code"===e.kind?t.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;xe(t,e.markerLength);const r=t.getChildren();if("code"===e.kind){const o=j(e.node.lang||void 0);return n&&d(o,At,n[1]),e.node.meta&&d(o,Ht,e.node.meta),Ut(o,r),t.replace(o),o.selectStart(),!0}let o,i;if("heading"===e.kind){const t=Ut(rt(`h${e.node.depth}`),r);o=t,i=t}else if("blockquote"===e.kind){const t=Ut(it(),r);o=t,i=t}else{const t=e.node,n=Vt(t),s=t.ordered&&null!=t.start?t.start:1,l=V(n,s),a=t.children[0],c=a&&"listItem"===a.type&&"boolean"==typeof a.checked?a.checked:void 0,d=Ut(Y(c),r);Ut(l,[d]),o=l,i=d}return t.replace(o),i.selectStart(),!0}const ye=/^\[([ xX])\]\s$/;function Ce(t,e){return p(t)&&B(t.getParent())&&t.getFirstChild()===e}function $e(t,e){const n=new ge(e),r=n.inlineTriggers,o=new Set([" ",...r]);return b(t.registerUpdateListener(({tags:e,dirtyLeaves:i,editorState:s,prevEditorState:l})=>{if(0===i.size||e.has(w)||e.has(E))return;if(t.isComposing())return;const a=e.has(R),c=s.read(S),d=l.read(S);if(!T(c)||!T(d)||!c.isCollapsed()||c.is(d)&&!a)return;const u=c.anchor.key,p=c.anchor.offset,f=s._nodeMap.get(u);if(!m(f)||!i.has(u))return;if(!a&&1!==p&&(d.anchor.key!==u||p!==d.anchor.offset+1))return;const h=s.read(()=>f.getTextContent()),g=h[p-1];var x,k;a&&!o.has(g)||(" "===g||r.has(g))&&(" "===g||(x=h.slice(0,p),")"===(k=g)?x.lastIndexOf("](")>0:-1!==x.lastIndexOf(k,x.length-2)))&&t.update(()=>{const t=N(u);if(!m(t)||t.hasFormat("code"))return;const e=t.getParent();if(null===e||G(e))return;let r=!1;if(" "===g){if(n.supportsTaskListItems&&function(t,e,n){if(e.getFirstChild()!==t)return!1;const r=e.getTextContent().slice(0,n).match(ye);if(!r)return!1;const o="x"===r[1].toLowerCase();if(tt(e)){const t=e.getParent();return!(!Z(t)||"number"===t.getListType()||(xe(e,r[0].length),t.setListType("check"),e.setChecked(o),0))}if(Ce(e,t)){xe(e,r[0].length);const t=e.getChildren(),n=V("check"),i=Ut(Y(o),t);return Ut(n,[i]),e.replace(n),i.selectStart(),!0}return!1}(t,e,p))r=!0;else if(p<=24&&Ce(e,t)){const o=n.scanBlock(t.getTextContent().slice(0,p));o&&"code"!==o.kind&&o.markerLength===p&&(r=ke(e,o))}}else r=function(t,e,n){const r=t.getTextContent().slice(0,e),o=n.scanInline(r);if(!o||!o.position)return!1;const i=o.position.start.offset??0,s=e;let l;if(i<=0)[l]=t.splitText(s);else{const e=t.splitText(i,s);l=3===e.length?e[1]:e[e.length-1]}const a=n.importInline(o);if(0===a.length)return!1;let c=a[0];l.replace(c);for(let t=1;t<a.length;t++)c.insertAfter(a[t]),c=a[t];if(m(c)){const t=c.getTextContentSize();c.select(t,t)}else c.selectNext(0,0);return!0}(t,p,n);r&&I(L)})}),t.registerCommand(F,t=>{if(null!==t&&t.shiftKey)return!1;const e=S();if(!T(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!m(r)||r.hasFormat("code"))return!1;const o=r.getParent(),i=e.anchor.offset;if(null===o||G(o)||!Ce(o,r)||i!==r.getTextContentSize())return!1;const s=n.scanBlock(o.getTextContent());return!(!s||s.markerLength!==i||!ke(o,s))&&(null!==t&&t.preventDefault(),!0)},O))}const Te=[{$import:(t,e)=>Ut(c(),e.importChildren(t)),type:"paragraph"},{$import:(t,e)=>e.createText(t.value),type:"text"},{$import:(t,e)=>e.createText(t.value),type:"html"},{$import:(t,e)=>e.createText(t.value,e.format|Xt),type:"inlineCode"},{$import:Zt,type:"emphasis"},{$import:te,type:"strong"},{$import:(t,e)=>{let n="\\";if(e.source&&t.position){const{start:r,end:o}=t.position;if(null!=r.offset&&null!=o.offset){const t=e.source.slice(r.offset,o.offset).replace(/\n$/,"");/^ {2,}$/.test(t)&&(n=t)}}return[d(u(),qt,n)]},type:"break"}],Se=[{$export:(t,e)=>p(t)?{children:e.exportInline(t),type:"paragraph"}:null,type:"paragraph"},{$export:oe,type:"text"},{$export:ie,type:"linebreak"},{$export:t=>g(t)?{type:"text",value:"\t"}:null,type:"tab"}],Me=/* @__PURE__ */_({build(t,e){const n=function(t){const e=new Map,n=new Map;for(const n of t.importRules)e.has(n.type)||e.set(n.type,n.$import);for(const e of t.exportRules)n.has(e.type)||n.set(e.type,e.$export);return{exportHandlers:n,importHandlers:e,inlineShortcutTriggers:new Set(t.inlineShortcutTriggers),inlineShortcutTypes:new Set(t.inlineShortcutTypes),mdastExtensions:[...t.mdastExtensions],micromarkExtensions:[...t.micromarkExtensions],toMarkdownExtensions:[...t.toMarkdownExtensions]}}(e),{$generateNodesFromMarkdown:r,$generateNodesFromMdast:o,$importMarkdown:i,$importMdast:s}=fe(n);return{$convertFromMarkdownString:i,$convertFromMdast:s,$generateNodesFromMarkdownString:r,$generateNodesFromMdast:o,registry:n}},config:/* @__PURE__ */H({exportRules:Se,importRules:Te,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]}),mergeConfig(t,e){function n(t,e){return t?[...t,...e]:e}return A(t,{exportRules:n(e.exportRules,t.exportRules),importRules:n(e.importRules,t.importRules),inlineShortcutTriggers:n(e.inlineShortcutTriggers,t.inlineShortcutTriggers),inlineShortcutTypes:n(e.inlineShortcutTypes,t.inlineShortcutTypes),mdastExtensions:n(e.mdastExtensions,t.mdastExtensions),micromarkExtensions:n(e.micromarkExtensions,t.micromarkExtensions),toMarkdownExtensions:n(e.toMarkdownExtensions,t.toMarkdownExtensions)})},name:"@lexical/mdast/Import"}),ve=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>{if(!ot(t))return null;const n={children:e.exportInline(t),depth:ee[t.getTag()],type:"heading"};return h(t,_t)&&(n.data={mdastSetext:!0}),n},type:"heading"}],importRules:[{$import:(t,e)=>{const n=rt(`h${t.depth}`);if(e.source&&t.position&&(1===t.depth||2===t.depth)){const r=t.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(e.source.slice(r,r+10))||d(n,_t,!0)}return Ut(n,e.importChildren(t))},type:"heading"}]})],name:"@lexical/mdast/Heading",nodes:[lt]}),be=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>st(t)?{children:t.isShadowRoot()?e.exportChildren(t):e.exportBlocks(t),type:"blockquote"}:null,type:"quote"}],importRules:[{$import:(t,e)=>{const n=it(),r=[];for(const n of t.children)"paragraph"===n.type?(r.length>0&&r.push(Gt()),r.push(...e.importChildren(n))):r.push(...e.importNode(n));return Ut(n,r)},type:"blockquote"}]})],name:"@lexical/mdast/Blockquote",nodes:[at]}),we=/* @__PURE__ */_({dependencies:[ve,be],name:"@lexical/mdast/RichText"}),Ee=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>Z(t)?ne(t,e):null,type:"list"}],importRules:[{$import:(t,e)=>{const n=Vt(t),r=t.ordered&&null!=t.start?t.start:1,o=V(n,r),i=t.children[0],s=e.source&&i&&i.position?i.position.start.offset:void 0;if(null!=s){const t=e.source.slice(s,s+16);if("number"===n){const e=t.match(/^\s*\d+([.)])/),n=e&&e[1];"."!==n&&")"!==n||d(o,Ft,n)}else{const e=t.match(/^\s*([-*+])/),n=e&&e[1];"-"!==n&&"*"!==n&&"+"!==n||d(o,Lt,n)}}return Ut(o,t.children.flatMap(t=>e.importNode(t)))},type:"list"},{$import:(t,e)=>{const n=Y("boolean"==typeof t.checked?t.checked:void 0),r=[];for(const o of t.children)"list"===o.type?r.push(Ut(Y(),e.importNode(o))):"paragraph"===o.type?(n.getChildrenSize()>0&&Ut(n,[Gt()]),Ut(n,e.importChildren(o))):Ut(n,e.importNode(o));return[n,...r]},type:"listItem"}]})],name:"@lexical/mdast/List",nodes:[et,nt]}),Re=/* @__PURE__ */_({dependencies:[Ee,/* @__PURE__ */q(Me,{mdastExtensions:[/* @__PURE__ */ft()],micromarkExtensions:[/* @__PURE__ */xt()],toMarkdownExtensions:[/* @__PURE__ */mt()]})],name:"@lexical/mdast/TaskList"}),Ne=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:t=>{if(!G(t))return null;const e={lang:t.getLanguage()||null,type:"code",value:t.getTextContent()},n=h(t,Ht);n&&(e.meta=n);const r=h(t,At);return r&&(e.data={mdastFence:r}),e},type:"code"}],importRules:[{$import:(t,e)=>{const n=j(t.lang||void 0);if(e.source&&t.position&&null!=t.position.start.offset){const r=t.position.start.offset,o=e.source.indexOf("\n",r),i=e.source.slice(r,-1===o?void 0:o).match(/^[ \t]*(`{3,}|~{3,})/);i&&d(n,At,i[1])}return t.meta&&d(n,Ht,t.meta),t.value&&Ut(n,[x(t.value)]),n},type:"code"}]})],name:"@lexical/mdast/Code",nodes:[K]}),Ie=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>{if(!W(t)||X(t))return null;const n={children:e.exportInline(t),title:t.getTitle()??null,type:"link",url:t.getURL()},r=h(t,Dt);return r&&(n.data={mdastLinkStyle:r}),n},type:"link"}],importRules:[{$import:(t,e)=>{const n=Ut(Q(t.url,{title:null==t.title?void 0:t.title}),e.importChildren(t));if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source[t.position.start.offset];d(n,Dt,"["===r?"inline":"<"===r?"autolink":"literal")}return n},type:"link"},{$import:(t,e)=>{const n=e.getDefinition(t.identifier);if(n)return Ut(Q(n.url,{title:null==n.title?void 0:n.title}),e.importChildren(t));const{position:r}=t;return e.source&&r&&null!=r.start.offset?e.createText(e.source.slice(r.start.offset,r.end.offset)):[...e.createText("["),...e.importChildren(t),...e.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]})],name:"@lexical/mdast/Link",nodes:[J]}),Le=/* @__PURE__ */_({dependencies:[Ie,/* @__PURE__ */q(Me,{mdastExtensions:[/* @__PURE__ */dt()],micromarkExtensions:[/* @__PURE__ */ht()],toMarkdownExtensions:[/* @__PURE__ */ct()]})],name:"@lexical/mdast/AutolinkLiteral"}),Fe=/* @__PURE__ */_({dependencies:[be,
10
+ /* @__PURE__ */
11
+ q(Me,{importRules:[{$import:(t,e)=>Ut(it({shadowRoot:!0}),function(t,e){const n=[];let r=null;const o=()=>{r&&(n.push(r),r=null)};for(const i of t.children)for(const t of e.importNode(i))jt(t)?(o(),n.push(t)):(r||(r=c()),Ut(r,[t]));return o(),n}(t,e)),type:"blockquote"}]})],name:"@lexical/mdast/ShadowRootQuote"}),Oe=/* @__PURE__ */_({dependencies:[t,/* @__PURE__ */q(Me,{exportRules:[{$export:t=>{if(!s(t))return null;const e={type:"thematicBreak"},n=h(t,Pt);return n&&(e.data={mdastRule:n}),e},type:"horizontalrule"}],importRules:[{$import:(t,e)=>{const n=i();if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source.slice(t.position.start.offset,t.position.start.offset+4).trimStart()[0];"-"!==r&&"*"!==r&&"_"!==r||d(n,Pt,r)}return n},type:"thematicBreak"}]})],name:"@lexical/mdast/HorizontalRule"}),Be=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{importRules:[{$import:(t,e)=>e.importChildren(t,Wt),type:"delete"}],inlineShortcutTriggers:["~"],inlineShortcutTypes:["delete"],mdastExtensions:[/* @__PURE__ */pt()],micromarkExtensions:[/* @__PURE__ */gt()],toMarkdownExtensions:[/* @__PURE__ */ut()]})],name:"@lexical/mdast/Strikethrough"}),_e=/* @__PURE__ */_({dependencies:[we,Ee,Ne,Ie,Oe],name:"@lexical/mdast/CommonMark"}),Ae=/* @__PURE__ */_({build:(t,e)=>r(e),config:/* @__PURE__ */H({disabled:!1}),dependencies:[Me],name:"@lexical/mdast/Shortcuts",register:(t,r,o)=>{const{disabled:i}=o.getOutput();return e(()=>{if(i.value)return;const{registry:e}=n(t,Me).output;return $e(t,e)})}});function He(t,e){o(Me).$convertFromMarkdownString(t,e)}function qe(t,e){o(Me).$convertFromMdast(t,e)}function ze(t){return o(Me).$generateNodesFromMarkdownString(t)}function Pe(t){return o(Me).$generateNodesFromMdast(t)}const De=/* @__PURE__ */_({build(t,e,n){const{registry:r}=n.getDependency(Me).output,{$exportSelectionToMarkdown:o,$exportToMdast:i,$exportToMarkdown:s}=de(r);return{$convertSelectionToMarkdownString:o,$convertToMarkdownString:s,$convertToMdast:i}},dependencies:[Me],name:"@lexical/mdast/Export"});function Ue(t){return o(De).$convertToMarkdownString(t)}function je(t){return o(De).$convertToMdast(t)}function Ge(t){return o(De).$convertSelectionToMarkdownString(t)}const Ke=/* @__PURE__ */_({dependencies:[Me,De],name:"@lexical/mdast/Mdast"}),Qe=/* @__PURE__ */a("mdastTableAlign",{parse:t=>Array.isArray(t)?t.map(t=>"center"===t||"left"===t||"right"===t?t:null):[],resetOnCopyNode:!0}),We=/* @__PURE__ */_({dependencies:[/* @__PURE__ */l(Me,{exportRules:[{$export:(t,e)=>{if(!bt(t))return null;const n=[];for(const r of t.getChildren()){if(!wt(r)||!e.isIncluded(r))continue;const t=[];for(const n of r.getChildren()){if(!Et(n))continue;const r=[];for(const t of n.getChildren())y(t)&&(r.length>0&&r.push({type:"break"}),r.push(...e.exportInline(t)));t.push({children:r,type:"tableCell"})}n.push({children:t,type:"tableRow"})}return{align:h(t,Qe),children:n,type:"table"}},type:"table"}],importRules:[{$import:(t,e)=>{const n=Tt();return t.align&&t.align.some(t=>null!=t)&&d(n,Qe,t.align),t.children.forEach((t,r)=>{const o=St();for(const n of t.children){const t=Mt(0===r?vt.ROW:vt.NO_STATUS),i=c();Ut(i,e.importChildren(n)),Ut(t,[i]),Ut(o,[t])}Ut(n,[o])}),n},type:"table"}],mdastExtensions:[/* @__PURE__ */Nt()],micromarkExtensions:[/* @__PURE__ */It()],toMarkdownExtensions:[/* @__PURE__ */Rt()]})],name:"@lexical/mdast/Table",nodes:[yt,Ct,$t]}),Xe=/* @__PURE__ */_({dependencies:[Be,Re,Le,We],name:"@lexical/mdast/Gfm"});export{He as $convertFromMarkdownString,qe as $convertFromMdast,Ge as $convertSelectionToMarkdownString,Ue as $convertToMarkdownString,je as $convertToMdast,ze as $generateNodesFromMarkdownString,Pe as $generateNodesFromMdast,Le as MdastAutolinkLiteralExtension,be as MdastBlockquoteExtension,Ne as MdastCodeExtension,_e as MdastCommonMarkExtension,De as MdastExportExtension,Ke as MdastExtension,Xe as MdastGfmExtension,ve as MdastHeadingExtension,Oe as MdastHorizontalRuleExtension,Me as MdastImportExtension,Ie as MdastLinkExtension,Ee as MdastListExtension,we as MdastRichTextExtension,Fe as MdastShadowRootQuoteExtension,Ae as MdastShortcutsExtension,Be as MdastStrikethroughExtension,We as MdastTableExtension,Re as MdastTaskListExtension};
@@ -0,0 +1,20 @@
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 { CompiledMdast } from './types';
9
+ import type { BaseSelection, ElementNode } from 'lexical';
10
+ import type { Root } from 'mdast';
11
+ /**
12
+ * Creates a reusable exporter that converts the Lexical tree rooted at the
13
+ * supplied element (or the editor root) — or just the selected content —
14
+ * into a Markdown string.
15
+ */
16
+ export declare function createMdastExport(compiled: CompiledMdast): {
17
+ $exportToMdast: (node?: ElementNode) => Root;
18
+ $exportToMarkdown: (node?: ElementNode) => string;
19
+ $exportSelectionToMarkdown: (selection?: BaseSelection | null) => string;
20
+ };
@@ -0,0 +1,80 @@
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 { BaseSelection, ElementNode } from 'lexical';
9
+ import type { Root } from 'mdast';
10
+ /**
11
+ * The runtime API exposed by {@link MdastExportExtension}. Obtain it inside a
12
+ * read/update with `$getExtensionOutput(MdastExportExtension)`, or use the
13
+ * {@link $convertToMarkdownString} shorthand.
14
+ * @experimental
15
+ */
16
+ export interface MdastExportExtensionOutput {
17
+ /**
18
+ * Serializes the editor root (or `node`) to a Markdown string. Must be
19
+ * called inside an `editor.read()` or `editor.update()`.
20
+ */
21
+ $convertToMarkdownString(node?: ElementNode): string;
22
+ /**
23
+ * Exports the editor root (or `node`) to an mdast `Root` tree without
24
+ * serializing it, for interop with the unified/remark ecosystem (remark
25
+ * plugins, `remark-rehype`, tree diffing, ...). Must be called inside an
26
+ * `editor.read()` or `editor.update()`. Syntax preserved from import
27
+ * rides along as `data` fields on the nodes, mdast's sanctioned
28
+ * extension point.
29
+ */
30
+ $convertToMdast(node?: ElementNode): Root;
31
+ /**
32
+ * Serializes only the selected content (defaulting to the current
33
+ * selection) to a Markdown string: leaves outside the selection are
34
+ * skipped, partially selected text nodes are sliced to the selected
35
+ * range, and elements are kept when they or any descendant are selected.
36
+ * Returns `''` for a null or collapsed selection. Must be called inside
37
+ * an `editor.read()` or `editor.update()`.
38
+ */
39
+ $convertSelectionToMarkdownString(selection?: BaseSelection | null): string;
40
+ }
41
+ /**
42
+ * Markdown serialization for `@lexical/mdast`. Import
43
+ * (`MdastImportExtension` and the feature extensions that contribute to it) and
44
+ * export are separate extensions so that editors which only *parse* Markdown
45
+ * — never serialize back — don't bundle `mdast-util-to-markdown`.
46
+ *
47
+ * The export rules themselves are contributed by the same feature extensions
48
+ * that contribute import rules; this extension compiles the shared registry
49
+ * into a serializer:
50
+ * ```ts
51
+ * dependencies: [MdastCommonMarkExtension, MdastExportExtension]
52
+ * ```
53
+ * @experimental
54
+ */
55
+ export declare const MdastExportExtension: import("lexical").LexicalExtension<Record<never, never>, "@lexical/mdast/Export", MdastExportExtensionOutput, void>;
56
+ /**
57
+ * Shorthand for
58
+ * `$getExtensionOutput(MdastExportExtension).$convertToMarkdownString`.
59
+ * Must be called inside an `editor.read()` or `editor.update()`. Throws if
60
+ * the editor was not built with {@link MdastExportExtension}.
61
+ * @experimental
62
+ */
63
+ export declare function $convertToMarkdownString(node?: ElementNode): string;
64
+ /**
65
+ * Shorthand for `$getExtensionOutput(MdastExportExtension).$convertToMdast`.
66
+ * Must be called inside an `editor.read()` or `editor.update()`. Throws if
67
+ * the editor was not built with {@link MdastExportExtension}.
68
+ * @experimental
69
+ */
70
+ export declare function $convertToMdast(node?: ElementNode): Root;
71
+ /**
72
+ * Shorthand for
73
+ * `$getExtensionOutput(MdastExportExtension).$convertSelectionToMarkdownString`.
74
+ * Serializes only the selected content (defaulting to the current selection)
75
+ * to a Markdown string; returns `''` for a null or collapsed selection.
76
+ * Must be called inside an `editor.read()` or `editor.update()`. Throws if
77
+ * the editor was not built with {@link MdastExportExtension}.
78
+ * @experimental
79
+ */
80
+ export declare function $convertSelectionToMarkdownString(selection?: BaseSelection | null): string;
@@ -0,0 +1,21 @@
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
+ * Convenience bundle of {@link MdastImportExtension} and
10
+ * {@link MdastExportExtension}: Markdown parsing *and* serialization.
11
+ *
12
+ * Depend on this when you want both directions without thinking about it:
13
+ * ```ts
14
+ * dependencies: [MdastCommonMarkExtension, MdastExtension]
15
+ * ```
16
+ * Editors that never serialize back to Markdown can skip it (feature
17
+ * extensions already pull in {@link MdastImportExtension}) and avoid
18
+ * bundling the serializer (`mdast-util-to-markdown`).
19
+ * @experimental
20
+ */
21
+ export declare const MdastExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/mdast/Mdast", unknown, unknown>;
@@ -0,0 +1,20 @@
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
+ * Convenience bundle of every GFM extension — strikethrough, task lists,
10
+ * literal autolinks, and tables — mirroring the scope of
11
+ * `micromark-extension-gfm`. Combine with `MdastCommonMarkExtension` for
12
+ * GitHub-flavored Markdown:
13
+ * ```ts
14
+ * dependencies: [MdastCommonMarkExtension, MdastGfmExtension]
15
+ * ```
16
+ * Each member is also usable individually when you only want some of GFM
17
+ * (e.g. task lists without tables).
18
+ * @experimental
19
+ */
20
+ export declare const MdastGfmExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/mdast/Gfm", unknown, unknown>;