@lofcz/platejs-markdown 52.3.5 → 52.3.6

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/dist/index.d.ts CHANGED
@@ -1,109 +1,15 @@
1
- import { Descendant as Descendant$1, NodeKey, Nullable, OmitFirst, PluginConfig, SlateEditor, TElement, TListElement, TNodeMap, TText, Value } from "platejs";
1
+ import * as platejs2 from "platejs";
2
+ import { Descendant, NodeKey, Nullable, OmitFirst, PluginConfig, SlateEditor, TElement, TListElement, TNodeMap, TText, Value } from "platejs";
2
3
  import { MdxJsxFlowElement, MdxJsxFlowElement as MdMdxJsxFlowElement, MdxJsxTextElement, MdxJsxTextElement as MdMdxJsxTextElement } from "mdast-util-mdx";
3
4
  import { Options } from "remark-stringify";
4
5
  import { Plugin } from "unified";
5
6
  import { Token } from "marked";
6
7
  import baseRemarkMdx from "remark-mdx";
7
- import * as unistLib from "unist";
8
- import { StrictExtract } from "ts-essentials";
9
8
  import { Blockquote as MdBlockquote, Break as MdBreak, Code as MdCode, Content as MdContent, Definition as MdDefinition, Delete as MdDelete, Emphasis as MdEmphasis, FootnoteDefinition as MdFootnoteDefinition, FootnoteReference as MdFootnoteReference, Heading as MdHeading, Html as MdHtml, Image as MdImage, ImageReference as MdImageReference, InlineCode as MdInlineCode, Link as MdLink, LinkReference as MdLinkReference, List as MdList, ListItem as MdListItem, Paragraph as MdParagraph, PhrasingContent as MDPhrasingContent, Root, Root as MdRoot, RootContent as MdRootContent, Strong as MdStrong, Table as MdTable, TableCell as MdTableCell, TableRow as MdTableRow, Text as MdText, ThematicBreak as MdThematicBreak, Yaml as MdYaml } from "mdast";
10
9
  import { InlineMath as MdInlineMath, Math as MdMath } from "mdast-util-math";
10
+ import * as unistLib from "unist";
11
+ import { StrictExtract } from "ts-essentials";
11
12
 
12
- //#region src/lib/deserializer/utils/customMdxDeserialize.d.ts
13
- declare const customMdxDeserialize: (mdastNode: MdxJsxFlowElement | MdxJsxTextElement, deco: MdDecoration, options: DeserializeMdOptions) => any;
14
- //#endregion
15
- //#region src/lib/deserializer/utils/deserializeInlineMd.d.ts
16
- declare const deserializeInlineMd: (editor: SlateEditor, text: string, options?: DeserializeMdOptions) => Descendant[];
17
- //#endregion
18
- //#region src/lib/deserializer/utils/getDeserializerByKey.d.ts
19
- declare const getDeserializerByKey: (key: string, options: DeserializeMdOptions) => any;
20
- //#endregion
21
- //#region src/lib/deserializer/utils/getMergedOptionsDeserialize.d.ts
22
- /**
23
- * Merges Markdown configurations, following the principle that options take
24
- * precedence
25
- *
26
- * @param editor Editor instance used to get plugin default configurations
27
- * @param options User-provided options (higher priority)
28
- * @returns The final merged configuration
29
- */
30
- declare const getMergedOptionsDeserialize: (editor: SlateEditor, options?: DeserializeMdOptions) => DeserializeMdOptions;
31
- //#endregion
32
- //#region src/lib/deserializer/utils/getStyleValue.d.ts
33
- declare const getStyleValue: (mdastNode: MdMdxJsxTextElement, styleName: string) => string | undefined;
34
- //#endregion
35
- //#region src/lib/deserializer/utils/htmlToJsx.d.ts
36
- declare const htmlToJsx: (html: string) => string;
37
- //#endregion
38
- //#region src/lib/deserializer/utils/markdownToSlateNodesSafely.d.ts
39
- declare const markdownToSlateNodesSafely: (editor: SlateEditor, data: string, options?: Omit<DeserializeMdOptions, "editor">) => Descendant[];
40
- //#endregion
41
- //#region src/lib/deserializer/utils/parseMarkdownBlocks.d.ts
42
- type ParseMarkdownBlocksOptions = {
43
- /**
44
- * Token types to exclude from the output.
45
- *
46
- * @default ['space']
47
- */
48
- exclude?: string[];
49
- /**
50
- * Whether to trim the content.
51
- *
52
- * @default true
53
- */
54
- trim?: boolean;
55
- };
56
- declare const parseMarkdownBlocks: (content: string, {
57
- exclude,
58
- trim
59
- }?: ParseMarkdownBlocksOptions) => Token[];
60
- //#endregion
61
- //#region src/lib/deserializer/utils/splitIncompleteMdx.d.ts
62
- declare const splitIncompleteMdx: (data: string) => string[] | string;
63
- //#endregion
64
- //#region src/lib/deserializer/utils/stripMarkdown.d.ts
65
- declare const stripMarkdownBlocks: (text: string) => string;
66
- declare const stripMarkdownInline: (text: string) => string;
67
- declare const stripMarkdown: (text: string) => string;
68
- //#endregion
69
- //#region src/lib/deserializer/deserializeMd.d.ts
70
- type DeserializeMdOptions = {
71
- allowedNodes?: PlateType[] | null;
72
- allowNode?: AllowNodeConfig;
73
- disallowedNodes?: PlateType[] | null;
74
- editor?: SlateEditor;
75
- memoize?: boolean;
76
- parser?: ParseMarkdownBlocksOptions;
77
- preserveEmptyParagraphs?: boolean;
78
- remarkPlugins?: Plugin[];
79
- rules?: MdRules | null;
80
- splitLineBreaks?: boolean;
81
- withoutMdx?: boolean;
82
- onError?: (error: Error) => void;
83
- };
84
- declare const markdownToAstProcessor: (editor: SlateEditor, data: string, options?: DeserializeMdOptions) => Root;
85
- declare const markdownToSlateNodes: (editor: SlateEditor, data: string, options?: Omit<DeserializeMdOptions, "editor">) => Descendant$1[];
86
- declare const deserializeMd: (editor: SlateEditor, data: string, options?: Omit<DeserializeMdOptions, "editor">) => Value;
87
- declare module 'unified' {
88
- interface CompileResultMap {
89
- remarkToSlateNode: Descendant$1[];
90
- }
91
- }
92
- //# sourceMappingURL=deserializeMd.d.ts.map
93
- //#endregion
94
- //#region src/lib/deserializer/convertChildrenDeserialize.d.ts
95
- declare const convertChildrenDeserialize: (children: MdRootContent[], deco: MdDecoration, options: DeserializeMdOptions) => Descendant$1[];
96
- //#endregion
97
- //#region src/lib/deserializer/convertNodesDeserialize.d.ts
98
- declare const convertNodesDeserialize: (nodes: MdRootContent[], deco: MdDecoration, options: DeserializeMdOptions) => Descendant$1[];
99
- declare const buildSlateNode: (mdastNode: MdRootContent, deco: MdDecoration, options: DeserializeMdOptions) => Descendant$1[];
100
- //#endregion
101
- //#region src/lib/deserializer/convertTextsDeserialize.d.ts
102
- declare const convertTextsDeserialize: (mdastNode: MdDelete | MdEmphasis | MdStrong, deco: MdDecoration, options: DeserializeMdOptions) => any;
103
- //#endregion
104
- //#region src/lib/deserializer/mdastToSlate.d.ts
105
- declare const mdastToSlate: (node: Root, options: DeserializeMdOptions) => Descendant$1[];
106
- //#endregion
107
13
  //#region src/lib/serializer/serializeMd.d.ts
108
14
  type SerializeMdOptions = {
109
15
  allowedNodes?: PlateType[] | null;
@@ -117,14 +23,14 @@ type SerializeMdOptions = {
117
23
  remarkStringifyOptions?: Options | null;
118
24
  rules?: MdRules;
119
25
  spread?: boolean;
120
- value?: Descendant$1[];
26
+ value?: Descendant[];
121
27
  withBlockId?: boolean;
122
28
  };
123
29
  /** Serialize the editor value to Markdown. */
124
30
  declare const serializeMd: (editor: SlateEditor, options?: Omit<SerializeMdOptions, "editor">) => string;
125
31
  //#endregion
126
32
  //#region src/lib/serializer/convertNodesSerialize.d.ts
127
- declare const convertNodesSerialize: (nodes: Descendant$1[], options: SerializeMdOptions, isBlock?: boolean) => unistLib.Node[];
33
+ declare const convertNodesSerialize: (nodes: Descendant[], options: SerializeMdOptions, isBlock?: boolean) => unistLib.Node[];
128
34
  declare const buildMdastNode: (node: any, options: SerializeMdOptions, isBlock?: boolean) => any;
129
35
  //#endregion
130
36
  //#region src/lib/serializer/convertTextsSerialize.d.ts
@@ -254,12 +160,12 @@ type MdNodeMap = {
254
160
  * Get plate node type from mdast node type if the mdast is mdast only return
255
161
  * the mdast type itself.
256
162
  */
257
- declare const mdastToPlate: <T extends StrictMdType>(editor: SlateEditor, mdastType: T) => any;
163
+ declare const mdastToPlate: <T extends StrictMdType>(editor: SlateEditor, mdastType: T) => string;
258
164
  /**
259
165
  * Get mdast node type from plate element type if the plateType is plate only
260
166
  * return the plateType itself.
261
167
  */
262
- declare const plateToMdast: <T extends StrictPlateType>(plateType: T) => T | NonNullable<{
168
+ declare const plateToMdast: <T extends StrictPlateType>(plateType: T) => {
263
169
  readonly a: "link";
264
170
  readonly blockquote: "blockquote";
265
171
  readonly bold: "strong";
@@ -293,7 +199,108 @@ declare const plateToMdast: <T extends StrictPlateType>(plateType: T) => T | Non
293
199
  readonly toggle: "toggle";
294
200
  readonly tr: "tableRow";
295
201
  readonly underline: "u";
296
- }[T]>;
202
+ }[T];
203
+ //#endregion
204
+ //#region src/lib/deserializer/utils/customMdxDeserialize.d.ts
205
+ declare const customMdxDeserialize: (mdastNode: MdxJsxFlowElement | MdxJsxTextElement, deco: MdDecoration, options: DeserializeMdOptions) => any;
206
+ //#endregion
207
+ //#region src/lib/deserializer/utils/deserializeInlineMd.d.ts
208
+ declare const deserializeInlineMd: (editor: SlateEditor, text: string, options?: DeserializeMdOptions) => Descendant[] | {
209
+ text: string;
210
+ }[];
211
+ //#endregion
212
+ //#region src/lib/deserializer/utils/getDeserializerByKey.d.ts
213
+ declare const getDeserializerByKey: (key: string, options: DeserializeMdOptions) => any;
214
+ //#endregion
215
+ //#region src/lib/deserializer/utils/getMergedOptionsDeserialize.d.ts
216
+ /**
217
+ * Merges Markdown configurations, following the principle that options take
218
+ * precedence
219
+ *
220
+ * @param editor Editor instance used to get plugin default configurations
221
+ * @param options User-provided options (higher priority)
222
+ * @returns The final merged configuration
223
+ */
224
+ declare const getMergedOptionsDeserialize: (editor: SlateEditor, options?: DeserializeMdOptions) => DeserializeMdOptions;
225
+ //#endregion
226
+ //#region src/lib/deserializer/utils/getStyleValue.d.ts
227
+ declare const getStyleValue: (mdastNode: MdMdxJsxTextElement, styleName: string) => string | undefined;
228
+ //#endregion
229
+ //#region src/lib/deserializer/utils/htmlToJsx.d.ts
230
+ declare const htmlToJsx: (html: string) => string;
231
+ //#endregion
232
+ //#region src/lib/deserializer/utils/markdownToSlateNodesSafely.d.ts
233
+ declare const markdownToSlateNodesSafely: (editor: SlateEditor, data: string, options?: Omit<DeserializeMdOptions, "editor">) => (platejs2.TText | {
234
+ children: platejs2.Descendant[] | {
235
+ text: string;
236
+ }[];
237
+ type: string;
238
+ })[];
239
+ //#endregion
240
+ //#region src/lib/deserializer/utils/parseMarkdownBlocks.d.ts
241
+ type ParseMarkdownBlocksOptions = {
242
+ /**
243
+ * Token types to exclude from the output.
244
+ *
245
+ * @default ['space']
246
+ */
247
+ exclude?: string[];
248
+ /**
249
+ * Whether to trim the content.
250
+ *
251
+ * @default true
252
+ */
253
+ trim?: boolean;
254
+ };
255
+ declare const parseMarkdownBlocks: (content: string, {
256
+ exclude,
257
+ trim
258
+ }?: ParseMarkdownBlocksOptions) => Token[];
259
+ //#endregion
260
+ //#region src/lib/deserializer/utils/splitIncompleteMdx.d.ts
261
+ declare const splitIncompleteMdx: (data: string) => string[] | string;
262
+ //#endregion
263
+ //#region src/lib/deserializer/utils/stripMarkdown.d.ts
264
+ declare const stripMarkdownBlocks: (text: string) => string;
265
+ declare const stripMarkdownInline: (text: string) => string;
266
+ declare const stripMarkdown: (text: string) => string;
267
+ //#endregion
268
+ //#region src/lib/deserializer/deserializeMd.d.ts
269
+ type DeserializeMdOptions = {
270
+ allowedNodes?: PlateType[] | null;
271
+ allowNode?: AllowNodeConfig;
272
+ disallowedNodes?: PlateType[] | null;
273
+ editor?: SlateEditor;
274
+ memoize?: boolean;
275
+ parser?: ParseMarkdownBlocksOptions;
276
+ preserveEmptyParagraphs?: boolean;
277
+ remarkPlugins?: Plugin[];
278
+ rules?: MdRules | null;
279
+ splitLineBreaks?: boolean;
280
+ withoutMdx?: boolean;
281
+ onError?: (error: Error) => void;
282
+ };
283
+ declare const markdownToAstProcessor: (editor: SlateEditor, data: string, options?: DeserializeMdOptions) => Root;
284
+ declare const markdownToSlateNodes: (editor: SlateEditor, data: string, options?: Omit<DeserializeMdOptions, "editor">) => Descendant[];
285
+ declare const deserializeMd: (editor: SlateEditor, data: string, options?: Omit<DeserializeMdOptions, "editor">) => Value;
286
+ declare module 'unified' {
287
+ interface CompileResultMap {
288
+ remarkToSlateNode: Descendant[];
289
+ }
290
+ }
291
+ //#endregion
292
+ //#region src/lib/deserializer/convertChildrenDeserialize.d.ts
293
+ declare const convertChildrenDeserialize: (children: MdRootContent[], deco: MdDecoration, options: DeserializeMdOptions) => Descendant[];
294
+ //#endregion
295
+ //#region src/lib/deserializer/convertNodesDeserialize.d.ts
296
+ declare const convertNodesDeserialize: (nodes: MdRootContent[], deco: MdDecoration, options: DeserializeMdOptions) => Descendant[];
297
+ declare const buildSlateNode: (mdastNode: MdRootContent, deco: MdDecoration, options: DeserializeMdOptions) => Descendant[];
298
+ //#endregion
299
+ //#region src/lib/deserializer/convertTextsDeserialize.d.ts
300
+ declare const convertTextsDeserialize: (mdastNode: MdDelete | MdEmphasis | MdStrong, deco: MdDecoration, options: DeserializeMdOptions) => any;
301
+ //#endregion
302
+ //#region src/lib/deserializer/mdastToSlate.d.ts
303
+ declare const mdastToSlate: (node: Root, options: DeserializeMdOptions) => Descendant[];
297
304
  //#endregion
298
305
  //#region src/lib/MarkdownPlugin.d.ts
299
306
  type AllowNodeConfig = {
@@ -363,7 +370,73 @@ type MarkdownConfig = PluginConfig<'markdown', {
363
370
  serialize: OmitFirst<typeof serializeMd>;
364
371
  };
365
372
  }>;
366
- declare const MarkdownPlugin: any;
373
+ declare const MarkdownPlugin: platejs2.SlatePlugin<PluginConfig<"markdown", {
374
+ /**
375
+ * Configuration for allowed node types. Cannot be combined with
376
+ * disallowedNodes.
377
+ */
378
+ allowedNodes: PlateType[] | null;
379
+ /**
380
+ * Configuration for disallowed node types. Cannot be combined with
381
+ * allowedNodes.
382
+ *
383
+ * @default null
384
+ */
385
+ disallowedNodes: PlateType[] | null;
386
+ /**
387
+ * Array of remark plugins to extend Markdown parsing and serialization
388
+ * functionality. For example, you can add remark-gfm to support GFM syntax,
389
+ * remark-math to support mathematical formulas, etc. These plugins will be
390
+ * used during the parsing and generation of Markdown text.
391
+ *
392
+ * @default undefined
393
+ */
394
+ remarkPlugins: Plugin[];
395
+ /**
396
+ * Custom options passed to remark-stringify.
397
+ *
398
+ * @default null
399
+ */
400
+ remarkStringifyOptions: Options | null;
401
+ /**
402
+ * Rules that define how to convert Markdown syntax elements to Slate editor
403
+ * elements. Or rules that how to convert Slate editor elements to Markdown
404
+ * syntax elements. Includes conversion rules for elements such as
405
+ * paragraphs, headings, lists, links, images, etc.
406
+ *
407
+ * You can pass null disable default node parser.
408
+ *
409
+ * NOTE: don't forget pass `mark:true` when you custom inline nodes.
410
+ *
411
+ * @default null
412
+ */
413
+ rules: MdRules | null;
414
+ /**
415
+ * Custom filter function for nodes during deserialization and
416
+ * serialization.
417
+ *
418
+ * @default null
419
+ */
420
+ allowNode?: AllowNodeConfig;
421
+ /**
422
+ * Marks to treat as plain text without applying markdown formatting.
423
+ *
424
+ * @default null
425
+ */
426
+ plainMarks?: PlateType[] | null;
427
+ }, {
428
+ markdown: {
429
+ deserialize: OmitFirst<typeof deserializeMd>;
430
+ deserializeInline: OmitFirst<typeof deserializeInlineMd>;
431
+ serialize: OmitFirst<typeof serializeMd>;
432
+ };
433
+ } & Record<"markdown", {
434
+ deserialize: (data: string, options?: Omit<DeserializeMdOptions, "editor"> | undefined) => platejs2.Value;
435
+ deserializeInline: (text: string, options?: DeserializeMdOptions | undefined) => platejs2.Descendant[] | {
436
+ text: string;
437
+ }[];
438
+ serialize: (options?: Omit<SerializeMdOptions, "editor"> | undefined) => string;
439
+ }>, {}, {}>>;
367
440
  //#endregion
368
441
  //#region src/lib/plugins/remarkMdx.d.ts
369
442
  declare const remarkMdx: typeof baseRemarkMdx;
@@ -421,5 +494,4 @@ declare const tagRemarkPlugin: (pluginFn: any, tag: string) => {
421
494
  };
422
495
  declare const getRemarkPluginsWithoutMdx: (plugins: Plugin[]) => Plugin[];
423
496
  //#endregion
424
- export { AllowNodeConfig, DeserializeMdOptions, type MDPhrasingContent, MarkdownConfig, MarkdownPlugin, type MdBlockquote, type MdBreak, type MdCode, type MdContent, MdDecoration, type MdDefinition, type MdDelete, type MdEmphasis, type MdFootnoteDefinition, type MdFootnoteReference, type MdHeading, type MdHtml, type MdImage, type MdImageReference, type MdInlineCode, type MdInlineMath, type MdLink, type MdLinkReference, type MdList, type MdListItem, MdMark, type MdMath, type MdMdxJsxFlowElement, type MdMdxJsxTextElement, MdNodeParser, type MdParagraph, type MdRoot, type MdRootContent, MdRules, type MdStrong, type MdTable, type MdTableCell, type MdTableRow, type MdText, type MdThematicBreak, MdType, type MdYaml, MentionNode, ParseMarkdownBlocksOptions, PlateType, REMARK_MDX_TAG, SerializeMdOptions, StrictPlateType, basicMarkdownMarks, buildMdastNode, buildRules, buildSlateNode, columnRules, convertChildrenDeserialize, convertNodesDeserialize, convertNodesSerialize, convertTextsDeserialize, convertTextsSerialize, customMdxDeserialize, defaultRules, deserializeInlineMd, deserializeMd, fontRules, getCustomMark, getDeserializerByKey, getMergedOptionsDeserialize, getMergedOptionsSerialize, getRemarkPluginsWithoutMdx, getSerializerByKey, getStyleValue, htmlToJsx, listToMdastTree, markdownToAstProcessor, markdownToSlateNodes, markdownToSlateNodesSafely, mdastToPlate, mdastToSlate, mediaRules, parseAttributes, parseMarkdownBlocks, plateToMdast, propsToAttributes, remarkMdx, remarkMention, serializeInlineMd, serializeMd, splitIncompleteMdx, stripMarkdown, stripMarkdownBlocks, stripMarkdownInline, tagRemarkPlugin, type unistLib, unreachable, wrapWithBlockId };
425
- //# sourceMappingURL=index.d.ts.map
497
+ export { AllowNodeConfig, DeserializeMdOptions, type MDPhrasingContent, MarkdownConfig, MarkdownPlugin, type MdBlockquote, type MdBreak, type MdCode, type MdContent, MdDecoration, type MdDefinition, type MdDelete, type MdEmphasis, type MdFootnoteDefinition, type MdFootnoteReference, type MdHeading, type MdHtml, type MdImage, type MdImageReference, type MdInlineCode, type MdInlineMath, type MdLink, type MdLinkReference, type MdList, type MdListItem, MdMark, type MdMath, type MdMdxJsxFlowElement, type MdMdxJsxTextElement, MdNodeParser, type MdParagraph, type MdRoot, type MdRootContent, MdRules, type MdStrong, type MdTable, type MdTableCell, type MdTableRow, type MdText, type MdThematicBreak, MdType, type MdYaml, MentionNode, ParseMarkdownBlocksOptions, PlateType, REMARK_MDX_TAG, SerializeMdOptions, StrictPlateType, basicMarkdownMarks, buildMdastNode, buildRules, buildSlateNode, columnRules, convertChildrenDeserialize, convertNodesDeserialize, convertNodesSerialize, convertTextsDeserialize, convertTextsSerialize, customMdxDeserialize, defaultRules, deserializeInlineMd, deserializeMd, fontRules, getCustomMark, getDeserializerByKey, getMergedOptionsDeserialize, getMergedOptionsSerialize, getRemarkPluginsWithoutMdx, getSerializerByKey, getStyleValue, htmlToJsx, listToMdastTree, markdownToAstProcessor, markdownToSlateNodes, markdownToSlateNodesSafely, mdastToPlate, mdastToSlate, mediaRules, parseAttributes, parseMarkdownBlocks, plateToMdast, propsToAttributes, remarkMdx, remarkMention, serializeInlineMd, serializeMd, splitIncompleteMdx, stripMarkdown, stripMarkdownBlocks, stripMarkdownInline, tagRemarkPlugin, type unistLib, unreachable, wrapWithBlockId };
package/dist/index.js CHANGED
@@ -522,9 +522,9 @@ function listToMdastTree(nodes, options, isBlock = false) {
522
522
  children: convertNodesSerialize(node.children, options),
523
523
  type: "paragraph"
524
524
  }],
525
+ spread: options.spread ?? false,
525
526
  type: "listItem"
526
527
  };
527
- if (options.spread) listItem.spread = true;
528
528
  if (node.listStyleType === "todo" && node.checked !== void 0) listItem.checked = node.checked;
529
529
  stackTop.list.children.push(listItem);
530
530
  const nextNode = nodes[i + 1];
@@ -568,9 +568,9 @@ function processListWithBlockIds(nodes, options) {
568
568
  children: convertNodesSerialize(node.children, options),
569
569
  type: "paragraph"
570
570
  }],
571
+ spread: options.spread ?? false,
571
572
  type: "listItem"
572
573
  };
573
- if (options.spread) listItem.spread = true;
574
574
  if (node.listStyleType === "todo" && node.checked !== void 0) listItem.checked = node.checked;
575
575
  singleList.children.push(listItem);
576
576
  if (node.id) fragments.push(wrapWithBlockId(singleList, String(node.id)));
@@ -699,6 +699,19 @@ const LEADING_NEWLINE_REGEX = /^\n/;
699
699
  function isBoolean(value) {
700
700
  return value === true || value === false || !!value && typeof value === "object" && Object.prototype.toString.call(value) === "[object Boolean]";
701
701
  }
702
+ const createClassicListItemContent = (editor, children = []) => ({
703
+ children: children.length > 0 ? children : [{ text: "" }],
704
+ type: getPluginType(editor, KEYS.lic)
705
+ });
706
+ const deserializeClassicListItemChildren = (mdastChildren, deco, options) => {
707
+ const licType = getPluginType(options.editor, KEYS.lic);
708
+ const children = mdastChildren.map((child) => {
709
+ if (child.type === "paragraph") return createClassicListItemContent(options.editor, convertChildrenDeserialize(child.children, deco, options));
710
+ return convertChildrenDeserialize([child], deco, options)[0];
711
+ }).filter(Boolean);
712
+ if (!children.some((child) => child.type === licType)) children.unshift(createClassicListItemContent(options.editor));
713
+ return children;
714
+ };
702
715
  const defaultRules = {
703
716
  a: {
704
717
  deserialize: (mdastNode, deco, options) => ({
@@ -989,13 +1002,7 @@ const defaultRules = {
989
1002
  if (!!!options.editor?.plugins.list) return {
990
1003
  children: mdastNode.children.map((child) => {
991
1004
  if (child.type === "listItem") return {
992
- children: child.children.map((itemChild) => {
993
- if (itemChild.type === "paragraph") return {
994
- children: convertChildrenDeserialize(itemChild.children, deco, options),
995
- type: getPluginType(options.editor, KEYS.lic)
996
- };
997
- return convertChildrenDeserialize([itemChild], deco, options)[0];
998
- }),
1005
+ children: deserializeClassicListItemChildren(child.children, deco, options),
999
1006
  type: getPluginType(options.editor, KEYS.li)
1000
1007
  };
1001
1008
  return convertChildrenDeserialize([child], deco, options)[0];
@@ -1015,7 +1022,7 @@ const defaultRules = {
1015
1022
  children: [{ text: "" }],
1016
1023
  type: getPluginType(options.editor, KEYS.p)
1017
1024
  };
1018
- (Array.isArray(result) ? result : [result]).forEach((node) => {
1025
+ (Array.isArray(result) ? result : [result]).forEach((node, nodeIndex) => {
1019
1026
  const itemContent = {
1020
1027
  ...node,
1021
1028
  indent,
@@ -1023,7 +1030,10 @@ const defaultRules = {
1023
1030
  };
1024
1031
  itemContent.listStyleType = listStyleType;
1025
1032
  if (isTodoList) itemContent.checked = listItem.checked;
1026
- if (isOrdered) itemContent.listStart = startIndex + index;
1033
+ if (isOrdered) {
1034
+ itemContent.listStart = startIndex + index;
1035
+ if (index === 0 && nodeIndex === 0 && itemContent.listStart > 1) itemContent.listRestartPolite = itemContent.listStart;
1036
+ }
1027
1037
  items.push(itemContent);
1028
1038
  });
1029
1039
  subLists.forEach((subNode) => {
@@ -1084,18 +1094,10 @@ const defaultRules = {
1084
1094
  }
1085
1095
  },
1086
1096
  listItem: {
1087
- deserialize: (mdastNode, deco, options) => {
1088
- return {
1089
- children: mdastNode.children.map((child) => {
1090
- if (child.type === "paragraph") return {
1091
- children: convertChildrenDeserialize(child.children, deco, options),
1092
- type: getPluginType(options.editor, KEYS.lic)
1093
- };
1094
- return convertChildrenDeserialize([child], deco, options)[0];
1095
- }),
1096
- type: getPluginType(options.editor, KEYS.li)
1097
- };
1098
- },
1097
+ deserialize: (mdastNode, deco, options) => ({
1098
+ children: deserializeClassicListItemChildren(mdastNode.children, deco, options),
1099
+ type: getPluginType(options.editor, KEYS.li)
1100
+ }),
1099
1101
  serialize: (node, options) => ({
1100
1102
  children: convertNodesSerialize(node.children, options),
1101
1103
  type: "listItem"
@@ -1462,17 +1464,17 @@ const stripMarkdown = (text) => {
1462
1464
  const LEADING_SPACES_REGEX = /^\s*/;
1463
1465
  const TRAILING_SPACES_REGEX = /\s*$/;
1464
1466
  const deserializeInlineMd = (editor, text, options) => {
1467
+ const trimmedText = text.trim();
1465
1468
  const leadingSpaces = LEADING_SPACES_REGEX.exec(text)?.[0] || "";
1466
1469
  const trailingSpaces = TRAILING_SPACES_REGEX.exec(text)?.[0] || "";
1467
- const strippedText = stripMarkdownBlocks(text.trim());
1470
+ const strippedText = stripMarkdownBlocks(trimmedText);
1471
+ if (!strippedText) return text ? [{ text }] : [];
1468
1472
  const fragment = [];
1469
1473
  if (leadingSpaces) fragment.push({ text: leadingSpaces });
1470
- if (strippedText) {
1471
- const result = editor.getApi(MarkdownPlugin).markdown.deserialize(strippedText, options)[0];
1472
- if (result) {
1473
- const nodes = ElementApi.isElement(result) ? result.children : [result];
1474
- fragment.push(...nodes);
1475
- }
1474
+ const result = editor.getApi(MarkdownPlugin).markdown.deserialize(strippedText, options)[0];
1475
+ if (result) {
1476
+ const nodes = ElementApi.isElement(result) ? result.children : [result];
1477
+ fragment.push(...nodes);
1476
1478
  }
1477
1479
  if (trailingSpaces) fragment.push({ text: trailingSpaces });
1478
1480
  return fragment;
@@ -1692,6 +1694,7 @@ const splitIncompleteMdx = (data) => {
1692
1694
  }
1693
1695
  const tagName = data.slice(nameStart, i).toLowerCase();
1694
1696
  let inQuote = null;
1697
+ let foundTagEnd = false;
1695
1698
  let selfClosing = false;
1696
1699
  while (i < len) {
1697
1700
  const ch = data[i];
@@ -1699,13 +1702,14 @@ const splitIncompleteMdx = (data) => {
1699
1702
  if (ch === inQuote) inQuote = null;
1700
1703
  } else if (ch === "\"" || ch === "'") inQuote = ch;
1701
1704
  else if (ch === ">") {
1705
+ foundTagEnd = true;
1702
1706
  selfClosing = data[i - 1] === "/";
1703
1707
  i++;
1704
1708
  break;
1705
1709
  }
1706
1710
  i++;
1707
1711
  }
1708
- if (i >= len) {
1712
+ if (!foundTagEnd) {
1709
1713
  cutPos = tagStart;
1710
1714
  break;
1711
1715
  }
@@ -1741,7 +1745,6 @@ const markdownToSlateNodesSafely = (editor, data, options) => {
1741
1745
  withoutMdx: true
1742
1746
  });
1743
1747
  const completeNodes = markdownToSlateNodes(editor, completeString, options);
1744
- if (incompleteNodes.length === 0) return completeNodes;
1745
1748
  const newBlock = {
1746
1749
  children: incompleteNodes,
1747
1750
  type: getPluginType(editor, KEYS.p)
@@ -1931,5 +1934,4 @@ const remarkMention = () => (tree) => {
1931
1934
  };
1932
1935
 
1933
1936
  //#endregion
1934
- export { MarkdownPlugin, REMARK_MDX_TAG, basicMarkdownMarks, buildMdastNode, buildRules, buildSlateNode, columnRules, convertChildrenDeserialize, convertNodesDeserialize, convertNodesSerialize, convertTextsDeserialize, convertTextsSerialize, customMdxDeserialize, defaultRules, deserializeInlineMd, deserializeMd, fontRules, getCustomMark, getDeserializerByKey, getMergedOptionsDeserialize, getMergedOptionsSerialize, getRemarkPluginsWithoutMdx, getSerializerByKey, getStyleValue, htmlToJsx, listToMdastTree, markdownToAstProcessor, markdownToSlateNodes, markdownToSlateNodesSafely, mdastToPlate, mdastToSlate, mediaRules, parseAttributes, parseMarkdownBlocks, plateToMdast, propsToAttributes, remarkMdx, remarkMention, serializeInlineMd, serializeMd, splitIncompleteMdx, stripMarkdown, stripMarkdownBlocks, stripMarkdownInline, tagRemarkPlugin, unreachable, wrapWithBlockId };
1935
- //# sourceMappingURL=index.js.map
1937
+ export { MarkdownPlugin, REMARK_MDX_TAG, basicMarkdownMarks, buildMdastNode, buildRules, buildSlateNode, columnRules, convertChildrenDeserialize, convertNodesDeserialize, convertNodesSerialize, convertTextsDeserialize, convertTextsSerialize, customMdxDeserialize, defaultRules, deserializeInlineMd, deserializeMd, fontRules, getCustomMark, getDeserializerByKey, getMergedOptionsDeserialize, getMergedOptionsSerialize, getRemarkPluginsWithoutMdx, getSerializerByKey, getStyleValue, htmlToJsx, listToMdastTree, markdownToAstProcessor, markdownToSlateNodes, markdownToSlateNodesSafely, mdastToPlate, mdastToSlate, mediaRules, parseAttributes, parseMarkdownBlocks, plateToMdast, propsToAttributes, remarkMdx, remarkMention, serializeInlineMd, serializeMd, splitIncompleteMdx, stripMarkdown, stripMarkdownBlocks, stripMarkdownInline, tagRemarkPlugin, unreachable, wrapWithBlockId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lofcz/platejs-markdown",
3
- "version": "52.3.5",
3
+ "version": "52.3.6",
4
4
  "description": "Markdown serializer plugin for Plate",
5
5
  "keywords": [
6
6
  "markdown",
@@ -48,7 +48,8 @@
48
48
  "@types/unist": "^3.0.3",
49
49
  "remark-gfm": "4.0.1",
50
50
  "remark-math": "6.0.0",
51
- "@plate/scripts": "1.0.0"
51
+ "@plate/scripts": "1.0.0",
52
+ "platejs": "npm:@lofcz/platejs@52.3.6"
52
53
  },
53
54
  "peerDependencies": {
54
55
  "platejs": ">=52.0.11",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/lib/deserializer/utils/customMdxDeserialize.ts","../src/lib/deserializer/utils/deserializeInlineMd.ts","../src/lib/deserializer/utils/getDeserializerByKey.ts","../src/lib/deserializer/utils/getMergedOptionsDeserialize.ts","../src/lib/deserializer/utils/getStyleValue.ts","../src/lib/deserializer/utils/htmlToJsx.ts","../src/lib/deserializer/utils/markdownToSlateNodesSafely.ts","../src/lib/deserializer/utils/parseMarkdownBlocks.ts","../src/lib/deserializer/utils/splitIncompleteMdx.ts","../src/lib/deserializer/utils/stripMarkdown.ts","../src/lib/deserializer/deserializeMd.ts","../src/lib/deserializer/convertChildrenDeserialize.ts","../src/lib/deserializer/convertNodesDeserialize.ts","../src/lib/deserializer/convertTextsDeserialize.ts","../src/lib/deserializer/mdastToSlate.ts","../src/lib/serializer/serializeMd.ts","../src/lib/serializer/convertNodesSerialize.ts","../src/lib/serializer/convertTextsSerialize.ts","../src/lib/serializer/listToMdastTree.ts","../src/lib/serializer/serializeInlineMd.ts","../src/lib/serializer/wrapWithBlockId.ts","../src/lib/serializer/utils/getCustomMark.ts","../src/lib/serializer/utils/getMergedOptionsSerialize.ts","../src/lib/serializer/utils/getSerializerByKey.ts","../src/lib/serializer/utils/unreachable.ts","../src/lib/types.ts","../src/lib/MarkdownPlugin.ts","../src/lib/plugins/remarkMdx.ts","../src/lib/plugins/remarkMention.ts","../src/lib/rules/columnRules.ts","../src/lib/rules/defaultRules.ts","../src/lib/rules/fontRules.ts","../src/lib/rules/mediaRules.ts","../src/lib/rules/utils/parseAttributes.ts","../src/lib/utils/getRemarkPluginsWithoutMdx.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAWa,kCACA,oBAAoB,yBACzB,uBACG;;;cCJE,8BACH,qCAEE,yBAAoB;;;cCTnB,6CAEF;;;;;;;;;;;cCUE,sCACH,uBACE,yBACT;;;cCjBU,2BACA;;;cCmCA;;;cC7BA,qCACH,qCAEE,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,sCAAuC,aAAQ"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["unistLib","StrictExtract","NodeKey","Nullable","SlateEditor","TElement","TNodeMap","TText","getPluginKey","DeserializeMdOptions","MdBlockquote","MdBreak","MdCode","MdDefinition","MdDelete","MdEmphasis","MdFootnoteDefinition","MdFootnoteReference","MdHeading","MdHtml","MdImage","MdImageReference","MdInlineCode","MdInlineMath","MdLink","MdLinkReference","MdList","MdMath","MdParagraph","MdRootContent","MdStrong","MdTable","MdTableCell","MdTableRow","MdText","MdThematicBreak","MdYaml","SerializeMdOptions","MdRules","Partial","PlateNodeMap","MdNodeParser","K","Record","AnyNodeParser","mark","deserialize","mdastNode","MdNodeMap","deco","MdDecoration","options","serialize","slateNode","StrictMdType","MdGFM","MdStyle","MdType","MdMark","Readonly","StrictPlateType","PlateType","Pick","text","list","heading","footnoteReference","definition","footnoteDefinition","break","yaml","imageReference","linkReference","html","a","blockquote","code_block","equation","hr","img","inline_equation","p","table","td","th","tr","bold","italic","code","strikethrough","column_group","column","toc","callout","toggle","mention","date","underline","comment","superscript","subscript","suggestion","file","video","audio","PLATE_TO_MDAST","code_line","li","const","MDAST_TO_PLATE","backgroundColor","color","del","delete","emphasis","fontFamily","fontSize","fontWeight","image","inlineCode","inlineMath","link","listItem","math","mdxFlowExpression","mdxjsEsm","mdxJsxFlowElement","mdxJsxTextElement","mdxTextExpression","paragraph","strong","sub","sup","tableCell","tableRow","thematicBreak","u","mdastToPlate","editor","mdastType","T","plateKey","plateToMdast","plateType","SerializeMdOptions","getCustomMark","options","rules","Object","entries","filter","_","parser","mark","map","key","parseAttributes","attributes","Record","props","length","forEach","attr","name","value","undefined","JSON","parse","_error","propsToAttributes","Object","entries","map","type","stringify","getPluginType","KEYS","MdRules","convertChildrenDeserialize","convertNodesSerialize","parseAttributes","propsToAttributes","columnRules","column","deserialize","mdastNode","deco","options","props","attributes","children","type","editor","serialize","node","id","rest","name","column_group","columnGroup","kebabCase","MdMdxJsxTextElement","MdRules","convertChildrenDeserialize","getStyleValue","createFontRule","propName","styleName","mark","serialize","slateNode","attributes","name","type","value","children","text","fontRules","backgroundColor","color","fontFamily","fontSize","fontWeight","span","deserialize","mdastNode","deco","options","TMediaElement","MdMdxJsxFlowElement","MdRules","convertNodesSerialize","parseAttributes","propsToAttributes","createMediaRule","deserialize","node","src","props","attributes","children","text","type","name","url","serialize","options","id","rest","mediaRules","audio","file","video","SlateEditor","SerializeMdOptions","MarkdownPlugin","buildRules","getMergedOptionsSerialize","editor","options","allowedNodes","PluginAllowedNodes","allowNode","PluginAllowNode","disallowedNodes","PluginDisallowedNodes","plainMarks","PluginPlainMarks","remarkPlugins","PluginRemarkPlugins","remarkStringifyOptions","PluginRemarkStringifyOptions","rules","PluginRules","getOptions","mergedRules","preserveEmptyParagraphs","spread","value","children","withBlockId","SerializeMdOptions","buildRules","getSerializerByKey","key","options","nodes","rules","editor","serialize","undefined","unreachable","value","console","warn","JSON","stringify","TText","getPluginType","MdMark","SerializeMdOptions","getCustomMark","getSerializerByKey","basicMarkdownMarks","convertTextsSerialize","slateTexts","options","_key","customLeaf","mdastTexts","starts","ends","textTemp","j","length","cur","text","prevStarts","slice","prevEnds","prev","next","filter","k","includes","const","forEach","key","nodeType","editor","plainMarks","push","endsToRemove","reduce","index","acc","kIndex","bef","aft","toString","startsWith","endsWith","res","type","value","reverse","nodeParser","node","children","currentRes","arr","e","splice","mergedTexts","mergeTexts","flattenedEmptyNodes","map","hasContent","child","nodes","last","at","concat","unistLib","wrapWithBlockId","mdastNode","Node","nodeId","attributes","name","type","value","String","children","data","_mdxExplicitJsx","TListElement","MdList","MdListItem","MdParagraph","SerializeMdOptions","convertNodesSerialize","wrapWithBlockId","listToMdastTree","nodes","options","isBlock","length","Error","withBlockId","some","node","id","processListWithBlockIds","root","children","ordered","listStyleType","spread","start","listStart","type","indentStack","indent","list","parent","styleType","i","currentIndent","at","pop","stackTop","hasSameIndentStyleChange","siblingList","push","listItem","checked","undefined","nextNode","nestedList","fragments","singleList","String","Descendant","TElement","TText","getPluginKey","getPluginType","KEYS","TextApi","unistLib","SerializeMdOptions","convertTextsSerialize","listToMdastTree","unreachable","getSerializerByKey","wrapWithBlockId","convertNodesSerialize","nodes","options","isBlock","Node","mdastNodes","textQueue","listBlock","i","length","n","isText","shouldIncludeText","push","shouldIncludeNode","pType","editor","p","type","next","isNextIndent","firstList","at","hasDifferentListStyle","listStyleType","indent","result","children","node","buildMdastNode","key","heading","includes","olClassic","ulClassic","nodeParser","mdastNode","withBlockId","id","text","allowedNodes","allowNode","disallowedNodes","Error","value","Object","entries","serialize","SlateEditor","remarkStringify","unified","SerializeMdOptions","convertTextsSerialize","getMergedOptionsSerialize","serializeInlineMd","editor","options","mergedOptions","toRemarkProcessor","use","remarkPlugins","emphasis","remarkStringifyOptions","value","length","convertedTexts","serializedContent","stringify","children","type","Descendant","SlateEditor","remarkStringify","Options","RemarkStringifyOptions","Plugin","unified","AllowNodeConfig","MdRoot","MdRules","PlateType","convertNodesSerialize","getMergedOptionsSerialize","SerializeMdOptions","allowedNodes","allowNode","disallowedNodes","editor","plainMarks","preserveEmptyParagraphs","remarkPlugins","remarkStringifyOptions","rules","spread","value","withBlockId","serializeMd","options","Omit","mergedOptions","toRemarkProcessor","use","emphasis","mdast","slateToMdast","children","stringify","processedChildren","ast","type","SlateEditor","TElement","TListElement","TMentionElement","TText","getPluginKey","getPluginType","KEYS","MdHeading","MdImage","MdLink","MdList","MdMdxJsxFlowElement","MdMdxJsxTextElement","MdParagraph","MdRootContent","MdTable","MdTableCell","MdTableRow","MentionNode","MdRules","buildSlateNode","convertChildrenDeserialize","convertTextsDeserialize","convertNodesSerialize","columnRules","fontRules","mediaRules","parseAttributes","propsToAttributes","LEADING_NEWLINE_REGEX","isBoolean","value","Object","prototype","toString","call","defaultRules","a","deserialize","mdastNode","deco","options","children","type","editor","url","serialize","node","blockquote","length","flatMap","paragraph","index","paragraphChildren","push","text","flattenedChildren","child","nodes","at","bold","mark","br","break","_mdastNode","_deco","callout","props","attributes","slateNode","rest","name","code","code_block","split","map","line","codeLine","lang","undefined","codeBlock","c","join","comment","date","dateValue","del","strikethrough","equation","texExpression","footnoteDefinition","p","footnoteReference","heading","headingType","defaultType","depth","key","depthMap","h1","h2","h3","h4","h5","h6","highlight","hr","_","__","html","_options","replaceAll","img","alt","title","altAttr","src","caption","image","inline_equation","inlineEquation","italic","kbd","list","isIndentList","plugins","itemChild","lic","li","ordered","olClassic","ulClassic","parseListItems","listNode","indent","startIndex","items","isOrdered","listStyleType","ol","ul","forEach","listItem","isTodoList","checked","listTodo","subLists","result","itemNodes","Array","isArray","itemContent","listStart","subNode","subListStart","start","nestedItems","item","serializeListItems","currentItem","spread","liChild","mention","displayText","username","mentionId","encodedId","encodeURIComponent","String","replace","isKeepLineBreak","splitLineBreaks","splitBlockTypes","Set","elements","inlineNodes","flushInlineNodes","has","textParts","isSingleLineBreak","part","array","isNotFirstPart","isNotLastPart","enrichedChildren","preserveEmptyParagraphs","convertedNodes","subscript","sub","suggestion","superscript","sup","table","paragraphType","rows","row","rowIndex","cell","cellType","cellChildren","groupedChildren","currentParagraphChildren","tr","td","i","th","toc","underline","buildRules","keys","newRules","Record","pluginKey","DeserializeMdOptions","buildRules","getDeserializerByKey","key","options","rules","deserialize","undefined","editor","MdxJsxFlowElement","MdxJsxTextElement","getPluginKey","getPluginType","KEYS","MdDecoration","DeserializeMdOptions","mdastToPlate","convertChildrenDeserialize","getDeserializerByKey","customMdxDeserialize","mdastNode","deco","options","customJsxElementKey","name","key","editor","nodeParserDeserialize","console","warn","type","tagName","textContent","children","map","child","value","join","text","p","stripMarkdownBlocks","text","result","replaceAll","stripMarkdownInline","stripMarkdown","Descendant","SlateEditor","ElementApi","DeserializeMdOptions","MarkdownPlugin","stripMarkdownBlocks","LEADING_SPACES_REGEX","TRAILING_SPACES_REGEX","deserializeInlineMd","editor","text","options","leadingSpaces","exec","trailingSpaces","strippedText","trim","fragment","push","result","getApi","markdown","deserialize","nodes","isElement","children","Plugin","REMARK_MDX_TAG","tagRemarkPlugin","pluginFn","tag","wrapped","this","args","apply","__pluginTag","getRemarkPluginsWithoutMdx","plugins","filter","plugin","SlateEditor","DeserializeMdOptions","MarkdownPlugin","buildRules","getRemarkPluginsWithoutMdx","getMergedOptionsDeserialize","editor","options","allowedNodes","PluginAllowedNodes","allowNode","PluginAllowNode","disallowedNodes","PluginDisallowedNodes","remarkPlugins","PluginRemarkPlugins","rules","PluginRules","getOptions","mergedRules","memoize","parser","withoutMdx","splitLineBreaks","MdMdxJsxTextElement","getStyleValue","mdastNode","styleName","styleAttribute","attributes","find","attr","name","value","styles","split","style","map","s","trim","VOID_ELEMENTS","Set","BOOL_ATTRS","Map","BOOL_ATTR_REGEXES","Array","from","entries","map","htmlAttr","jsxAttr","reg","RegExp","ATTR_RENAMES","htmlToJsx","html","replace","_match","tagName","attrs","selfClosing","a","forEach","pattern","replacement","isVoid","has","toLowerCase","closing","trimEnd","Root","Descendant","getPluginKey","KEYS","MdRoot","DeserializeMdOptions","convertNodesDeserialize","mdastToSlate","node","options","buildSlateRoot","root","splitLineBreaks","children","map","child","type","value","results","startLine","position","start","line","addEmptyParagraphs","count","push","Array","from","length","text","editor","p","forEach","index","isFirstChild","isLastChild","emptyLinesBefore","transformValue","emptyLinesAfter","end","Root","Plugin","Descendant","SlateEditor","TElement","Value","getPluginKey","KEYS","TextApi","remarkParse","unified","AllowNodeConfig","MdRules","PlateType","mdastToSlate","ParseMarkdownBlocksOptions","htmlToJsx","parseMarkdownBlocks","getMergedOptionsDeserialize","markdownToSlateNodesSafely","DeserializeMdOptions","allowedNodes","allowNode","disallowedNodes","editor","memoize","parser","preserveEmptyParagraphs","remarkPlugins","rules","splitLineBreaks","withoutMdx","onError","error","Error","markdownToAstProcessor","data","options","mergedOptions","use","parse","markdownToSlateNodes","Omit","processedData","toSlateProcessor","remarkToSlate","flatMap","token","type","api","create","block","_memo","raw","processSync","result","map","deserializeMd","output","item","isText","children","p","CompileResultMap","remarkToSlateNode","compiler","node","isNameChar","c","splitIncompleteMdx","data","Frame","name","pos","stack","len","length","i","cutPos","codePointAt","tagStart","closing","nameStart","tagName","slice","toLowerCase","inQuote","selfClosing","ch","j","splice","push","firstUnmatched","Math","min","SlateEditor","ElementApi","getPluginType","KEYS","DeserializeMdOptions","markdownToSlateNodes","deserializeInlineMd","splitIncompleteMdx","markdownToSlateNodesSafely","editor","data","options","Omit","result","Array","isArray","withoutMdx","completeString","incompleteString","incompleteNodes","completeNodes","length","newBlock","children","type","p","lastBlock","at","isElement","api","isVoid","push","Token","marked","ParseMarkdownBlocksOptions","exclude","trim","parseMarkdownBlocks","content","tokens","lexer","length","filter","token","includes","type","map","raw","trimEnd","Descendant","MdRootContent","MdDecoration","DeserializeMdOptions","mdastToPlate","customMdxDeserialize","getDeserializerByKey","convertNodesDeserialize","nodes","deco","options","reduce","acc","node","shouldIncludeNode","push","buildSlateNode","mdastNode","type","result","Array","isArray","editor","nodeParser","allowedNodes","allowNode","disallowedNodes","length","Error","includes","deserialize","Descendant","MdRootContent","MdDecoration","DeserializeMdOptions","convertNodesDeserialize","convertChildrenDeserialize","children","deco","options","length","text","getPluginType","MdDelete","MdEmphasis","MdStrong","MdDecoration","DeserializeMdOptions","mdastToPlate","buildSlateNode","convertTextsDeserialize","mdastNode","deco","options","children","reduce","acc","n","key","editor","type","push","Options","RemarkStringifyOptions","Plugin","OmitFirst","PluginConfig","bindFirst","createTSlatePlugin","isUrl","KEYS","MdRules","PlateType","deserializeInlineMd","deserializeMd","serializeMd","AllowNodeConfig","deserialize","node","serialize","MarkdownConfig","allowedNodes","disallowedNodes","remarkPlugins","remarkStringifyOptions","rules","allowNode","plainMarks","markdown","deserializeInline","MarkdownPlugin","key","options","extendApi","editor","extend","api","parser","format","data","query","dataTransfer","htmlData","getData","files","length","baseRemarkMdx","REMARK_MDX_TAG","tagRemarkPlugin","remarkMdx","Node","Parent","RootContent","Text","Plugin","visit","MentionNode","children","type","value","username","displayText","StaticPhrasingContentMap","mention","remarkMention","tree","node","index","parent","url","startsWith","slice","length","decodeURIComponent","mentionNode","atMentionPattern","parts","lastIndex","text","allMatches","end","start","match","RegExpExecArray","exec","mentionStart","mentionEnd","push","sort","a","b","matchInfo","splice"],"sources":["../src/lib/types.ts","../src/lib/serializer/utils/getCustomMark.ts","../src/lib/rules/utils/parseAttributes.ts","../src/lib/rules/columnRules.ts","../src/lib/rules/fontRules.ts","../src/lib/rules/mediaRules.ts","../src/lib/serializer/utils/getMergedOptionsSerialize.ts","../src/lib/serializer/utils/getSerializerByKey.ts","../src/lib/serializer/utils/unreachable.ts","../src/lib/serializer/convertTextsSerialize.ts","../src/lib/serializer/wrapWithBlockId.ts","../src/lib/serializer/listToMdastTree.ts","../src/lib/serializer/convertNodesSerialize.ts","../src/lib/serializer/serializeInlineMd.ts","../src/lib/serializer/serializeMd.ts","../src/lib/rules/defaultRules.ts","../src/lib/deserializer/utils/getDeserializerByKey.ts","../src/lib/deserializer/utils/customMdxDeserialize.ts","../src/lib/deserializer/utils/stripMarkdown.ts","../src/lib/deserializer/utils/deserializeInlineMd.ts","../src/lib/utils/getRemarkPluginsWithoutMdx.ts","../src/lib/deserializer/utils/getMergedOptionsDeserialize.ts","../src/lib/deserializer/utils/getStyleValue.ts","../src/lib/deserializer/utils/htmlToJsx.ts","../src/lib/deserializer/mdastToSlate.ts","../src/lib/deserializer/deserializeMd.ts","../src/lib/deserializer/utils/splitIncompleteMdx.ts","../src/lib/deserializer/utils/markdownToSlateNodesSafely.ts","../src/lib/deserializer/utils/parseMarkdownBlocks.ts","../src/lib/deserializer/convertNodesDeserialize.ts","../src/lib/deserializer/convertChildrenDeserialize.ts","../src/lib/deserializer/convertTextsDeserialize.ts","../src/lib/MarkdownPlugin.ts","../src/lib/plugins/remarkMdx.ts","../src/lib/plugins/remarkMention.ts"],"sourcesContent":["export type * as unistLib from 'unist';\n\nimport type { StrictExtract } from 'ts-essentials';\n\nimport {\n type NodeKey,\n type Nullable,\n type SlateEditor,\n type TElement,\n type TNodeMap,\n type TText,\n getPluginKey,\n} from 'platejs';\n\nimport type { DeserializeMdOptions } from './deserializer';\nimport type {\n MdBlockquote,\n MdBreak,\n MdCode,\n MdDefinition,\n MdDelete,\n MdEmphasis,\n MdFootnoteDefinition,\n MdFootnoteReference,\n MdHeading,\n MdHtml,\n MdImage,\n MdImageReference,\n MdInlineCode,\n MdInlineMath,\n MdLink,\n MdLinkReference,\n MdList,\n MdMath,\n MdParagraph,\n MdRootContent,\n MdStrong,\n MdTable,\n MdTableCell,\n MdTableRow,\n MdText,\n MdThematicBreak,\n MdYaml,\n} from './mdast';\nimport type { SerializeMdOptions } from './serializer';\n\nimport 'mdast-util-mdx';\n\nexport type MdRules = Partial<{\n [K in keyof PlateNodeMap]: Nullable<MdNodeParser<K>>;\n}> &\n Record<string, Nullable<AnyNodeParser>>;\n\nexport type MdNodeParser<K extends keyof PlateNodeMap> = {\n mark?: boolean;\n deserialize?: (\n mdastNode: MdNodeMap[K],\n deco: MdDecoration,\n options: DeserializeMdOptions\n ) => PlateNodeMap[K];\n serialize?: (\n slateNode: PlateNodeMap[K],\n options: SerializeMdOptions\n ) => MdNodeMap[K];\n};\n\ntype AnyNodeParser = {\n mark?: boolean;\n deserialize?: (\n mdastNode: any,\n deco: MdDecoration,\n options: DeserializeMdOptions\n ) => any;\n serialize?: (slateNode: any, options: SerializeMdOptions) => any;\n};\n\ntype StrictMdType = MdGFM | MdRootContent['type'] | MdStyle;\n\nexport type MdType = (string & {}) | StrictMdType;\n\ntype MdGFM = 'del' | 'mark' | 'sub' | 'sup' | 'u';\n\ntype MdStyle =\n | 'backgroundColor'\n | 'color'\n | 'fontFamily'\n | 'fontSize'\n | 'fontWeight';\n\nexport type MdMark = MdDelete | MdEmphasis | MdInlineCode | MdStrong | MdText;\n\nexport type MdDecoration = Readonly<\n Partial<\n Record<\n | (string & {})\n | (MdDelete | MdEmphasis | MdInlineCode | MdStrong)['type']\n | MdStyle\n | 'underline',\n boolean | string\n >\n >\n>;\n\nexport type StrictPlateType =\n | StrictExtract<\n NodeKey,\n | 'a'\n | 'blockquote'\n | 'bold'\n | 'callout'\n | 'code'\n | 'code_block'\n | 'code_line'\n | 'column'\n | 'column_group'\n | 'comment'\n | 'date'\n | 'equation'\n | 'hr'\n | 'img'\n | 'inline_equation'\n | 'italic'\n | 'li'\n | 'mention'\n | 'p'\n | 'strikethrough'\n | 'subscript'\n | 'suggestion'\n | 'superscript'\n | 'table'\n | 'td'\n | 'th'\n | 'toc'\n | 'toggle'\n | 'tr'\n | 'underline'\n >\n | 'heading'\n | 'list'\n | 'text';\n\nexport type PlateType = (string & {}) | StrictPlateType;\n\ntype PlateNodeMap = Pick<\n TNodeMap,\n | 'a'\n | 'audio'\n | 'blockquote'\n | 'bold'\n | 'callout'\n | 'code'\n | 'code_block'\n | 'column'\n | 'column_group'\n | 'comment'\n | 'date'\n | 'equation'\n | 'file'\n | 'hr'\n | 'img'\n | 'inline_equation'\n | 'italic'\n | 'mention'\n | 'p'\n | 'strikethrough'\n | 'subscript'\n | 'suggestion'\n | 'superscript'\n | 'table'\n | 'td'\n | 'th'\n | 'toc'\n | 'toggle'\n | 'tr'\n | 'underline'\n | 'video'\n> & {\n /** Markdown only */\n text: TText;\n list: any;\n heading: TElement;\n footnoteReference: any;\n definition: any;\n footnoteDefinition: any;\n break: any;\n yaml: any;\n imageReference: any;\n linkReference: any;\n html: any;\n};\n\ntype MdNodeMap = {\n /** Common Elements */\n a: MdLink;\n blockquote: MdBlockquote;\n code_block: MdCode;\n equation: MdMath;\n heading: MdHeading;\n hr: MdThematicBreak;\n img: MdImage;\n inline_equation: MdInlineMath;\n p: MdParagraph;\n table: MdTable;\n td: MdTableCell;\n th: MdTableCell;\n tr: MdTableRow;\n list: MdList;\n\n /** Common Marks */\n bold: MdStrong;\n italic: MdEmphasis;\n code: MdInlineCode;\n text: MdText;\n strikethrough: MdDelete;\n\n /** Markdown only */\n footnoteReference: MdFootnoteReference;\n definition: MdDefinition;\n footnoteDefinition: MdFootnoteDefinition;\n break: MdBreak;\n yaml: MdYaml;\n imageReference: MdImageReference;\n linkReference: MdLinkReference;\n html: MdHtml;\n\n /** Plate only */\n column_group: any;\n column: any;\n toc: any;\n callout: any;\n toggle: any;\n mention: any;\n date: any;\n underline: any;\n comment: any;\n superscript: any;\n subscript: any;\n suggestion: any;\n file: any;\n video: any;\n audio: any;\n};\n\nconst PLATE_TO_MDAST = {\n a: 'link',\n blockquote: 'blockquote',\n bold: 'strong',\n callout: 'callout',\n code: 'inlineCode',\n code_block: 'code',\n code_line: 'code_line',\n column: 'column',\n column_group: 'column_group',\n comment: 'comment',\n date: 'date',\n equation: 'math',\n heading: 'heading',\n hr: 'thematicBreak',\n img: 'image',\n inline_equation: 'inlineMath',\n italic: 'emphasis',\n li: 'listItem',\n list: 'list',\n mention: 'mention',\n p: 'paragraph',\n strikethrough: 'delete',\n subscript: 'sub',\n suggestion: 'suggestion',\n superscript: 'sup',\n table: 'table',\n td: 'tableCell',\n text: 'text',\n th: 'tableCell',\n toc: 'toc',\n toggle: 'toggle',\n tr: 'tableRow',\n underline: 'u',\n} as const satisfies Record<StrictPlateType, MdType>;\n\nconst MDAST_TO_PLATE = {\n backgroundColor: 'backgroundColor',\n blockquote: 'blockquote',\n break: 'break',\n code: 'code_block',\n color: 'color',\n definition: 'definition',\n del: 'strikethrough',\n delete: 'strikethrough',\n emphasis: 'italic',\n fontFamily: 'fontFamily',\n fontSize: 'fontSize',\n fontWeight: 'fontWeight',\n footnoteDefinition: 'footnoteDefinition',\n footnoteReference: 'footnoteReference',\n heading: 'heading',\n html: 'html',\n image: 'img',\n imageReference: 'imageReference',\n inlineCode: 'code',\n inlineMath: 'inline_equation',\n link: 'a',\n linkReference: 'linkReference',\n list: 'list',\n listItem: 'li',\n mark: 'highlight',\n math: 'equation',\n mdxFlowExpression: 'mdxFlowExpression',\n mdxjsEsm: 'mdxjsEsm',\n mdxJsxFlowElement: 'mdxJsxFlowElement',\n mdxJsxTextElement: 'mdxJsxTextElement',\n mdxTextExpression: 'mdxTextExpression',\n paragraph: 'p',\n strong: 'bold',\n sub: 'subscript',\n sup: 'superscript',\n table: 'table',\n tableCell: 'td',\n tableRow: 'tr',\n text: 'text',\n thematicBreak: 'hr',\n u: 'underline',\n yaml: 'yaml',\n} as const satisfies Record<StrictMdType, PlateType>;\n\n/**\n * Get plate node type from mdast node type if the mdast is mdast only return\n * the mdast type itself.\n */\nexport const mdastToPlate = <T extends StrictMdType>(\n editor: SlateEditor,\n mdastType: T\n) => {\n const plateKey = MDAST_TO_PLATE[mdastType];\n\n return getPluginKey(editor, plateKey) ?? plateKey ?? mdastType;\n};\n\n/**\n * Get mdast node type from plate element type if the plateType is plate only\n * return the plateType itself.\n */\nexport const plateToMdast = <T extends StrictPlateType>(plateType: T) =>\n PLATE_TO_MDAST[plateType] ?? plateType;\n","import type { SerializeMdOptions } from '../serializeMd';\n\nexport const getCustomMark = (options?: SerializeMdOptions): string[] => {\n if (!options?.rules) {\n return [];\n }\n\n return Object.entries(options.rules)\n .filter(([_, parser]) => parser?.mark)\n .map(([key]) => key);\n};\n","// Helper function to parse JSON attributes to props\nexport function parseAttributes(attributes: any[]): Record<string, any> {\n const props: Record<string, any> = {};\n\n if (attributes && attributes.length > 0) {\n attributes.forEach((attr: any) => {\n if (attr.name && attr.value !== undefined) {\n let value = attr.value;\n\n try {\n value = JSON.parse(attr.value);\n } catch (_error) {\n value = attr.value;\n }\n\n props[attr.name] = value;\n }\n });\n }\n\n return props;\n}\n\n// Helper function to convert props to attributes\nexport function propsToAttributes(props: Record<string, any>): any[] {\n return Object.entries(props).map(([name, value]) => ({\n name,\n type: 'mdxJsxAttribute',\n value: typeof value === 'string' ? value : JSON.stringify(value),\n }));\n}\n","import { getPluginType, KEYS } from 'platejs';\n\nimport type { MdRules } from '../types';\n\nimport { convertChildrenDeserialize } from '../deserializer/convertChildrenDeserialize';\nimport { convertNodesSerialize } from '../serializer';\nimport { parseAttributes, propsToAttributes } from './utils';\n\nexport const columnRules: MdRules = {\n column: {\n deserialize: (mdastNode, deco, options) => {\n const props = parseAttributes(mdastNode.attributes);\n return {\n children: convertChildrenDeserialize(\n mdastNode.children,\n { ...deco },\n options\n ) as any,\n type: getPluginType(options.editor!, KEYS.column),\n ...props,\n } as any;\n },\n serialize: (node, options) => {\n const { id, children, type, ...rest } = node;\n\n return {\n attributes: propsToAttributes(rest),\n children: convertNodesSerialize(children, options) as any,\n name: type,\n type: 'mdxJsxFlowElement',\n };\n },\n },\n column_group: {\n deserialize: (mdastNode, deco, options) => {\n const props = parseAttributes(mdastNode.attributes);\n\n return {\n children: convertChildrenDeserialize(\n mdastNode.children,\n { ...deco },\n options\n ) as any,\n type: getPluginType(options.editor!, KEYS.columnGroup) as any,\n ...props,\n };\n },\n serialize: (node, options) => {\n const { id, children, type, ...rest } = node;\n\n return {\n attributes: propsToAttributes(rest),\n children: convertNodesSerialize(children, options) as any,\n name: type,\n type: 'mdxJsxFlowElement',\n };\n },\n },\n};\n","import kebabCase from 'lodash/kebabCase.js';\n\nimport type { MdMdxJsxTextElement } from '../mdast';\nimport type { MdRules } from '../types';\n\nimport { convertChildrenDeserialize, getStyleValue } from '../deserializer';\n\nfunction createFontRule(propName: string) {\n const styleName = kebabCase(propName);\n\n return {\n mark: true,\n serialize: (slateNode: any): MdMdxJsxTextElement => ({\n attributes: [\n {\n name: 'style',\n type: 'mdxJsxAttribute',\n value: `${styleName}: ${slateNode[propName]};`,\n },\n ],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'span',\n type: 'mdxJsxTextElement',\n }),\n };\n}\n\nexport const fontRules: MdRules = {\n backgroundColor: createFontRule('backgroundColor'),\n color: createFontRule('color'),\n fontFamily: createFontRule('fontFamily'),\n fontSize: createFontRule('fontSize'),\n fontWeight: createFontRule('fontWeight'),\n span: {\n mark: true,\n deserialize: (mdastNode: MdMdxJsxTextElement, deco: any, options: any) => {\n const fontFamily = getStyleValue(mdastNode, 'font-family');\n const fontSize = getStyleValue(mdastNode, 'font-size');\n const fontWeight = getStyleValue(mdastNode, 'font-weight');\n const color = getStyleValue(mdastNode, 'color');\n const backgroundColor = getStyleValue(mdastNode, 'background-color');\n\n return convertChildrenDeserialize(\n mdastNode.children,\n {\n ...deco,\n backgroundColor,\n color,\n fontFamily,\n fontSize,\n fontWeight,\n },\n options\n ) as any;\n },\n },\n};\n","import type { TMediaElement } from 'platejs';\n\nimport type { MdMdxJsxFlowElement } from '../mdast';\nimport type { MdRules } from '../types';\n\nimport { convertNodesSerialize } from '../serializer';\nimport { parseAttributes, propsToAttributes } from './utils';\n\nfunction createMediaRule() {\n return {\n deserialize: (node: MdMdxJsxFlowElement): TMediaElement => {\n const { src, ...props } = parseAttributes(node.attributes);\n\n return {\n children: [{ text: '' }],\n type: node.name!,\n url: src,\n ...props,\n } as TMediaElement;\n },\n serialize: (node: TMediaElement, options: any) => {\n const { id, children, type, url, ...rest } = node;\n\n return {\n attributes: propsToAttributes({ ...rest, src: url }),\n children: convertNodesSerialize(children, options) as any,\n name: type,\n type: 'mdxJsxFlowElement',\n };\n },\n };\n}\n\nexport const mediaRules: MdRules = {\n audio: createMediaRule(),\n file: createMediaRule(),\n video: createMediaRule(),\n};\n","import type { SlateEditor } from 'platejs';\n\nimport type { SerializeMdOptions } from '../serializeMd';\n\nimport { MarkdownPlugin } from '../../MarkdownPlugin';\nimport { buildRules } from '../../rules';\n\n/**\n * Merges Markdown configurations, following the principle that options take\n * precedence\n *\n * @param editor Editor instance used to get plugin default configurations\n * @param options User-provided options (higher priority)\n * @returns The final merged configuration\n */\nexport const getMergedOptionsSerialize = (\n editor: SlateEditor,\n options?: SerializeMdOptions\n): SerializeMdOptions => {\n const {\n allowedNodes: PluginAllowedNodes,\n allowNode: PluginAllowNode,\n disallowedNodes: PluginDisallowedNodes,\n plainMarks: PluginPlainMarks,\n remarkPlugins: PluginRemarkPlugins,\n remarkStringifyOptions: PluginRemarkStringifyOptions,\n rules: PluginRules,\n } = editor.getOptions(MarkdownPlugin);\n\n const mergedRules = {\n ...buildRules(editor),\n ...(options?.rules ?? PluginRules),\n };\n\n return {\n allowedNodes: options?.allowedNodes ?? PluginAllowedNodes,\n allowNode: options?.allowNode ?? PluginAllowNode,\n disallowedNodes: options?.disallowedNodes ?? PluginDisallowedNodes,\n editor,\n plainMarks: options?.plainMarks ?? PluginPlainMarks,\n preserveEmptyParagraphs: options?.preserveEmptyParagraphs,\n remarkPlugins: options?.remarkPlugins ?? PluginRemarkPlugins ?? [],\n remarkStringifyOptions:\n options?.remarkStringifyOptions ?? PluginRemarkStringifyOptions,\n rules: mergedRules,\n spread: options?.spread,\n value: options?.value ?? editor.children,\n withBlockId: options?.withBlockId ?? false,\n };\n};\n","import type { SerializeMdOptions } from '../serializeMd';\n\nimport { buildRules } from '../../rules/defaultRules';\n\nexport const getSerializerByKey = (\n key: string,\n options: SerializeMdOptions\n) => {\n const nodes = options.rules;\n\n const rules = buildRules(options.editor!);\n\n return nodes?.[key]?.serialize === undefined\n ? rules[key]?.serialize\n : nodes?.[key]?.serialize;\n};\n","export const unreachable = (value: any) => {\n console.warn(`Unreachable code: ${JSON.stringify(value)}`);\n};\n","import { type TText, getPluginType } from 'platejs';\n\nimport type { MdMark } from '../types';\nimport type { SerializeMdOptions } from './serializeMd';\n\nimport { getCustomMark } from './utils';\nimport { getSerializerByKey } from './utils/getSerializerByKey';\n\n// inlineCode should be last because of the spec in mdast\n// https://github.com/inokawa/remark-slate-transformer/issues/145\nexport const basicMarkdownMarks = ['italic', 'bold', 'strikethrough', 'code'];\n\nexport const convertTextsSerialize = (\n slateTexts: readonly TText[],\n options: SerializeMdOptions,\n _key?: string\n): MdMark[] => {\n const customLeaf: string[] = getCustomMark(options);\n\n const mdastTexts: MdMark[] = [];\n\n const starts: string[] = [];\n let ends: string[] = [];\n\n let textTemp = '';\n for (let j = 0; j < slateTexts.length; j++) {\n const cur = slateTexts[j]!;\n textTemp += cur.text;\n\n const prevStarts = starts.slice();\n const prevEnds = ends.slice();\n\n const prev = slateTexts[j - 1];\n const next = slateTexts[j + 1];\n ends = [];\n (\n [\n ...basicMarkdownMarks,\n // exclude repeated marks\n ...customLeaf.filter((k) => !basicMarkdownMarks.includes(k)),\n ] as const\n ).forEach((key) => {\n const nodeType = getPluginType(options.editor!, key);\n\n if (cur[nodeType]) {\n // Skip marks that should be treated as plain text\n if (options.plainMarks?.includes(key)) {\n return;\n }\n\n if (!prev?.[nodeType]) {\n starts.push(key);\n }\n if (!next?.[nodeType]) {\n ends.push(key);\n }\n }\n });\n\n const endsToRemove = starts.reduce<{ key: string; index: number }[]>(\n (acc, k, kIndex) => {\n if (ends.includes(k)) {\n acc.push({ key: k, index: kIndex });\n }\n return acc;\n },\n []\n );\n\n if (starts.length > 0) {\n let bef = '';\n let aft = '';\n if (\n endsToRemove.length === 1 &&\n (prevStarts.toString() !== starts.toString() ||\n // https://github.com/inokawa/remark-slate-transformer/issues/90\n (prevEnds.includes('italic') && ends.includes('bold'))) &&\n starts.length - endsToRemove.length === 0\n ) {\n while (textTemp.startsWith(' ')) {\n bef += ' ';\n textTemp = textTemp.slice(1);\n }\n while (textTemp.endsWith(' ')) {\n aft += ' ';\n textTemp = textTemp.slice(0, -1);\n }\n }\n let res: MdMark = {\n type: 'text',\n value: textTemp,\n };\n textTemp = '';\n starts\n .slice()\n .reverse()\n .forEach((k) => {\n const nodeParser = getSerializerByKey(k, options);\n\n if (nodeParser) {\n const node = nodeParser(cur, options) as any;\n res = {\n ...node,\n children: [res],\n };\n }\n\n switch (k) {\n case 'bold': {\n res = {\n children: [res],\n type: 'strong',\n };\n break;\n }\n case 'code': {\n let currentRes = res;\n while (\n currentRes.type !== 'text' &&\n currentRes.type !== 'inlineCode'\n ) {\n currentRes = currentRes.children[0] as MdMark;\n }\n currentRes.type = 'inlineCode';\n\n break;\n }\n case 'italic': {\n res = {\n children: [res],\n type: 'emphasis',\n };\n break;\n }\n case 'strikethrough': {\n res = {\n children: [res],\n type: 'delete',\n };\n break;\n }\n }\n });\n const arr: MdMark[] = [];\n if (bef.length > 0) {\n arr.push({ type: 'text', value: bef });\n }\n arr.push(res);\n if (aft.length > 0) {\n arr.push({ type: 'text', value: aft });\n }\n mdastTexts.push(...arr);\n }\n\n if (endsToRemove.length > 0) {\n endsToRemove.reverse().forEach((e) => {\n starts.splice(e.index, 1);\n });\n } else {\n mdastTexts.push({ type: 'text', value: textTemp });\n textTemp = '';\n }\n }\n if (textTemp) {\n mdastTexts.push({ type: 'text', value: textTemp });\n textTemp = '';\n }\n\n const mergedTexts = mergeTexts(mdastTexts);\n\n const flattenedEmptyNodes = mergedTexts.map((node) => {\n if (!hasContent(node)) {\n return { type: 'text', value: '' } as MdMark;\n }\n return node;\n });\n\n return flattenedEmptyNodes;\n};\n\nconst hasContent = (node: MdMark): boolean => {\n if (node.type === 'inlineCode') {\n // inline has no children - no deeper search needed\n return node.value !== '';\n }\n\n if (node.type === 'text') {\n // inline has no children - no deeper search needed\n return node.value !== '';\n }\n\n if (node.children?.length > 0) {\n for (const child of node.children) {\n // all types other then emphasis are represented with some characters that can also be formatted\n if (\n child.type !== 'emphasis' &&\n child.type !== 'strong' &&\n child.type !== 'inlineCode' &&\n child.type !== 'delete' &&\n child.type !== 'text'\n ) {\n return true;\n }\n if (hasContent(child)) {\n return true;\n }\n }\n }\n return false;\n};\n\nconst mergeTexts = (nodes: MdMark[]): MdMark[] => {\n const res: MdMark[] = [];\n for (const cur of nodes) {\n const last = res.at(-1);\n if (last && last.type === cur.type) {\n if (last.type === 'text') {\n last.value += (cur as typeof last).value;\n } else if (last.type === 'inlineCode') {\n last.value += (cur as typeof last).value;\n } else {\n last.children = mergeTexts(\n last.children.concat((cur as typeof last).children) as MdMark[]\n );\n }\n } else {\n if (cur.type === 'text' && cur.value === '') continue;\n res.push(cur);\n }\n }\n return res;\n};\n","import type { unistLib } from '../types';\n\n/**\n * Wraps an mdast node with a block element containing an ID attribute. Used for\n * preserving block IDs when serializing to markdown.\n *\n * @param mdastNode - The mdast node to wrap\n * @param nodeId - The ID to attach to the block element\n * @returns The wrapped mdast node with block element and ID attribute\n */\nexport const wrapWithBlockId = (\n mdastNode: unistLib.Node,\n nodeId: string\n): unistLib.Node =>\n ({\n attributes: [\n {\n name: 'id',\n type: 'mdxJsxAttribute',\n value: String(nodeId),\n },\n ],\n children: [mdastNode],\n data: {\n _mdxExplicitJsx: true,\n },\n name: 'block',\n type: 'mdxJsxFlowElement',\n }) as any;\n","import type { TListElement } from 'platejs';\n\nimport type { MdList, MdListItem, MdParagraph } from '../mdast';\nimport type { SerializeMdOptions } from './serializeMd';\n\nimport { convertNodesSerialize } from './convertNodesSerialize';\nimport { wrapWithBlockId } from './wrapWithBlockId';\n\nexport function listToMdastTree(\n nodes: TListElement[],\n options: SerializeMdOptions,\n isBlock = false\n): any {\n if (nodes.length === 0) {\n throw new Error('Cannot create a list from empty nodes');\n }\n\n // If withBlockId is enabled, isBlock is true, and any node has an ID,\n // we need to wrap each list item separately\n if (options.withBlockId && isBlock && nodes.some((node) => node.id)) {\n return processListWithBlockIds(nodes, options);\n }\n\n // Normal list processing\n const root: MdList = {\n children: [],\n ordered: nodes[0].listStyleType === 'decimal',\n spread: options.spread ?? false,\n start: nodes[0].listStart,\n type: 'list',\n };\n\n // Stack to track parent nodes at different indentation levels\n const indentStack: {\n indent: number;\n list: MdList;\n parent: MdListItem | null;\n styleType: TListElement['listStyleType'];\n }[] = [\n {\n indent: nodes[0].indent,\n list: root,\n parent: null,\n styleType: nodes[0].listStyleType,\n },\n ];\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n const currentIndent = node.indent;\n\n // Find the appropriate parent list for the current indentation level\n while (\n indentStack.length > 1 &&\n indentStack.at(-1)!.indent > currentIndent\n ) {\n indentStack.pop();\n }\n\n let stackTop = indentStack.at(-1);\n if (!stackTop) {\n throw new Error('Stack should never be empty');\n }\n\n const hasSameIndentStyleChange =\n stackTop.indent === currentIndent &&\n stackTop.styleType !== node.listStyleType &&\n !!stackTop.parent;\n\n if (hasSameIndentStyleChange) {\n // Split sibling list when style switches at same indent\n const siblingList: MdList = {\n children: [],\n ordered: node.listStyleType === 'decimal',\n spread: options.spread ?? false,\n start: node.listStart,\n type: 'list',\n };\n\n // Attach sibling list under the same parent item\n stackTop.parent!.children.push(siblingList);\n\n indentStack[indentStack.length - 1] = {\n indent: currentIndent,\n list: siblingList,\n parent: stackTop.parent,\n styleType: node.listStyleType,\n };\n\n stackTop = indentStack.at(-1)!;\n }\n\n // Create the current list item\n const listItem: MdListItem = {\n checked: null,\n children: [\n {\n children: convertNodesSerialize(\n node.children,\n options\n ) as MdParagraph['children'],\n type: 'paragraph',\n },\n ],\n type: 'listItem',\n } as any;\n\n // Add spread property to list items when spread is true\n if (options.spread) {\n (listItem as any).spread = true;\n }\n\n // Add checked property for todo lists\n if (node.listStyleType === 'todo' && node.checked !== undefined) {\n listItem.checked = node.checked;\n }\n\n // Add the list item to the appropriate parent list\n stackTop.list.children.push(listItem);\n\n // Check if the next node has a higher indentation level\n const nextNode = nodes[i + 1];\n if (nextNode && nextNode.indent > currentIndent) {\n // Create a new nested list for the next indentation level\n const nestedList: MdList = {\n children: [],\n ordered: nextNode.listStyleType === 'decimal',\n spread: options.spread ?? false,\n start: nextNode.listStart,\n type: 'list',\n };\n\n // Add the nested list to the current list item\n listItem.children.push(nestedList);\n\n // Push the new indentation level to the stack\n indentStack.push({\n indent: nextNode.indent,\n list: nestedList,\n parent: listItem,\n styleType: nextNode.listStyleType,\n });\n }\n }\n\n return root;\n}\n\n/**\n * Process list nodes with block IDs by wrapping each item separately This\n * preserves list numbering while allowing individual block wrapping\n */\nfunction processListWithBlockIds(\n nodes: TListElement[],\n options: SerializeMdOptions\n): { children: any[]; type: string } {\n const fragments: any[] = [];\n\n // Process each node individually\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n\n // Create a single-item list for this node\n const singleList: MdList = {\n children: [],\n ordered: node.listStyleType === 'decimal',\n spread: options.spread ?? false,\n // For ordered lists, preserve the correct number\n start: node.listStyleType === 'decimal' ? i + 1 : undefined,\n type: 'list',\n };\n\n // Create the list item\n const listItem: MdListItem = {\n checked: null,\n children: [\n {\n children: convertNodesSerialize(\n node.children,\n options\n ) as MdParagraph['children'],\n type: 'paragraph',\n },\n ],\n type: 'listItem',\n } as any;\n\n // Add spread property to list items when spread is true\n if (options.spread) {\n (listItem as any).spread = true;\n }\n\n // Add checked property for todo lists\n if (node.listStyleType === 'todo' && node.checked !== undefined) {\n listItem.checked = node.checked;\n }\n\n singleList.children.push(listItem);\n\n // Wrap with block ID if this node has one\n if (node.id) {\n fragments.push(wrapWithBlockId(singleList, String(node.id)));\n } else {\n fragments.push(singleList);\n }\n }\n\n // Return a fragment containing all wrapped lists\n return {\n children: fragments,\n type: 'fragment',\n };\n}\n","import {\n type Descendant,\n type TElement,\n type TText,\n getPluginKey,\n getPluginType,\n KEYS,\n TextApi,\n} from 'platejs';\n\nimport type { unistLib } from '../types';\nimport type { SerializeMdOptions } from './serializeMd';\n\nimport { convertTextsSerialize } from './convertTextsSerialize';\nimport { listToMdastTree } from './listToMdastTree';\nimport { unreachable } from './utils';\nimport { getSerializerByKey } from './utils/getSerializerByKey';\nimport { wrapWithBlockId } from './wrapWithBlockId';\n\nexport const convertNodesSerialize = (\n nodes: Descendant[],\n options: SerializeMdOptions,\n isBlock = false\n): unistLib.Node[] => {\n const mdastNodes: unistLib.Node[] = [];\n let textQueue: TText[] = [];\n\n const listBlock: TElement[] = [];\n\n for (let i = 0; i <= nodes.length; i++) {\n const n = nodes[i] as any;\n\n if (n && TextApi.isText(n)) {\n // Only add text nodes that pass the filtering\n if (shouldIncludeText(n, options)) {\n textQueue.push(n);\n }\n } else {\n if (textQueue.length > 0) {\n mdastNodes.push(\n ...(convertTextsSerialize(\n textQueue,\n options\n ) as any as unistLib.Node[])\n );\n }\n textQueue = [];\n if (!n) continue;\n\n // Skip this node if it doesn't pass the filtering\n if (!shouldIncludeNode(n, options)) {\n continue;\n }\n\n const pType = getPluginType(options.editor!, KEYS.p) ?? KEYS.p;\n\n if (n?.type === pType && 'listStyleType' in n) {\n listBlock.push(n);\n\n const next = nodes[i + 1] as TElement;\n const isNextIndent =\n next && next.type === pType && 'listStyleType' in next;\n const firstList = listBlock.at(0);\n const hasDifferentListStyle =\n isNextIndent &&\n firstList &&\n next.listStyleType !== firstList.listStyleType &&\n next.indent === firstList.indent;\n\n if (!isNextIndent || hasDifferentListStyle) {\n // Pass the original nodes and isBlock flag to listToMdastTree\n // so it can handle wrapping individual items with block IDs\n const result = listToMdastTree(listBlock as any, options, isBlock);\n\n // Handle fragment type (used when list items have IDs)\n if (result.type === 'fragment') {\n mdastNodes.push(...result.children);\n } else {\n mdastNodes.push(result);\n }\n\n listBlock.length = 0;\n }\n } else {\n const node = buildMdastNode(n, options, isBlock);\n\n if (node) {\n mdastNodes.push(node as unistLib.Node);\n }\n }\n }\n }\n\n return mdastNodes;\n};\n\nexport const buildMdastNode = (\n node: any,\n options: SerializeMdOptions,\n isBlock = false\n) => {\n const editor = options.editor!;\n\n let key = getPluginKey(editor, node.type) ?? node.type;\n\n if (KEYS.heading.includes(key)) {\n key = 'heading';\n }\n\n if (key === KEYS.olClassic || key === KEYS.ulClassic) {\n key = 'list';\n }\n\n const nodeParser = getSerializerByKey(key, options);\n\n if (nodeParser) {\n const mdastNode = nodeParser(node, options);\n\n // If withBlockId is enabled and the node has an ID, wrap it\n // But only wrap if isBlock is true (top-level elements only)\n if (options.withBlockId && node.id && isBlock) {\n return wrapWithBlockId(mdastNode, node.id);\n }\n\n return mdastNode;\n }\n\n unreachable(node);\n};\n\nconst shouldIncludeText = (\n text: TText,\n options: SerializeMdOptions\n): boolean => {\n const { allowedNodes, allowNode, disallowedNodes } = options;\n\n // First check allowedNodes/disallowedNodes\n if (\n allowedNodes &&\n disallowedNodes &&\n allowedNodes.length > 0 &&\n disallowedNodes.length > 0\n ) {\n throw new Error('Cannot combine allowedNodes with disallowedNodes');\n }\n\n // Check text properties against allowedNodes/disallowedNodes\n for (const [key, value] of Object.entries(text)) {\n if (key === 'text') continue;\n\n if (allowedNodes) {\n // If allowedNodes is specified, only include if the mark is in allowedNodes\n if (!allowedNodes.includes(key) && value) {\n return false;\n }\n } else if (disallowedNodes?.includes(key) && value) {\n // If using disallowedNodes, exclude if the mark is in disallowedNodes\n return false;\n }\n }\n\n // Finally, check allowNode if provided\n if (allowNode?.serialize) {\n return allowNode.serialize(text);\n }\n\n return true;\n};\n\nconst shouldIncludeNode = (\n node: TElement,\n options: SerializeMdOptions\n): boolean => {\n const { allowedNodes, allowNode, disallowedNodes } = options;\n\n if (!node.type) return true;\n\n // First check allowedNodes/disallowedNodes\n if (\n allowedNodes &&\n disallowedNodes &&\n allowedNodes.length > 0 &&\n disallowedNodes.length > 0\n ) {\n throw new Error('Cannot combine allowedNodes with disallowedNodes');\n }\n\n if (allowedNodes) {\n // If allowedNodes is specified, only include if the type is in allowedNodes\n if (!allowedNodes.includes(node.type)) {\n return false;\n }\n } else if (disallowedNodes?.includes(node.type)) {\n // If using disallowedNodes, exclude if the type is in disallowedNodes\n return false;\n }\n\n // Finally, check allowNode if provided\n if (allowNode?.serialize) {\n return allowNode.serialize(node);\n }\n\n return true;\n};\n","import type { SlateEditor } from 'platejs';\n\nimport remarkStringify from 'remark-stringify';\nimport { unified } from 'unified';\n\nimport type { SerializeMdOptions } from './serializeMd';\n\nimport { convertTextsSerialize } from './convertTextsSerialize';\nimport { getMergedOptionsSerialize } from './utils';\n\nexport const serializeInlineMd = (\n editor: SlateEditor,\n options?: SerializeMdOptions\n) => {\n const mergedOptions = getMergedOptionsSerialize(editor, options);\n\n const toRemarkProcessor = unified()\n .use(mergedOptions.remarkPlugins ?? [])\n .use(remarkStringify, {\n emphasis: '_',\n ...mergedOptions?.remarkStringifyOptions,\n });\n\n if (options?.value?.length === 0) return '';\n\n const convertedTexts = convertTextsSerialize(mergedOptions.value as any, {\n editor,\n });\n\n // Serialize the content\n const serializedContent = toRemarkProcessor.stringify({\n children: convertedTexts,\n type: 'root',\n });\n\n return serializedContent;\n};\n","import type { Descendant, SlateEditor } from 'platejs';\n\nimport remarkStringify, {\n type Options as RemarkStringifyOptions,\n} from 'remark-stringify';\nimport { type Plugin, unified } from 'unified';\n\nimport type { AllowNodeConfig } from '../MarkdownPlugin';\nimport type { MdRoot } from '../mdast';\nimport type { MdRules, PlateType } from '../types';\n\nimport { convertNodesSerialize } from './convertNodesSerialize';\nimport { getMergedOptionsSerialize } from './utils/getMergedOptionsSerialize';\n\nexport type SerializeMdOptions = {\n allowedNodes?: PlateType[] | null;\n allowNode?: AllowNodeConfig;\n disallowedNodes?: PlateType[] | null;\n editor?: SlateEditor;\n /** Marks to treat as plain text without applying markdown formatting. */\n plainMarks?: PlateType[] | null;\n preserveEmptyParagraphs?: boolean;\n remarkPlugins?: Plugin[];\n remarkStringifyOptions?: RemarkStringifyOptions | null;\n rules?: MdRules;\n spread?: boolean;\n value?: Descendant[];\n withBlockId?: boolean;\n};\n\n/** Serialize the editor value to Markdown. */\nexport const serializeMd = (\n editor: SlateEditor,\n options?: Omit<SerializeMdOptions, 'editor'>\n) => {\n const mergedOptions = getMergedOptionsSerialize(editor, options);\n\n const { remarkPlugins, value } = mergedOptions;\n\n const toRemarkProcessor = unified()\n .use(remarkPlugins ?? [])\n .use(remarkStringify, {\n emphasis: '_',\n ...mergedOptions?.remarkStringifyOptions,\n });\n\n const mdast = slateToMdast({\n children: value!,\n options: mergedOptions,\n });\n\n return toRemarkProcessor.stringify(mdast);\n};\n\nconst slateToMdast = ({\n children,\n options,\n}: {\n children: Descendant[];\n options: SerializeMdOptions;\n}): MdRoot => {\n const processedChildren = convertNodesSerialize(\n children,\n options,\n true // isBlock = true for top-level elements\n ) as MdRoot['children'];\n\n const ast = {\n children: processedChildren,\n type: 'root',\n } as MdRoot;\n return ast;\n};\n","import {\n type SlateEditor,\n type TElement,\n type TListElement,\n type TMentionElement,\n type TText,\n getPluginKey,\n getPluginType,\n KEYS,\n} from 'platejs';\n\nimport type {\n MdHeading,\n MdImage,\n MdLink,\n MdList,\n MdMdxJsxFlowElement,\n MdMdxJsxTextElement,\n MdParagraph,\n MdRootContent,\n MdTable,\n MdTableCell,\n MdTableRow,\n} from '../mdast';\nimport type { MentionNode } from '../plugins/remarkMention';\nimport type { MdRules } from '../types';\n\nimport {\n buildSlateNode,\n convertChildrenDeserialize,\n convertTextsDeserialize,\n} from '../deserializer';\nimport { convertNodesSerialize } from '../serializer';\nimport { columnRules } from './columnRules';\nimport { fontRules } from './fontRules';\nimport { mediaRules } from './mediaRules';\nimport { parseAttributes, propsToAttributes } from './utils';\n\nconst LEADING_NEWLINE_REGEX = /^\\n/;\n\nfunction isBoolean(value: any) {\n return (\n value === true ||\n value === false ||\n (!!value &&\n typeof value === 'object' &&\n Object.prototype.toString.call(value) === '[object Boolean]')\n );\n}\n\nexport const defaultRules: MdRules = {\n a: {\n deserialize: (mdastNode, deco, options) => ({\n children: convertChildrenDeserialize(mdastNode.children, deco, options),\n type: getPluginType(options.editor!, KEYS.a),\n url: mdastNode.url,\n }),\n serialize: (node, options) => ({\n children: convertNodesSerialize(\n node.children,\n options\n ) as MdLink['children'],\n type: 'link',\n url: node.url,\n }),\n },\n blockquote: {\n deserialize: (mdastNode, deco, options) => {\n const children =\n mdastNode.children.length > 0\n ? mdastNode.children.flatMap((paragraph, index, children) => {\n if (paragraph.type === 'paragraph') {\n if (children.length > 1 && children.length - 1 !== index) {\n // add a line break between the paragraphs\n const paragraphChildren = convertChildrenDeserialize(\n paragraph.children,\n deco,\n options\n );\n paragraphChildren.push({ text: '\\n' }, { text: '\\n' });\n return paragraphChildren;\n }\n return convertChildrenDeserialize(\n paragraph.children,\n deco,\n options\n );\n }\n\n if ('children' in paragraph) {\n return convertChildrenDeserialize(\n paragraph.children,\n deco,\n options\n );\n }\n\n return [{ text: '' }];\n })\n : [{ text: '' }];\n\n const flattenedChildren = children.flatMap((child: any) =>\n child.type === 'blockquote' ? child.children : [child]\n );\n\n return {\n children: flattenedChildren,\n type: getPluginType(options.editor!, KEYS.blockquote),\n };\n },\n serialize: (node, options) => {\n const nodes = [] as any;\n\n for (const child of node.children) {\n if (child.text === '\\n') {\n nodes.push({\n type: 'break',\n });\n } else {\n nodes.push(child);\n }\n }\n\n const paragraphChildren = convertNodesSerialize(\n nodes,\n options\n ) as MdParagraph['children'];\n\n if (\n paragraphChildren.length > 0 &&\n paragraphChildren.at(-1)!.type === 'break'\n ) {\n // if the last child of the paragraph is a line break add an additional one\n\n paragraphChildren.at(-1)!.type = 'html';\n // @ts-expect-error -- value is ok\n paragraphChildren.at(-1)!.value = '\\n<br />';\n }\n\n return {\n children: [\n {\n children: paragraphChildren,\n type: 'paragraph',\n },\n ],\n type: 'blockquote',\n };\n },\n },\n bold: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertTextsDeserialize(mdastNode, deco, options),\n },\n br: {\n deserialize() {\n return [{ text: '\\n' }];\n },\n },\n break: {\n deserialize: (_mdastNode, _deco) => ({\n text: '\\n',\n }),\n serialize: () => ({\n type: 'break',\n }),\n },\n callout: {\n deserialize: (mdastNode, deco, options) => {\n const props = parseAttributes(mdastNode.attributes);\n return {\n children: convertChildrenDeserialize(mdastNode.children, deco, options),\n type: getPluginType(options.editor!, KEYS.callout),\n ...props,\n };\n },\n serialize(slateNode, options): MdMdxJsxFlowElement {\n const { children, type, ...rest } = slateNode;\n return {\n attributes: propsToAttributes(rest),\n children: convertNodesSerialize(children, options) as any,\n name: 'callout',\n type: 'mdxJsxFlowElement',\n };\n },\n },\n code: {\n mark: true,\n deserialize: (mdastNode, deco, options) => ({\n ...deco,\n [getPluginType(options.editor!, KEYS.code) as 'code']: true,\n text: mdastNode.value,\n }),\n },\n code_block: {\n deserialize: (mdastNode, _deco, options) => ({\n children: (mdastNode.value || '').split('\\n').map((line) => ({\n children: [{ text: line } as TText],\n type: getPluginType(options.editor!, KEYS.codeLine),\n })),\n lang: mdastNode.lang ?? undefined,\n type: getPluginType(options.editor!, KEYS.codeBlock),\n }),\n serialize: (node) => ({\n lang: node.lang,\n type: 'code',\n value: node.children\n .map((child: any) =>\n child?.children === undefined\n ? child.text\n : child.children.map((c: any) => c.text).join('')\n )\n .join('\\n'),\n }),\n },\n comment: {\n mark: true,\n deserialize: (mdastNode, deco, options) => {\n // const props = parseAttributes(mdastNode.attributes);\n return convertChildrenDeserialize(\n mdastNode.children,\n {\n [getPluginType(options.editor!, KEYS.comment)]: true,\n ...deco,\n // ...props,\n },\n options\n ) as any;\n },\n serialize(slateNode): MdMdxJsxTextElement {\n // const { text, comment, ...rest } = slateNode;\n return {\n // attributes: propsToAttributes(rest),\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'comment',\n type: 'mdxJsxTextElement',\n };\n },\n },\n date: {\n deserialize(mdastNode, _deco, options) {\n const dateValue = (mdastNode.children?.[0] as any)?.value || '';\n return {\n children: [{ text: '' }],\n date: dateValue,\n type: getPluginType(options.editor!, KEYS.date),\n };\n },\n serialize({ date }): MdMdxJsxTextElement {\n return {\n attributes: [],\n children: [{ type: 'text', value: date ?? '' }],\n name: 'date',\n type: 'mdxJsxTextElement',\n };\n },\n },\n del: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertChildrenDeserialize(\n mdastNode.children,\n { [getPluginType(options.editor!, KEYS.strikethrough)]: true, ...deco },\n options\n ) as any,\n // no serialize because it's mdx <del /> only\n },\n equation: {\n deserialize: (mdastNode, _deco, options) => ({\n children: [{ text: '' }],\n texExpression: mdastNode.value,\n type: getPluginType(options.editor!, KEYS.equation),\n }),\n serialize: (node) => ({\n type: 'math',\n value: node.texExpression,\n }),\n },\n // plate doesn't support footnoteDefinition and footnoteReference\n // so we need to convert them to p for now\n footnoteDefinition: {\n deserialize: (mdastNode, deco, options) => {\n const children = convertChildrenDeserialize(\n mdastNode.children,\n deco,\n options\n );\n\n // Flatten nested paragraphs similar to blockquote implementation\n const flattenedChildren = children.flatMap((child: any) =>\n child.type === 'p' ? child.children : [child]\n );\n\n return {\n children: flattenedChildren,\n type: getPluginType(options.editor!, KEYS.p),\n };\n },\n },\n footnoteReference: {},\n heading: {\n deserialize: (mdastNode, deco, options) => {\n const headingType = {\n 1: 'h1',\n 2: 'h2',\n 3: 'h3',\n 4: 'h4',\n 5: 'h5',\n 6: 'h6',\n };\n\n const defaultType = headingType[mdastNode.depth];\n\n const type = getPluginType(options.editor!, defaultType);\n\n return {\n children: convertChildrenDeserialize(mdastNode.children, deco, options),\n type,\n };\n },\n serialize: (node, options) => {\n const key = getPluginKey(options.editor!, node.type) ?? node.type;\n const depthMap = {\n h1: 1,\n h2: 2,\n h3: 3,\n h4: 4,\n h5: 5,\n h6: 6,\n };\n\n return {\n children: convertNodesSerialize(\n node.children,\n options\n ) as MdHeading['children'],\n depth: depthMap[key as keyof typeof depthMap] as any,\n type: 'heading',\n };\n },\n },\n highlight: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertChildrenDeserialize(\n mdastNode.children,\n { [getPluginType(options.editor!, KEYS.highlight)]: true, ...deco },\n options\n ) as any,\n serialize(slateNode): MdMdxJsxTextElement {\n return {\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'mark',\n type: 'mdxJsxTextElement',\n };\n },\n },\n hr: {\n deserialize: (_, __, options) => ({\n children: [{ text: '' } as TText],\n type: getPluginType(options.editor!, KEYS.hr),\n }),\n serialize: () => ({ type: 'thematicBreak' }),\n },\n html: {\n deserialize: (mdastNode, _deco, _options) => ({\n text: (mdastNode.value || '').replaceAll('<br />', '\\n'),\n }),\n },\n img: {\n deserialize: (mdastNode, _deco, options) => {\n const { alt, attributes, title, url } = mdastNode as any;\n const {\n alt: altAttr,\n src,\n ...rest\n } = attributes ? parseAttributes(attributes) : ({} as any);\n\n return {\n caption: [{ text: altAttr || alt || '' } as TText],\n children: [{ text: '' } as TText],\n ...(title && { title }),\n type: getPluginType(options.editor!, KEYS.img),\n url: src || url,\n ...rest,\n };\n },\n serialize: ({ caption, url }) => {\n const image: MdImage = {\n alt: caption ? caption.map((c) => (c as any).text).join('') : undefined,\n title: caption\n ? caption.map((c) => (c as any).text).join('')\n : undefined,\n type: 'image',\n url,\n };\n\n // since plate is using block image so we need to wrap it in a paragraph\n return { children: [image], type: 'paragraph' } as any;\n },\n },\n inline_equation: {\n deserialize(mdastNode, _, options) {\n return {\n children: [{ text: '' }],\n texExpression: mdastNode.value,\n type: getPluginType(options.editor!, KEYS.inlineEquation),\n };\n },\n serialize: (node) => ({\n type: 'inlineMath',\n value: node.texExpression,\n }),\n },\n italic: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertTextsDeserialize(mdastNode, deco, options),\n },\n kbd: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertChildrenDeserialize(\n mdastNode.children,\n { [getPluginType(options.editor!, KEYS.kbd)]: true, ...deco },\n options\n ) as any,\n serialize(slateNode): MdMdxJsxTextElement {\n return {\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'kbd',\n type: 'mdxJsxTextElement',\n };\n },\n },\n list: {\n deserialize: (mdastNode: MdList, deco, options) => {\n // Handle standard list\n const isIndentList = !!options.editor?.plugins.list;\n\n if (!isIndentList) {\n // For standard lists, we need to ensure each list item is properly structured\n const children = mdastNode.children.map((child) => {\n if (child.type === 'listItem') {\n // Process each list item\n return {\n children: child.children.map((itemChild) => {\n if (itemChild.type === 'paragraph') {\n return {\n children: convertChildrenDeserialize(\n itemChild.children,\n deco,\n options\n ),\n type: getPluginType(options.editor!, KEYS.lic),\n };\n }\n return convertChildrenDeserialize(\n [itemChild],\n deco,\n options\n )[0];\n }),\n type: getPluginType(options.editor!, KEYS.li),\n };\n }\n return convertChildrenDeserialize([child], deco, options)[0];\n });\n\n return {\n children,\n type: getPluginType(\n options.editor!,\n mdastNode.ordered ? KEYS.olClassic : KEYS.ulClassic\n ),\n };\n }\n\n const parseListItems = (listNode: MdList, indent = 1, startIndex = 1) => {\n const items: any[] = [];\n const isOrdered = !!listNode.ordered;\n let listStyleType = isOrdered\n ? getPluginType(options.editor!, KEYS.ol)\n : getPluginType(options.editor!, KEYS.ul);\n\n listNode.children?.forEach((listItem, index) => {\n if (listItem.type !== 'listItem') return;\n\n const isTodoList = isBoolean(listItem.checked);\n\n if (isTodoList)\n listStyleType = getPluginType(options.editor!, KEYS.listTodo);\n\n // Handle the main content of the list item\n const [paragraph, ...subLists] = listItem.children || [];\n\n // Create list item from paragraph content\n const result = paragraph\n ? buildSlateNode(paragraph, deco, options)\n : {\n children: [{ text: '' }],\n type: getPluginType(options.editor!, KEYS.p),\n };\n\n // Convert result to array if it's not already\n const itemNodes = Array.isArray(result) ? result : [result];\n\n // Add list properties to each node\n itemNodes.forEach((node: any) => {\n const itemContent: TListElement = {\n ...node,\n indent,\n type:\n node.type === getPluginType(options.editor!, KEYS.img)\n ? node.type\n : getPluginType(options.editor!, KEYS.p),\n };\n\n // Only add listStyleType and listStart for appropriate cases\n itemContent.listStyleType = listStyleType;\n if (isTodoList) {\n itemContent.checked = listItem.checked!;\n }\n if (isOrdered) {\n itemContent.listStart = startIndex + index;\n }\n\n items.push(itemContent);\n });\n\n // Process sub-lists and other content\n subLists.forEach((subNode) => {\n if (subNode.type === 'list') {\n // Recursively process nested lists\n const subListStart = (subNode as any).start || 1;\n const nestedItems = parseListItems(\n subNode,\n indent + 1,\n subListStart\n );\n items.push(...nestedItems);\n } else {\n // Transform any other node type using buildSlateNode\n const result = buildSlateNode(subNode, deco, options);\n\n // Handle both array and single node results\n if (Array.isArray(result)) {\n items.push(\n ...result.map((item) => ({\n ...item,\n indent: indent + 1,\n }))\n );\n } else {\n items.push({\n ...(result as any),\n indent: indent + 1,\n });\n }\n }\n });\n });\n\n return items;\n };\n\n const startIndex = (mdastNode as any).start || 1;\n return parseListItems(mdastNode, 1, startIndex);\n },\n serialize: (node: { type: 'ol' | 'ul' } & TElement, options): MdList => {\n const editor = options.editor!;\n const isOrdered = getPluginKey(editor, node.type) === KEYS.olClassic;\n\n const serializeListItems = (children: any[]): any[] => {\n const items: any[] = [];\n let currentItem: any = null;\n\n for (const child of children) {\n if (getPluginKey(editor, child.type) === 'li') {\n if (currentItem) {\n items.push(currentItem);\n }\n currentItem = {\n children: [],\n spread: false,\n type: 'listItem',\n };\n\n for (const liChild of child.children) {\n if (getPluginKey(editor, liChild.type) === 'lic') {\n currentItem.children.push({\n children: convertNodesSerialize(liChild.children, options),\n type: 'paragraph',\n });\n } else if (\n getPluginKey(editor, liChild.type) === 'ol' ||\n getPluginKey(editor, liChild.type) === 'ul'\n ) {\n currentItem.children.push({\n children: serializeListItems(liChild.children),\n ordered: getPluginKey(editor, liChild.type) === 'ol',\n spread: false,\n type: 'list',\n });\n }\n }\n }\n }\n\n if (currentItem) {\n items.push(currentItem);\n }\n\n return items;\n };\n\n return {\n children: serializeListItems(node.children),\n ordered: isOrdered,\n spread: false,\n type: 'list',\n };\n },\n },\n listItem: {\n deserialize: (mdastNode, deco, options) => {\n // Transform each paragraph in the list item into a 'lic' type\n const children = mdastNode.children.map((child: MdRootContent) => {\n if (child.type === 'paragraph') {\n return {\n children: convertChildrenDeserialize(child.children, deco, options),\n type: getPluginType(options.editor!, KEYS.lic),\n };\n }\n return convertChildrenDeserialize([child], deco, options)[0];\n });\n\n return {\n children,\n type: getPluginType(options.editor!, KEYS.li),\n };\n },\n serialize: (node, options) => ({\n children: convertNodesSerialize(node.children, options),\n type: 'listItem',\n }),\n },\n mention: {\n deserialize: (node: MentionNode, _deco, options): TMentionElement => ({\n children: [{ text: '' }],\n type: getPluginType(options.editor!, KEYS.mention),\n value: node.displayText || node.username,\n ...(node.displayText && { key: node.username }),\n }),\n serialize: (node: TMentionElement) => {\n const mentionId = node.key || node.value;\n const displayText = node.value;\n\n // Always use link format for all mentions\n // Encode the mention ID to create a valid URL, manually encoding parentheses\n const encodedId = encodeURIComponent(String(mentionId))\n .replace(/\\(/g, '%28')\n .replace(/\\)/g, '%29');\n return {\n children: [{ type: 'text', value: displayText }],\n type: 'link',\n url: `mention:${encodedId}`,\n };\n },\n },\n p: {\n deserialize: (node, deco, options) => {\n const isKeepLineBreak = options.splitLineBreaks;\n const children = convertChildrenDeserialize(node.children, deco, options);\n const splitBlockTypes = new Set(['img']);\n\n const elements: any[] = [];\n let inlineNodes: any[] = [];\n\n const flushInlineNodes = () => {\n if (inlineNodes.length > 0) {\n elements.push({\n children: inlineNodes,\n type: getPluginType(options.editor!, KEYS.p),\n });\n inlineNodes = [];\n }\n };\n\n children.forEach((c) => {\n if (c.text === '\\u200B') {\n c.text = '';\n }\n });\n\n children.forEach((child, index, children) => {\n const { type } = child as { type?: string };\n\n if (type && splitBlockTypes.has(type)) {\n flushInlineNodes();\n elements.push(child);\n } else if (\n isKeepLineBreak &&\n 'text' in child &&\n typeof child.text === 'string'\n ) {\n const textParts = child.text.split('\\n');\n\n // Handle line break generated by <br>\n const isSingleLineBreak =\n child.text === '\\n' && inlineNodes.length === 0;\n\n if (isSingleLineBreak) {\n inlineNodes.push({ ...child, text: '' });\n flushInlineNodes();\n\n return;\n }\n\n textParts.forEach((part, index, array) => {\n const isNotFirstPart = index > 0;\n const isNotLastPart = index < array.length - 1;\n\n // Create new paragraph for non-first parts\n if (isNotFirstPart) {\n flushInlineNodes();\n }\n // Only add non-empty text\n if (part) {\n inlineNodes.push({ ...child, text: part });\n }\n // Create paragraph break for non-last parts\n if (isNotLastPart) {\n flushInlineNodes();\n }\n });\n } else if (\n child.text === '\\n' &&\n children.length > 1 &&\n index === children.length - 1\n ) {\n // remove the last br of the paragraph if the previos element is not a br\n // no op\n } else {\n inlineNodes.push(child);\n }\n });\n\n flushInlineNodes();\n\n return elements.length === 1 ? elements[0] : elements;\n },\n serialize: (node, options) => {\n let enrichedChildren = node.children;\n\n enrichedChildren = enrichedChildren.map((child) => {\n if (child.text === '\\n') {\n return {\n type: 'break',\n } as any;\n }\n\n if (child.text === '' && options.preserveEmptyParagraphs !== false) {\n return { ...child, text: '\\u200B' };\n }\n\n return child;\n });\n\n const convertedNodes = convertNodesSerialize(\n enrichedChildren,\n options\n ) as MdParagraph['children'];\n\n if (\n convertedNodes.length > 0 &&\n enrichedChildren.at(-1)!.type === 'break'\n ) {\n // if the last child of the paragraph is a line break add an additional one\n convertedNodes.at(-1)!.type = 'html';\n // @ts-expect-error -- value is the right property here\n convertedNodes.at(-1)!.value = '\\n<br />';\n }\n\n return {\n children: convertedNodes,\n type: 'paragraph',\n };\n },\n },\n strikethrough: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertTextsDeserialize(mdastNode, deco, options),\n },\n subscript: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertChildrenDeserialize(\n mdastNode.children,\n { [getPluginType(options.editor!, KEYS.sub)]: true, ...deco },\n options\n ) as any,\n serialize(slateNode, _options): MdMdxJsxTextElement {\n return {\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'sub',\n type: 'mdxJsxTextElement',\n };\n },\n },\n suggestion: {\n mark: true,\n deserialize: (mdastNode, deco, options) => {\n // const props = parseAttributes(mdastNode.attributes);\n\n return convertChildrenDeserialize(\n mdastNode.children,\n {\n [getPluginType(options.editor!, KEYS.suggestion)]: true,\n ...deco,\n // ...props,\n },\n options\n ) as any;\n },\n serialize(slateNode): MdMdxJsxTextElement {\n // const { text, suggestion, ...rest } = slateNode;\n\n return {\n // attributes: propsToAttributes(rest),\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'suggestion',\n type: 'mdxJsxTextElement',\n };\n },\n },\n superscript: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertChildrenDeserialize(\n mdastNode.children,\n { [getPluginType(options.editor!, KEYS.sup)]: true, ...deco },\n options\n ) as any,\n serialize(slateNode, _options): MdMdxJsxTextElement {\n return {\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'sup',\n type: 'mdxJsxTextElement',\n };\n },\n },\n table: {\n deserialize: (node, deco, options) => {\n const paragraphType = getPluginType(options.editor!, KEYS.p);\n const rows =\n node.children?.map((row, rowIndex) => ({\n children:\n row.children?.map((cell) => {\n const cellType = rowIndex === 0 ? 'th' : 'td';\n\n const cellChildren = convertChildrenDeserialize(\n cell.children,\n deco,\n options\n );\n const groupedChildren: any[] = [];\n let currentParagraphChildren: any[] = [];\n\n for (const child of cellChildren) {\n // Text nodes or inline elements should be grouped into paragraphs\n if (!child.type || child.type === KEYS.inlineEquation) {\n currentParagraphChildren.push(child);\n } else {\n // Block-level elements should end the current paragraph and be added directly\n if (currentParagraphChildren.length > 0) {\n groupedChildren.push({\n children: currentParagraphChildren,\n type: paragraphType,\n });\n currentParagraphChildren = [];\n }\n groupedChildren.push(child);\n }\n }\n\n // Add any remaining paragraph child elements\n if (currentParagraphChildren.length > 0) {\n groupedChildren.push({\n children: currentParagraphChildren,\n type: paragraphType,\n });\n }\n\n return {\n children:\n groupedChildren.length > 0\n ? groupedChildren\n : [{ children: [{ text: '' }], type: paragraphType }],\n type: getPluginType(options.editor!, cellType),\n };\n }) || [],\n type: getPluginType(options.editor!, KEYS.tr),\n })) || [];\n\n return {\n children: rows,\n type: getPluginType(options.editor!, KEYS.table),\n };\n },\n serialize: (node, options) => ({\n children: convertNodesSerialize(\n node.children,\n options\n ) as MdTable['children'],\n type: 'table',\n }),\n },\n td: {\n serialize: (node, options) => {\n const children = convertNodesSerialize(\n node.children,\n options\n ) as MdTableCell['children'];\n\n // Insert <br/> between multiple blocks in table cells\n // since markdown tables don't support multiple blocks natively\n if (children.length > 1) {\n const result: MdTableCell['children'] = [];\n\n for (let i = 0; i < children.length; i++) {\n result.push(children[i]);\n\n if (i < children.length - 1) {\n result.push({ type: 'html', value: '<br/>' } as any);\n }\n }\n\n return { children: result, type: 'tableCell' };\n }\n\n return { children, type: 'tableCell' };\n },\n },\n text: {\n deserialize: (mdastNode, deco) => ({\n ...deco,\n text: mdastNode.value.replace(LEADING_NEWLINE_REGEX, ''),\n }),\n },\n th: {\n serialize: (node, options) => {\n const children = convertNodesSerialize(\n node.children,\n options\n ) as MdTableCell['children'];\n\n // Insert <br/> between multiple blocks in table cells\n // since markdown tables don't support multiple blocks natively\n if (children.length > 1) {\n const result: MdTableCell['children'] = [];\n\n for (let i = 0; i < children.length; i++) {\n result.push(children[i]);\n\n if (i < children.length - 1) {\n result.push({ type: 'html', value: '<br/>' } as any);\n }\n }\n\n return { children: result, type: 'tableCell' };\n }\n\n return { children, type: 'tableCell' };\n },\n },\n toc: {\n deserialize: (mdastNode, deco, options) => ({\n children: convertChildrenDeserialize(mdastNode.children, deco, options),\n type: getPluginType(options.editor!, KEYS.toc),\n }),\n serialize: (node, options): MdMdxJsxFlowElement => ({\n attributes: [],\n children: convertNodesSerialize(node.children, options) as any,\n name: 'toc',\n type: 'mdxJsxFlowElement',\n }),\n },\n tr: {\n serialize: (node, options) => ({\n children: convertNodesSerialize(\n node.children,\n options\n ) as MdTableRow['children'],\n type: 'tableRow',\n }),\n },\n underline: {\n mark: true,\n deserialize: (mdastNode, deco, options) =>\n convertChildrenDeserialize(\n mdastNode.children,\n { [getPluginType(options.editor!, KEYS.underline)]: true, ...deco },\n options\n ) as any,\n serialize(slateNode, _options): MdMdxJsxTextElement {\n return {\n attributes: [],\n children: [{ type: 'text', value: slateNode.text }],\n name: 'u',\n type: 'mdxJsxTextElement',\n };\n },\n },\n ...fontRules,\n ...mediaRules,\n ...columnRules,\n};\n\nexport const buildRules = (editor: SlateEditor) => {\n const keys = Object.keys(defaultRules);\n\n const newRules: Record<string, any> = {};\n keys.forEach((key) => {\n const pluginKey = getPluginKey(editor, key);\n newRules[pluginKey ?? key] = defaultRules[key];\n });\n\n return newRules;\n};\n","import type { DeserializeMdOptions } from '../deserializeMd';\n\nimport { buildRules } from '../../rules/defaultRules';\n\nexport const getDeserializerByKey = (\n key: string,\n options: DeserializeMdOptions\n) => {\n const rules = options.rules;\n\n return rules?.[key]?.deserialize === undefined\n ? buildRules(options.editor!)[key]?.deserialize\n : rules?.[key]?.deserialize;\n};\n","import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';\n\nimport { getPluginKey, getPluginType, KEYS } from 'platejs';\n\nimport type { MdDecoration } from '../../types';\nimport type { DeserializeMdOptions } from '../deserializeMd';\n\nimport { mdastToPlate } from '../../types';\nimport { convertChildrenDeserialize } from '../convertChildrenDeserialize';\nimport { getDeserializerByKey } from './getDeserializerByKey';\n\nexport const customMdxDeserialize = (\n mdastNode: MdxJsxFlowElement | MdxJsxTextElement,\n deco: MdDecoration,\n options: DeserializeMdOptions\n) => {\n const customJsxElementKey = mdastNode.name;\n\n const key =\n getPluginKey(options.editor!, customJsxElementKey as any) ?? mdastNode.name;\n\n if (key) {\n const nodeParserDeserialize = getDeserializerByKey(\n mdastToPlate(options.editor!, key as any),\n options\n );\n\n if (nodeParserDeserialize)\n return nodeParserDeserialize(mdastNode, deco, options) as any;\n } else {\n console.warn(\n 'This MDX node does not have a parser for deserialization',\n mdastNode\n );\n }\n\n // Default fallback: preserve tag structure as text\n if (mdastNode.type === 'mdxJsxTextElement') {\n const tagName = mdastNode.name;\n let textContent = '';\n\n if (mdastNode.children) {\n textContent = mdastNode.children\n .map((child) => {\n if ('value' in child) return child.value;\n return '';\n })\n .join('');\n }\n\n return [\n {\n text: `<${tagName}>${textContent}</${tagName}>`,\n },\n ];\n }\n\n if (mdastNode.type === 'mdxJsxFlowElement') {\n const tagName = mdastNode.name;\n\n // Return as a paragraph with the tag structure preserved\n return [\n {\n children: [\n {\n text: `<${tagName}>\\n`,\n },\n ...convertChildrenDeserialize(mdastNode.children, deco, options),\n {\n text: `\\n</${tagName}>`,\n },\n ],\n type: getPluginType(options.editor!, KEYS.p),\n },\n ];\n }\n};\n","export const stripMarkdownBlocks = (text: string) => {\n let result = text;\n\n // Remove headers\n result = result.replaceAll(/^#{1,6}\\s+/gm, '');\n\n // Remove blockquotes\n result = result.replaceAll(/^\\s*>\\s?/gm, '');\n\n // Remove horizontal rules\n result = result.replaceAll(/^([*_-]){3,}\\s*$/gm, '');\n\n // Remove list symbols\n result = result.replaceAll(/^(\\s*)([*+-]|\\d+\\.)\\s/gm, '$1');\n\n // Remove code blocks\n result = result.replaceAll(/^```[\\S\\s]*?^```/gm, '');\n\n // Replace <br> with \\n\n result = result.replaceAll('<br>', '\\n');\n\n return result;\n};\n\nexport const stripMarkdownInline = (text: string) => {\n let result = text;\n\n // Remove emphasis (bold, italic)\n result = result.replaceAll(/(\\*\\*|__)(.*?)\\1/g, '$2');\n result = result.replaceAll(/(\\*|_)(.*?)\\1/g, '$2');\n\n // Remove links\n result = result.replaceAll(/\\[([^\\]]+)]\\(([^)]+)\\)/g, '$1');\n\n // Remove inline code\n result = result.replaceAll(/`(.+?)`/g, '$1');\n\n // Replace HTML entities\n result = result.replaceAll('&nbsp;', ' ');\n result = result.replaceAll('&lt;', '<');\n result = result.replaceAll('&gt;', '>');\n result = result.replaceAll('&amp;', '&');\n\n return result;\n};\n\nexport const stripMarkdown = (text: string) => {\n let result = stripMarkdownBlocks(text);\n result = stripMarkdownInline(result);\n\n // Remove HTML tags (including <br>)\n // result = result.replace(/<[^>]*>/g, '');\n\n // Replace HTML entities\n // result = result.replace('&nbsp;', ' ');\n // result = result.replace('&lt;', '<');\n // result = result.replace('&gt;', '>');\n // result = result.replace('&amp;', '&');\n\n return result;\n};\n","import { type Descendant, type SlateEditor, ElementApi } from 'platejs';\n\nimport type { DeserializeMdOptions } from '../deserializeMd';\n\nimport { MarkdownPlugin } from '../../MarkdownPlugin';\nimport { stripMarkdownBlocks } from './stripMarkdown';\n\nconst LEADING_SPACES_REGEX = /^\\s*/;\nconst TRAILING_SPACES_REGEX = /\\s*$/;\n\nexport const deserializeInlineMd = (\n editor: SlateEditor,\n text: string,\n options?: DeserializeMdOptions\n) => {\n const leadingSpaces = LEADING_SPACES_REGEX.exec(text)?.[0] || '';\n const trailingSpaces = TRAILING_SPACES_REGEX.exec(text)?.[0] || '';\n\n const strippedText = stripMarkdownBlocks(text.trim());\n\n const fragment: Descendant[] = [];\n\n if (leadingSpaces) {\n fragment.push({ text: leadingSpaces });\n }\n\n if (strippedText) {\n const result = editor\n .getApi(MarkdownPlugin)\n .markdown.deserialize(strippedText, options)[0];\n\n if (result) {\n const nodes = ElementApi.isElement(result) ? result.children : [result];\n fragment.push(...nodes);\n }\n }\n if (trailingSpaces) {\n fragment.push({ text: trailingSpaces });\n }\n\n return fragment;\n};\n","import type { Plugin } from 'unified';\n\nexport const REMARK_MDX_TAG = 'remarkMdx';\n\nexport const tagRemarkPlugin = (pluginFn: any, tag: string) => {\n const wrapped = function (this: any, ...args: any[]) {\n return pluginFn.apply(this, args);\n };\n wrapped.__pluginTag = tag;\n return wrapped;\n};\n\nexport const getRemarkPluginsWithoutMdx = (plugins: Plugin[]) =>\n plugins.filter((plugin) => (plugin as any).__pluginTag !== REMARK_MDX_TAG);\n","import type { SlateEditor } from 'platejs';\n\nimport type { DeserializeMdOptions } from '../deserializeMd';\n\nimport { MarkdownPlugin } from '../../MarkdownPlugin';\nimport { buildRules } from '../../rules';\nimport { getRemarkPluginsWithoutMdx } from '../../utils/getRemarkPluginsWithoutMdx';\n\n/**\n * Merges Markdown configurations, following the principle that options take\n * precedence\n *\n * @param editor Editor instance used to get plugin default configurations\n * @param options User-provided options (higher priority)\n * @returns The final merged configuration\n */\nexport const getMergedOptionsDeserialize = (\n editor: SlateEditor,\n options?: DeserializeMdOptions\n): DeserializeMdOptions => {\n const {\n allowedNodes: PluginAllowedNodes,\n allowNode: PluginAllowNode,\n disallowedNodes: PluginDisallowedNodes,\n remarkPlugins: PluginRemarkPlugins,\n rules: PluginRules,\n } = editor.getOptions(MarkdownPlugin);\n\n const mergedRules = {\n ...buildRules(editor),\n ...(options?.rules ?? PluginRules),\n };\n\n const remarkPlugins = options?.remarkPlugins ?? PluginRemarkPlugins ?? [];\n\n return {\n allowedNodes: options?.allowedNodes ?? PluginAllowedNodes,\n allowNode: options?.allowNode ?? PluginAllowNode,\n disallowedNodes: options?.disallowedNodes ?? PluginDisallowedNodes,\n editor,\n memoize: options?.memoize,\n parser: options?.parser,\n remarkPlugins: options?.withoutMdx\n ? getRemarkPluginsWithoutMdx(remarkPlugins)\n : remarkPlugins,\n rules: mergedRules,\n splitLineBreaks: options?.splitLineBreaks,\n };\n};\n","import type { MdMdxJsxTextElement } from '../../mdast';\n\nexport const getStyleValue = (\n mdastNode: MdMdxJsxTextElement,\n styleName: string\n): string | undefined => {\n const styleAttribute = mdastNode.attributes.find(\n (attr) => 'name' in attr && attr.name === 'style'\n ) as any;\n\n if (!styleAttribute?.value) return;\n\n const styles = styleAttribute.value.split(';');\n for (const style of styles) {\n const [name, value] = style.split(':').map((s: string) => s.trim());\n if (name === styleName) {\n return value;\n }\n }\n return;\n};\n","const VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n]);\n\nconst BOOL_ATTRS = new Map([\n ['checked', 'checked'],\n ['disabled', 'disabled'],\n ['readonly', 'readOnly'],\n ['required', 'required'],\n ['multiple', 'multiple'],\n ['hidden', 'hidden'],\n]);\n\nconst BOOL_ATTR_REGEXES = Array.from(BOOL_ATTRS.entries()).map(\n ([htmlAttr, jsxAttr]) => ({\n jsxAttr,\n reg: new RegExp(`(\\\\s|^)${htmlAttr}(\\\\s|/?>|$)`, 'gi'),\n })\n);\n\nconst ATTR_RENAMES: [RegExp, string][] = [\n [/(\\s)class=/g, '$1className='],\n [/(\\s)for=/g, '$1htmlFor='],\n];\n\nexport const htmlToJsx = (html: string): string => {\n if (!html || typeof html !== 'string') return html;\n\n return html\n .replace(/<!--([\\s\\S]*?)-->/g, '{/*$1*/}')\n .replace(\n /<([a-zA-Z0-9]+)\\b([^>]*?)(\\/?)>/gi,\n (_match, tagName, attrs, selfClosing) => {\n let a = attrs;\n\n ATTR_RENAMES.forEach(([pattern, replacement]) => {\n a = a.replace(pattern, replacement);\n });\n\n a = a.replace(\n /(^|\\s)([a-zA-Z0-9_-]+)=([^{ \\t\\n\\r\"'>]+?)(?=\\s|\\/?>|$)/g,\n '$1$2=\"$3\"'\n );\n\n for (const { reg, jsxAttr } of BOOL_ATTR_REGEXES) {\n a = a.replace(reg, `$1${jsxAttr}=\"true\"$2`);\n }\n\n const isVoid = VOID_ELEMENTS.has(tagName.toLowerCase());\n const closing = isVoid ? ' /' : selfClosing;\n\n return `<${tagName}${a.trimEnd()}${closing}>`;\n }\n );\n};\n","import type { Root } from 'mdast';\n\nimport { type Descendant, getPluginKey, KEYS } from 'platejs';\n\nimport type { MdRoot } from '../mdast';\nimport type { DeserializeMdOptions } from './deserializeMd';\n\nimport { convertNodesDeserialize } from './convertNodesDeserialize';\n\nexport const mdastToSlate = (\n node: Root,\n options: DeserializeMdOptions\n): Descendant[] => buildSlateRoot(node, options);\n\nconst buildSlateRoot = (\n root: MdRoot,\n options: DeserializeMdOptions\n): Descendant[] => {\n if (!options.splitLineBreaks) {\n root.children = root.children.map((child) => {\n if (child.type === 'html' && child.value === '<br />') {\n return {\n children: [{ type: 'text', value: '\\n' }],\n type: 'paragraph',\n };\n }\n return child;\n });\n return convertNodesDeserialize(root.children, {}, options);\n }\n\n // Split line breaks into separate paragraphs\n const results: Descendant[] = [];\n let startLine = root.position?.start.line ?? 1;\n\n const addEmptyParagraphs = (count: number) => {\n if (count > 0) {\n results.push(\n ...Array.from({ length: count }).map(() => ({\n children: [{ text: '' }],\n type: options.editor\n ? (getPluginKey(options.editor, KEYS.p) ?? KEYS.p)\n : KEYS.p,\n }))\n );\n }\n };\n\n root.children?.forEach((child, index) => {\n const isFirstChild = index === 0;\n const isLastChild = index === root.children!.length - 1;\n\n if (child.position) {\n const emptyLinesBefore =\n child.position.start.line - (isFirstChild ? startLine : startLine + 1);\n addEmptyParagraphs(emptyLinesBefore);\n\n const transformValue = convertNodesDeserialize([child], {}, options);\n results.push(...transformValue);\n\n if (isLastChild) {\n const emptyLinesAfter =\n root.position!.end.line - child.position.end.line - 1;\n addEmptyParagraphs(emptyLinesAfter);\n }\n\n startLine = child.position.end.line;\n } else {\n const transformValue = convertNodesDeserialize([child], {}, options);\n results.push(...transformValue);\n }\n });\n\n return results;\n};\n","import type { Root } from 'mdast';\nimport type { Plugin } from 'unified';\n\nimport {\n type Descendant,\n type SlateEditor,\n type TElement,\n type Value,\n getPluginKey,\n KEYS,\n TextApi,\n} from 'platejs';\nimport remarkParse from 'remark-parse';\nimport { unified } from 'unified';\n\nimport type { AllowNodeConfig } from '../MarkdownPlugin';\nimport type { MdRules, PlateType } from '../types';\n\nimport { mdastToSlate } from './mdastToSlate';\nimport {\n type ParseMarkdownBlocksOptions,\n htmlToJsx,\n parseMarkdownBlocks,\n} from './utils';\nimport { getMergedOptionsDeserialize } from './utils/getMergedOptionsDeserialize';\nimport { markdownToSlateNodesSafely } from './utils/markdownToSlateNodesSafely';\n\n// TODO: fixes tests\n\nexport type DeserializeMdOptions = {\n allowedNodes?: PlateType[] | null;\n allowNode?: AllowNodeConfig;\n disallowedNodes?: PlateType[] | null;\n editor?: SlateEditor;\n memoize?: boolean;\n parser?: ParseMarkdownBlocksOptions;\n preserveEmptyParagraphs?: boolean;\n remarkPlugins?: Plugin[];\n rules?: MdRules | null;\n splitLineBreaks?: boolean;\n withoutMdx?: boolean;\n onError?: (error: Error) => void;\n};\n\nexport const markdownToAstProcessor = (\n editor: SlateEditor,\n data: string,\n options?: DeserializeMdOptions\n) => {\n const mergedOptions = getMergedOptionsDeserialize(editor, options);\n\n return unified()\n .use(remarkParse)\n .use(mergedOptions.remarkPlugins ?? [])\n .parse(data);\n};\n\nexport const markdownToSlateNodes = (\n editor: SlateEditor,\n data: string,\n options?: Omit<DeserializeMdOptions, 'editor'>\n): Descendant[] => {\n const processedData = options?.withoutMdx ? data : htmlToJsx(data);\n\n const mergedOptions = getMergedOptionsDeserialize(editor, options);\n\n const toSlateProcessor = unified()\n .use(remarkParse)\n .use(mergedOptions.remarkPlugins ?? [])\n .use(remarkToSlate, mergedOptions);\n\n if (options?.memoize) {\n return parseMarkdownBlocks(processedData, options.parser).flatMap(\n (token) => {\n if (token.type === 'space') {\n return {\n ...editor.api.create.block(),\n _memo: token.raw,\n };\n }\n\n return toSlateProcessor\n .processSync(token.raw)\n .result.map((result: any) => ({\n _memo: token.raw,\n ...result,\n }));\n }\n );\n }\n\n return toSlateProcessor.processSync(processedData).result;\n};\n\nexport const deserializeMd = (\n editor: SlateEditor,\n data: string,\n options?: Omit<DeserializeMdOptions, 'editor'>\n): Value => {\n let output: Descendant[] | null = null;\n\n try {\n output = markdownToSlateNodes(editor, data, options);\n } catch (error) {\n options?.onError?.(error as Error);\n\n if (!options?.withoutMdx) {\n output = markdownToSlateNodesSafely(editor, data, options);\n }\n }\n\n if (!output) return [];\n\n // when output is inline text, we need to wrap the text in a paragraph\n return output.map((item) =>\n TextApi.isText(item)\n ? ({\n children: [item],\n type: getPluginKey(editor, KEYS.p) ?? KEYS.p,\n } as TElement)\n : item\n );\n};\n\ndeclare module 'unified' {\n // biome-ignore lint/style/useConsistentTypeDefinitions: module\n interface CompileResultMap {\n remarkToSlateNode: Descendant[];\n }\n}\n\nconst remarkToSlate: Plugin<[DeserializeMdOptions?], Root, Descendant[]> =\n // TODO: options\n function (options = {}) {\n this.compiler = (node) => mdastToSlate(node as Root, options);\n };\n","/** Check if character is valid for tag name: A-Z / a-z / 0-9 / - _ : */\nconst isNameChar = (c: number) =>\n (c >= 48 && c <= 57) || // 0-9\n (c >= 65 && c <= 90) || // A-Z\n (c >= 97 && c <= 122) || // a-z\n c === 45 || // -\n c === 95 || // _\n c === 58; // :\n\nexport const splitIncompleteMdx = (data: string): string[] | string => {\n type Frame = {\n name: string;\n pos: number;\n };\n const stack: Frame[] = [];\n\n const len = data.length;\n let i = 0;\n let cutPos = -1; // Once \"incomplete\" is found, record the starting position and exit scanning\n\n while (i < len) {\n if (data.codePointAt(i) !== 60 /* '<' */) {\n i++;\n continue;\n }\n\n const tagStart = i; // Remember the position of '<'\n i++; // Skip '<'\n if (i >= len) {\n cutPos = tagStart;\n break;\n } // Stream breaks at '<'\n\n let closing = false;\n if (data[i] === '/') {\n closing = true;\n i++;\n }\n\n /* Parse tag name -------------------------------------------------- */\n const nameStart = i;\n while (i < len && isNameChar(data.codePointAt(i) as number)) i++;\n if (nameStart === i) {\n cutPos = tagStart;\n break;\n } // No name after '<'\n\n const tagName = data.slice(nameStart, i).toLowerCase();\n\n /* Skip to matching '>' (considering quotes) ------------------------------------ */\n let inQuote: \"'\" | '\"' | null = null;\n let selfClosing = false;\n\n while (i < len) {\n const ch = data[i];\n if (inQuote) {\n if (ch === inQuote) inQuote = null;\n } else if (ch === '\"' || ch === \"'\") inQuote = ch;\n else if (ch === '>') {\n selfClosing = data[i - 1] === '/';\n i++; // Include '>'\n break;\n }\n i++;\n }\n\n if (i >= len) {\n // Didn't reach '>'\n cutPos = tagStart;\n break;\n }\n\n /* Maintain stack ------------------------------------------------------ */\n if (selfClosing) continue;\n\n if (closing) {\n for (let j = stack.length - 1; j >= 0; j--) {\n if (stack[j].name === tagName) {\n stack.splice(j, 1);\n break;\n }\n }\n } else {\n stack.push({ name: tagName, pos: tagStart });\n }\n }\n\n /* Calculate final cut point -------------------------------------------------- */\n if (stack.length > 0) {\n const firstUnmatched = stack[0].pos;\n cutPos = cutPos === -1 ? firstUnmatched : Math.min(cutPos, firstUnmatched);\n }\n\n return cutPos === -1 ? data : [data.slice(0, cutPos), data.slice(cutPos)];\n};\n","import { type SlateEditor, ElementApi, getPluginType, KEYS } from 'platejs';\n\nimport {\n type DeserializeMdOptions,\n markdownToSlateNodes,\n} from '../deserializeMd';\nimport { deserializeInlineMd } from './deserializeInlineMd';\nimport { splitIncompleteMdx } from './splitIncompleteMdx';\n\nexport const markdownToSlateNodesSafely = (\n editor: SlateEditor,\n data: string,\n options?: Omit<DeserializeMdOptions, 'editor'>\n) => {\n const result = splitIncompleteMdx(data);\n\n if (!Array.isArray(result))\n return markdownToSlateNodes(editor, data, {\n ...options,\n withoutMdx: true,\n });\n\n const [completeString, incompleteString] = result;\n\n const incompleteNodes = deserializeInlineMd(editor, incompleteString, {\n ...options,\n withoutMdx: true,\n });\n\n const completeNodes = markdownToSlateNodes(editor, completeString, options);\n\n if (incompleteNodes.length === 0) {\n return completeNodes;\n }\n\n const newBlock = {\n children: incompleteNodes,\n type: getPluginType(editor, KEYS.p),\n };\n\n // Push inlineNodes to the children of the last block in blockNodes\n if (completeNodes.length === 0) {\n return [newBlock];\n }\n\n const lastBlock = completeNodes.at(-1);\n\n if (ElementApi.isElement(lastBlock) && editor.api.isVoid(lastBlock)) {\n return [...completeNodes, newBlock];\n }\n\n // FIXME table column will fail, need recursive find the last p\n if (ElementApi.isElement(lastBlock) && lastBlock?.children) {\n lastBlock.children.push(...incompleteNodes);\n return completeNodes;\n }\n\n return completeNodes;\n};\n","import { type Token, marked } from 'marked';\n\nexport type ParseMarkdownBlocksOptions = {\n /**\n * Token types to exclude from the output.\n *\n * @default ['space']\n */\n exclude?: string[];\n /**\n * Whether to trim the content.\n *\n * @default true\n */\n trim?: boolean;\n};\n\nexport const parseMarkdownBlocks = (\n content: string,\n { exclude = ['space'], trim = true }: ParseMarkdownBlocksOptions = {}\n): Token[] => {\n let tokens = [...marked.lexer(content)];\n\n if (exclude.length > 0) {\n tokens = tokens.filter((token) => !exclude.includes(token.type));\n }\n if (trim) {\n tokens = tokens.map((token) => ({\n ...token,\n raw: token.raw.trimEnd(),\n }));\n }\n\n return tokens;\n};\n","import type { Descendant } from 'platejs';\n\nimport type { MdRootContent } from '../mdast';\nimport type { MdDecoration } from '../types';\nimport type { DeserializeMdOptions } from './deserializeMd';\n\nimport { mdastToPlate } from '../types';\nimport { customMdxDeserialize } from './utils';\nimport { getDeserializerByKey } from './utils/getDeserializerByKey';\n\nexport const convertNodesDeserialize = (\n nodes: MdRootContent[],\n deco: MdDecoration,\n options: DeserializeMdOptions\n): Descendant[] => {\n return nodes.reduce<Descendant[]>((acc, node) => {\n // Only process nodes that pass the filtering\n if (shouldIncludeNode(node, options)) {\n acc.push(...buildSlateNode(node, deco, options));\n }\n return acc;\n }, []);\n};\n\nexport const buildSlateNode = (\n mdastNode: MdRootContent,\n deco: MdDecoration,\n options: DeserializeMdOptions\n): Descendant[] => {\n /** Handle custom mdx nodes */\n if (\n mdastNode.type === 'mdxJsxTextElement' ||\n mdastNode.type === 'mdxJsxFlowElement'\n ) {\n const result = customMdxDeserialize(mdastNode, deco, options);\n return Array.isArray(result) ? result : [result];\n }\n\n const type = mdastToPlate(options.editor!, mdastNode.type);\n\n const nodeParser = getDeserializerByKey(type, options);\n\n if (nodeParser) {\n const result = nodeParser(mdastNode as any, deco, options);\n return Array.isArray(result) ? result : [result];\n }\n return [];\n};\n\nconst shouldIncludeNode = (\n node: MdRootContent,\n options: DeserializeMdOptions\n): boolean => {\n const { allowedNodes, allowNode, disallowedNodes } = options;\n\n if (!node.type) return true;\n\n const type = mdastToPlate(options.editor!, node.type);\n\n // First check allowedNodes/disallowedNodes\n if (\n allowedNodes &&\n disallowedNodes &&\n allowedNodes.length > 0 &&\n disallowedNodes.length > 0\n ) {\n throw new Error('Cannot combine allowedNodes with disallowedNodes');\n }\n\n if (allowedNodes) {\n // If allowedNodes is specified, only include if the type is in allowedNodes\n if (!allowedNodes.includes(type)) {\n return false;\n }\n } else if (disallowedNodes?.includes(type)) {\n // If using disallowedNodes, exclude if the type is in disallowedNodes\n return false;\n }\n\n // Finally, check allowNode if provided\n if (allowNode?.deserialize) {\n return allowNode.deserialize({\n ...node,\n type,\n });\n }\n\n return true;\n};\n","import type { Descendant } from 'platejs';\n\nimport type { MdRootContent } from '../mdast';\nimport type { MdDecoration } from '../types';\nimport type { DeserializeMdOptions } from './deserializeMd';\n\nimport { convertNodesDeserialize } from './convertNodesDeserialize';\n\nexport const convertChildrenDeserialize = (\n children: MdRootContent[],\n deco: MdDecoration,\n options: DeserializeMdOptions\n): Descendant[] => {\n if (children.length === 0) {\n return [{ text: '' }];\n }\n\n return convertNodesDeserialize(children, deco, options);\n};\n","import { getPluginType } from 'platejs';\n\nimport type { MdDelete, MdEmphasis, MdStrong } from '../mdast';\nimport type { MdDecoration } from '../types';\nimport type { DeserializeMdOptions } from './deserializeMd';\n\nimport { mdastToPlate } from '../types';\nimport { buildSlateNode } from './convertNodesDeserialize';\n\nexport const convertTextsDeserialize = (\n mdastNode: MdDelete | MdEmphasis | MdStrong,\n deco: MdDecoration,\n options: DeserializeMdOptions\n) =>\n mdastNode.children.reduce((acc: any, n: any) => {\n const key = mdastToPlate(options.editor!, mdastNode.type);\n const type = getPluginType(options.editor!, key);\n\n acc.push(...buildSlateNode(n, { ...deco, [type]: true }, options));\n return acc;\n }, []);\n","import type { Options as RemarkStringifyOptions } from 'remark-stringify';\nimport type { Plugin } from 'unified';\n\nimport {\n type OmitFirst,\n type PluginConfig,\n bindFirst,\n createTSlatePlugin,\n isUrl,\n KEYS,\n} from 'platejs';\n\nimport type { MdRules, PlateType } from './types';\n\nimport { deserializeInlineMd, deserializeMd } from './deserializer';\nimport { serializeMd } from './serializer';\n\nexport type AllowNodeConfig = {\n /** Custom filter function for nodes during deserialization */\n deserialize?: (node: any) => boolean;\n /** Custom filter function for nodes during serialization */\n serialize?: (node: any) => boolean;\n};\n\nexport type MarkdownConfig = PluginConfig<\n 'markdown',\n {\n /**\n * Configuration for allowed node types. Cannot be combined with\n * disallowedNodes.\n */\n allowedNodes: PlateType[] | null;\n /**\n * Configuration for disallowed node types. Cannot be combined with\n * allowedNodes.\n *\n * @default null\n */\n disallowedNodes: PlateType[] | null;\n /**\n * Array of remark plugins to extend Markdown parsing and serialization\n * functionality. For example, you can add remark-gfm to support GFM syntax,\n * remark-math to support mathematical formulas, etc. These plugins will be\n * used during the parsing and generation of Markdown text.\n *\n * @default undefined\n */\n remarkPlugins: Plugin[];\n /**\n * Custom options passed to remark-stringify.\n *\n * @default null\n */\n remarkStringifyOptions: RemarkStringifyOptions | null;\n /**\n * Rules that define how to convert Markdown syntax elements to Slate editor\n * elements. Or rules that how to convert Slate editor elements to Markdown\n * syntax elements. Includes conversion rules for elements such as\n * paragraphs, headings, lists, links, images, etc.\n *\n * You can pass null disable default node parser.\n *\n * NOTE: don't forget pass `mark:true` when you custom inline nodes.\n *\n * @default null\n */\n rules: MdRules | null;\n /**\n * Custom filter function for nodes during deserialization and\n * serialization.\n *\n * @default null\n */\n allowNode?: AllowNodeConfig;\n /**\n * Marks to treat as plain text without applying markdown formatting.\n *\n * @default null\n */\n plainMarks?: PlateType[] | null;\n },\n {\n markdown: {\n deserialize: OmitFirst<typeof deserializeMd>;\n deserializeInline: OmitFirst<typeof deserializeInlineMd>;\n serialize: OmitFirst<typeof serializeMd>;\n };\n }\n>;\n\nexport const MarkdownPlugin = createTSlatePlugin<MarkdownConfig>({\n key: KEYS.markdown,\n options: {\n allowedNodes: null,\n disallowedNodes: null,\n plainMarks: null,\n remarkPlugins: [],\n remarkStringifyOptions: null,\n rules: null,\n },\n})\n .extendApi(({ editor }) => ({\n deserialize: bindFirst(deserializeMd, editor),\n deserializeInline: bindFirst(deserializeInlineMd, editor),\n serialize: bindFirst(serializeMd, editor),\n }))\n .extend(({ api }) => ({\n parser: {\n format: 'text/plain',\n deserialize: ({ data }) => api.markdown.deserialize(data),\n query: ({ data, dataTransfer }) => {\n const htmlData = dataTransfer.getData('text/html');\n\n if (htmlData) return false;\n\n const { files } = dataTransfer;\n\n if (\n !files?.length && // if content is simply a URL pass through to not break LinkPlugin\n isUrl(data)\n ) {\n return false;\n }\n\n return true;\n },\n },\n }));\n","import baseRemarkMdx from 'remark-mdx';\n\nimport { REMARK_MDX_TAG, tagRemarkPlugin } from '../utils';\n\nexport const remarkMdx = tagRemarkPlugin(\n baseRemarkMdx,\n REMARK_MDX_TAG\n) as typeof baseRemarkMdx;\n","import type { Node, Parent, RootContent, Text } from 'mdast';\nimport type { Plugin } from 'unified';\n\nimport { visit } from 'unist-util-visit';\n\nexport type MentionNode = {\n children: { type: 'text'; value: string }[];\n type: 'mention';\n username: string;\n displayText?: string;\n};\n\ndeclare module 'mdast' {\n // biome-ignore lint/style/useConsistentTypeDefinitions: module augmentation requires interface\n interface StaticPhrasingContentMap {\n mention: MentionNode;\n }\n}\n\n/**\n * A remark plugin that converts @username patterns and [display\n * text](mention:id) patterns in text nodes into mention nodes. This plugin runs\n * after remark-gfm and transforms mention patterns into special mention nodes\n * that can be later converted into Plate mention elements.\n *\n * Supports two formats:\n *\n * - @username - Simple mention format (no spaces allowed)\n * - [display text](mention:id) - Markdown link-style format (supports spaces)\n */\nexport const remarkMention: Plugin = () => (tree: Node) => {\n // First, convert link nodes with mention: protocol to mention nodes\n visit(\n tree,\n 'link',\n (node: any, index: number, parent: Parent | undefined) => {\n if (!parent || typeof index !== 'number') return;\n\n // Check if this is a mention link\n if (node.url?.startsWith('mention:')) {\n let username = node.url.slice('mention:'.length);\n // Decode URL-encoded spaces and special characters\n username = decodeURIComponent(username);\n const displayText = node.children?.[0]?.value || username;\n\n const mentionNode: MentionNode = {\n children: [{ type: 'text', value: displayText }],\n displayText,\n type: 'mention',\n username,\n };\n\n parent.children[index] = mentionNode as any;\n }\n }\n );\n\n // Then process text nodes for @mentions\n visit(\n tree,\n 'text',\n (node: Text, index: number, parent: Parent | undefined) => {\n if (!parent || typeof index !== 'number') return;\n\n // Skip processing @mentions within link nodes\n // Links should remain as links, not be converted to mentions\n if (parent.type === 'link') return;\n\n // Pattern for @username mentions (no spaces)\n // Matches @username but excludes trailing punctuation\n const atMentionPattern = /(?:^|\\s)@([a-zA-Z0-9_-]+)(?=[\\s.,;:!?)]|$)/g;\n\n const parts: (MentionNode | Text)[] = [];\n let lastIndex = 0;\n\n const text = node.value;\n const allMatches: { end: number; node: MentionNode; start: number }[] =\n [];\n\n // Find all @username mentions\n let match: RegExpExecArray | null;\n\n while (true) {\n match = atMentionPattern.exec(text);\n\n if (!match) break;\n\n const mentionStart = match[0].startsWith(' ')\n ? match.index + 1\n : match.index;\n const mentionEnd =\n mentionStart + match[0].length - (match[0].startsWith(' ') ? 1 : 0);\n\n allMatches.push({\n end: mentionEnd,\n node: {\n children: [{ type: 'text', value: `@${match[1]}` }],\n type: 'mention',\n username: match[1],\n },\n start: mentionStart,\n });\n }\n\n // Sort matches by start position\n allMatches.sort((a, b) => a.start - b.start);\n\n // Build the parts array\n for (const matchInfo of allMatches) {\n if (matchInfo.start > lastIndex) {\n parts.push({\n type: 'text',\n value: text.slice(lastIndex, matchInfo.start),\n });\n }\n parts.push(matchInfo.node);\n lastIndex = matchInfo.end;\n }\n\n if (lastIndex < text.length) {\n parts.push({\n type: 'text',\n value: text.slice(lastIndex),\n });\n }\n\n if (parts.length > 0) {\n parent.children.splice(index, 1, ...(parts as RootContent[]));\n }\n }\n );\n};\n"],"mappings":";;;;;;;;;;;AAmPA,MAAMyG,iBAAiB;CACrB/B,GAAG;CACHC,YAAY;CACZW,MAAM;CACNO,SAAS;CACTL,MAAM;CACNZ,YAAY;CACZ8B,WAAW;CACXf,QAAQ;CACRD,cAAc;CACdQ,SAAS;CACTF,MAAM;CACNnB,UAAU;CACVZ,SAAS;CACTa,IAAI;CACJC,KAAK;CACLC,iBAAiB;CACjBO,QAAQ;CACRoB,IAAI;CACJ3C,MAAM;CACN+B,SAAS;CACTd,GAAG;CACHQ,eAAe;CACfW,WAAW;CACXC,YAAY;CACZF,aAAa;CACbjB,OAAO;CACPC,IAAI;CACJpB,MAAM;CACNqB,IAAI;CACJQ,KAAK;CACLE,QAAQ;CACRT,IAAI;CACJY,WAAW;CACZ;AAED,MAAMY,iBAAiB;CACrBC,iBAAiB;CACjBnC,YAAY;CACZN,OAAO;CACPmB,MAAM;CACNuB,OAAO;CACP5C,YAAY;CACZ6C,KAAK;CACLC,QAAQ;CACRC,UAAU;CACVC,YAAY;CACZC,UAAU;CACVC,YAAY;CACZjD,oBAAoB;CACpBF,mBAAmB;CACnBD,SAAS;CACTQ,MAAM;CACN6C,OAAO;CACP/C,gBAAgB;CAChBgD,YAAY;CACZC,YAAY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