@payloadcms/richtext-lexical 4.0.0-canary.2 → 4.0.0-internal.011fd46

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.
Files changed (150) hide show
  1. package/dist/exports/client/Field-VQX3RNMF.js +2 -0
  2. package/dist/exports/client/{Field-G5Z2HM5Y.js.map → Field-VQX3RNMF.js.map} +3 -3
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/chunk-X3D4LZS7.js +2 -0
  5. package/dist/exports/client/chunk-X3D4LZS7.js.map +7 -0
  6. package/dist/exports/client/index.js +22 -20
  7. package/dist/exports/client/index.js.map +4 -4
  8. package/dist/features/blockquote/markdownTransformer.d.ts +1 -1
  9. package/dist/features/blockquote/markdownTransformer.d.ts.map +1 -1
  10. package/dist/features/blockquote/markdownTransformer.js.map +1 -1
  11. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.d.ts +1 -1
  12. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.d.ts.map +1 -1
  13. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.js +1 -1
  14. package/dist/features/blocks/client/markdown/getLexicalToMarkdown.js.map +1 -1
  15. package/dist/features/blocks/client/markdown/getMarkdownToLexical.d.ts +1 -1
  16. package/dist/features/blocks/client/markdown/getMarkdownToLexical.d.ts.map +1 -1
  17. package/dist/features/blocks/client/markdown/getMarkdownToLexical.js +1 -1
  18. package/dist/features/blocks/client/markdown/getMarkdownToLexical.js.map +1 -1
  19. package/dist/features/blocks/client/markdown/markdownTransformer.d.ts +1 -2
  20. package/dist/features/blocks/client/markdown/markdownTransformer.d.ts.map +1 -1
  21. package/dist/features/blocks/client/markdown/markdownTransformer.js.map +1 -1
  22. package/dist/features/blocks/server/markdown/markdownTransformer.d.ts +1 -1
  23. package/dist/features/blocks/server/markdown/markdownTransformer.d.ts.map +1 -1
  24. package/dist/features/blocks/server/markdown/markdownTransformer.js.map +1 -1
  25. package/dist/features/converters/lexicalToMarkdown/index.d.ts.map +1 -1
  26. package/dist/features/converters/lexicalToMarkdown/index.js +1 -1
  27. package/dist/features/converters/lexicalToMarkdown/index.js.map +1 -1
  28. package/dist/features/converters/markdownToLexical/index.js +1 -1
  29. package/dist/features/converters/markdownToLexical/index.js.map +1 -1
  30. package/dist/features/experimental_table/markdownTransformer.d.ts +1 -1
  31. package/dist/features/experimental_table/markdownTransformer.d.ts.map +1 -1
  32. package/dist/features/experimental_table/markdownTransformer.js +1 -1
  33. package/dist/features/experimental_table/markdownTransformer.js.map +1 -1
  34. package/dist/features/format/bold/markdownTransformers.d.ts +1 -1
  35. package/dist/features/format/bold/markdownTransformers.d.ts.map +1 -1
  36. package/dist/features/format/bold/markdownTransformers.js.map +1 -1
  37. package/dist/features/format/inlineCode/markdownTransformers.d.ts +1 -1
  38. package/dist/features/format/inlineCode/markdownTransformers.d.ts.map +1 -1
  39. package/dist/features/format/inlineCode/markdownTransformers.js.map +1 -1
  40. package/dist/features/format/italic/markdownTransformers.d.ts +1 -1
  41. package/dist/features/format/italic/markdownTransformers.d.ts.map +1 -1
  42. package/dist/features/format/italic/markdownTransformers.js.map +1 -1
  43. package/dist/features/format/strikethrough/markdownTransformers.d.ts +1 -1
  44. package/dist/features/format/strikethrough/markdownTransformers.d.ts.map +1 -1
  45. package/dist/features/format/strikethrough/markdownTransformers.js.map +1 -1
  46. package/dist/features/heading/markdownTransformer.d.ts +1 -1
  47. package/dist/features/heading/markdownTransformer.d.ts.map +1 -1
  48. package/dist/features/heading/markdownTransformer.js.map +1 -1
  49. package/dist/features/horizontalRule/client/markdownTransformer.d.ts +1 -1
  50. package/dist/features/horizontalRule/client/markdownTransformer.d.ts.map +1 -1
  51. package/dist/features/horizontalRule/client/markdownTransformer.js.map +1 -1
  52. package/dist/features/horizontalRule/server/markdownTransformer.d.ts +1 -1
  53. package/dist/features/horizontalRule/server/markdownTransformer.d.ts.map +1 -1
  54. package/dist/features/horizontalRule/server/markdownTransformer.js.map +1 -1
  55. package/dist/features/link/markdownTransformer.d.ts +1 -1
  56. package/dist/features/link/markdownTransformer.d.ts.map +1 -1
  57. package/dist/features/link/markdownTransformer.js.map +1 -1
  58. package/dist/features/link/markdownTransformer.spec.js +1 -1
  59. package/dist/features/link/markdownTransformer.spec.js.map +1 -1
  60. package/dist/features/lists/checklist/markdownTransformers.d.ts +1 -1
  61. package/dist/features/lists/checklist/markdownTransformers.d.ts.map +1 -1
  62. package/dist/features/lists/checklist/markdownTransformers.js.map +1 -1
  63. package/dist/features/lists/orderedList/markdownTransformer.d.ts +1 -1
  64. package/dist/features/lists/orderedList/markdownTransformer.d.ts.map +1 -1
  65. package/dist/features/lists/orderedList/markdownTransformer.js.map +1 -1
  66. package/dist/features/lists/shared/markdown.d.ts +1 -1
  67. package/dist/features/lists/shared/markdown.d.ts.map +1 -1
  68. package/dist/features/lists/shared/markdown.js.map +1 -1
  69. package/dist/features/lists/unorderedList/markdownTransformer.d.ts +1 -1
  70. package/dist/features/lists/unorderedList/markdownTransformer.d.ts.map +1 -1
  71. package/dist/features/lists/unorderedList/markdownTransformer.js.map +1 -1
  72. package/dist/features/toolbars/shared/useToolbarStates.d.ts.map +1 -1
  73. package/dist/features/toolbars/shared/useToolbarStates.js +3 -1
  74. package/dist/features/toolbars/shared/useToolbarStates.js.map +1 -1
  75. package/dist/features/typesClient.d.ts +1 -1
  76. package/dist/features/typesClient.d.ts.map +1 -1
  77. package/dist/features/typesClient.js.map +1 -1
  78. package/dist/features/typesServer.d.ts +1 -1
  79. package/dist/features/typesServer.d.ts.map +1 -1
  80. package/dist/features/typesServer.js.map +1 -1
  81. package/dist/features/upload/server/markdownTransformer.d.ts +1 -1
  82. package/dist/features/upload/server/markdownTransformer.d.ts.map +1 -1
  83. package/dist/features/upload/server/markdownTransformer.js.map +1 -1
  84. package/dist/field/bundled.css +1 -1
  85. package/dist/field/index.css +3 -4
  86. package/dist/index.d.ts +2 -2
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +2 -2
  89. package/dist/index.js.map +1 -1
  90. package/dist/lexical/plugins/MarkdownShortcut/index.d.ts.map +1 -1
  91. package/dist/lexical/plugins/MarkdownShortcut/index.js +1 -1
  92. package/dist/lexical/plugins/MarkdownShortcut/index.js.map +1 -1
  93. package/dist/lexical/utils/markdown/createBlockNode.d.ts +1 -1
  94. package/dist/lexical/utils/markdown/createBlockNode.d.ts.map +1 -1
  95. package/dist/lexical/utils/markdown/createBlockNode.js.map +1 -1
  96. package/dist/lexical/utils/markdown/normalizeMarkdown.d.ts +28 -0
  97. package/dist/lexical/utils/markdown/normalizeMarkdown.d.ts.map +1 -0
  98. package/dist/lexical/utils/markdown/normalizeMarkdown.js +95 -0
  99. package/dist/lexical/utils/markdown/normalizeMarkdown.js.map +1 -0
  100. package/dist/lexical-proxy/@lexical-markdown.d.ts +40 -1
  101. package/dist/lexical-proxy/@lexical-markdown.d.ts.map +1 -1
  102. package/dist/lexical-proxy/@lexical-markdown.js +56 -1
  103. package/dist/lexical-proxy/@lexical-markdown.js.map +1 -1
  104. package/dist/lexical-proxy/@lexical-markdown.spec.js +89 -0
  105. package/dist/lexical-proxy/@lexical-markdown.spec.js.map +1 -0
  106. package/dist/utilities/fieldsDrawer/index.css +0 -4
  107. package/package.json +21 -25
  108. package/dist/exports/client/Field-G5Z2HM5Y.js +0 -2
  109. package/dist/exports/client/chunk-LH634DPU.js +0 -12
  110. package/dist/exports/client/chunk-LH634DPU.js.map +0 -7
  111. package/dist/lexical-proxy/@lexical-react/LexicalContextMenuPlugin.d.ts +0 -2
  112. package/dist/lexical-proxy/@lexical-react/LexicalContextMenuPlugin.d.ts.map +0 -1
  113. package/dist/lexical-proxy/@lexical-react/LexicalContextMenuPlugin.js +0 -2
  114. package/dist/lexical-proxy/@lexical-react/LexicalContextMenuPlugin.js.map +0 -1
  115. package/dist/packages/@lexical/markdown/MarkdownExport.d.ts +0 -14
  116. package/dist/packages/@lexical/markdown/MarkdownExport.d.ts.map +0 -1
  117. package/dist/packages/@lexical/markdown/MarkdownExport.js +0 -213
  118. package/dist/packages/@lexical/markdown/MarkdownExport.js.map +0 -1
  119. package/dist/packages/@lexical/markdown/MarkdownImport.d.ts +0 -19
  120. package/dist/packages/@lexical/markdown/MarkdownImport.d.ts.map +0 -1
  121. package/dist/packages/@lexical/markdown/MarkdownImport.js +0 -198
  122. package/dist/packages/@lexical/markdown/MarkdownImport.js.map +0 -1
  123. package/dist/packages/@lexical/markdown/MarkdownShortcuts.d.ts +0 -11
  124. package/dist/packages/@lexical/markdown/MarkdownShortcuts.d.ts.map +0 -1
  125. package/dist/packages/@lexical/markdown/MarkdownShortcuts.js +0 -304
  126. package/dist/packages/@lexical/markdown/MarkdownShortcuts.js.map +0 -1
  127. package/dist/packages/@lexical/markdown/MarkdownTransformers.d.ts +0 -147
  128. package/dist/packages/@lexical/markdown/MarkdownTransformers.d.ts.map +0 -1
  129. package/dist/packages/@lexical/markdown/MarkdownTransformers.js +0 -268
  130. package/dist/packages/@lexical/markdown/MarkdownTransformers.js.map +0 -1
  131. package/dist/packages/@lexical/markdown/importTextFormatTransformer.d.ts +0 -22
  132. package/dist/packages/@lexical/markdown/importTextFormatTransformer.d.ts.map +0 -1
  133. package/dist/packages/@lexical/markdown/importTextFormatTransformer.js +0 -91
  134. package/dist/packages/@lexical/markdown/importTextFormatTransformer.js.map +0 -1
  135. package/dist/packages/@lexical/markdown/importTextMatchTransformer.d.ts +0 -21
  136. package/dist/packages/@lexical/markdown/importTextMatchTransformer.d.ts.map +0 -1
  137. package/dist/packages/@lexical/markdown/importTextMatchTransformer.js +0 -54
  138. package/dist/packages/@lexical/markdown/importTextMatchTransformer.js.map +0 -1
  139. package/dist/packages/@lexical/markdown/importTextTransformers.d.ts +0 -18
  140. package/dist/packages/@lexical/markdown/importTextTransformers.d.ts.map +0 -1
  141. package/dist/packages/@lexical/markdown/importTextTransformers.js +0 -54
  142. package/dist/packages/@lexical/markdown/importTextTransformers.js.map +0 -1
  143. package/dist/packages/@lexical/markdown/index.d.ts +0 -29
  144. package/dist/packages/@lexical/markdown/index.d.ts.map +0 -1
  145. package/dist/packages/@lexical/markdown/index.js +0 -39
  146. package/dist/packages/@lexical/markdown/index.js.map +0 -1
  147. package/dist/packages/@lexical/markdown/utils.d.ts +0 -34
  148. package/dist/packages/@lexical/markdown/utils.d.ts.map +0 -1
  149. package/dist/packages/@lexical/markdown/utils.js +0 -267
  150. package/dist/packages/@lexical/markdown/utils.js.map +0 -1
@@ -1,213 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */import { $getRoot, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isTextNode } from 'lexical';
8
- import { isEmptyParagraph, transformersByType } from './utils.js';
9
- /**
10
- * Renders string from markdown. The selection is moved to the start after the operation.
11
- */
12
- export function createMarkdownExport(transformers, shouldPreserveNewLines = false) {
13
- const byType = transformersByType(transformers);
14
- const elementTransformers = [...byType.multilineElement, ...byType.element];
15
- const isNewlineDelimited = !shouldPreserveNewLines;
16
- // Export only uses text formats that are responsible for single format
17
- // e.g. it will filter out *** (bold, italic) and instead use separate ** and *
18
- const textFormatTransformers = byType.textFormat.filter(transformer => transformer.format.length === 1) // Make sure all text transformers that contain 'code' in their format are at the end of the array. Otherwise, formatted code like
19
- // <strong><code>code</code></strong> will be exported as `**Bold Code**`, as the code format will be applied first, and the bold format
20
- // will be applied second and thus skipped entirely, as the code format will prevent any further formatting.
21
- .sort((a, b) => {
22
- if (a.format.includes('code') && !b.format.includes('code')) {
23
- return 1;
24
- } else if (!a.format.includes('code') && b.format.includes('code')) {
25
- return -1;
26
- } else {
27
- return 0;
28
- }
29
- });
30
- return node => {
31
- const output = [];
32
- const children = (node || $getRoot()).getChildren();
33
- children.forEach((child, i) => {
34
- const result = exportTopLevelElements(child, elementTransformers, textFormatTransformers, byType.textMatch);
35
- if (result != null) {
36
- output.push(
37
- // separate consecutive group of texts with a line break: eg. ["hello", "world"] -> ["hello", "/nworld"]
38
- isNewlineDelimited && i > 0 && !isEmptyParagraph(child) && !isEmptyParagraph(children[i - 1]) ? '\n'.concat(result) : result);
39
- }
40
- });
41
- // Ensure consecutive groups of texts are at least \n\n apart while each empty paragraph render as a newline.
42
- // Eg. ["hello", "", "", "hi", "\nworld"] -> "hello\n\n\nhi\n\nworld"
43
- return output.join('\n');
44
- };
45
- }
46
- function exportTopLevelElements(node, elementTransformers, textTransformersIndex, textMatchTransformers) {
47
- for (const transformer of elementTransformers) {
48
- if (!transformer.export) {
49
- continue;
50
- }
51
- const result = transformer.export(node, _node => exportChildren(_node, textTransformersIndex, textMatchTransformers));
52
- if (result != null) {
53
- return result;
54
- }
55
- }
56
- if ($isElementNode(node)) {
57
- return exportChildren(node, textTransformersIndex, textMatchTransformers);
58
- } else if ($isDecoratorNode(node)) {
59
- return node.getTextContent();
60
- } else {
61
- return null;
62
- }
63
- }
64
- function exportChildren(node, textTransformersIndex, textMatchTransformers, unclosedTags, unclosableTags) {
65
- const output = [];
66
- const children = node.getChildren();
67
- // keep track of unclosed tags from the very beginning
68
- if (!unclosedTags) {
69
- unclosedTags = [];
70
- }
71
- if (!unclosableTags) {
72
- unclosableTags = [];
73
- }
74
- mainLoop: for (const child of children) {
75
- for (const transformer of textMatchTransformers) {
76
- if (!transformer.export) {
77
- continue;
78
- }
79
- const result = transformer.export(child, parentNode => exportChildren(parentNode, textTransformersIndex, textMatchTransformers, unclosedTags,
80
- // Add current unclosed tags to the list of unclosable tags - we don't want nested tags from
81
- // textmatch transformers to close the outer ones, as that may result in invalid markdown.
82
- // E.g. **text [text**](https://lexical.io)
83
- // is invalid markdown, as the closing ** is inside the link.
84
- //
85
- [...unclosableTags, ...unclosedTags]), (textNode, textContent) => exportTextFormat(textNode, textContent, textTransformersIndex, unclosedTags, unclosableTags));
86
- if (result != null) {
87
- output.push(result);
88
- continue mainLoop;
89
- }
90
- }
91
- if ($isLineBreakNode(child)) {
92
- output.push('\n');
93
- } else if ($isTextNode(child)) {
94
- output.push(exportTextFormat(child, child.getTextContent(), textTransformersIndex, unclosedTags, unclosableTags));
95
- } else if ($isElementNode(child)) {
96
- // empty paragraph returns ""
97
- output.push(exportChildren(child, textTransformersIndex, textMatchTransformers, unclosedTags, unclosableTags));
98
- } else if ($isDecoratorNode(child)) {
99
- output.push(child.getTextContent());
100
- }
101
- }
102
- return output.join('');
103
- }
104
- function exportTextFormat(node, textContent, textTransformers,
105
- // unclosed tags include the markdown tags that haven't been closed yet, and their associated formats
106
- unclosedTags, unclosableTags) {
107
- // This function handles the case of a string looking like this: " foo "
108
- // Where it would be invalid markdown to generate: "** foo **"
109
- // We instead want to trim the whitespace out, apply formatting, and then
110
- // bring the whitespace back. So our returned string looks like this: " **foo** "
111
- const frozenString = textContent.trim();
112
- let output = frozenString;
113
- if (!node.hasFormat('code')) {
114
- // Escape any markdown characters in the text content
115
- output = output.replace(/([*_`~\\])/g, '\\$1');
116
- }
117
- // the opening tags to be added to the result
118
- let openingTags = '';
119
- // the closing tags to be added to the result
120
- let closingTagsBefore = '';
121
- let closingTagsAfter = '';
122
- const prevNode = getTextSibling(node, true);
123
- const nextNode = getTextSibling(node, false);
124
- const applied = new Set();
125
- for (const transformer of textTransformers) {
126
- const format = transformer.format[0];
127
- const tag = transformer.tag;
128
- // dedup applied formats
129
- if (hasFormat(node, format) && !applied.has(format)) {
130
- // Multiple tags might be used for the same format (*, _)
131
- applied.add(format);
132
- // append the tag to openningTags, if it's not applied to the previous nodes,
133
- // or the nodes before that (which would result in an unclosed tag)
134
- if (!hasFormat(prevNode, format) || !unclosedTags.find(element => element.tag === tag)) {
135
- unclosedTags.push({
136
- format,
137
- tag
138
- });
139
- openingTags += tag;
140
- }
141
- }
142
- }
143
- // close any tags in the same order they were applied, if necessary
144
- for (let i = 0; i < unclosedTags.length; i++) {
145
- const unclosedTag = unclosedTags[i];
146
- const nodeHasFormat = hasFormat(node, unclosedTag.format);
147
- const nextNodeHasFormat = hasFormat(nextNode, unclosedTag.format);
148
- // prevent adding closing tag if next sibling will do it
149
- if (nodeHasFormat && nextNodeHasFormat) {
150
- continue;
151
- }
152
- const unhandledUnclosedTags = [...unclosedTags] // Shallow copy to avoid modifying the original array
153
- ;
154
- while (unhandledUnclosedTags.length > i) {
155
- const unclosedTag = unhandledUnclosedTags.pop();
156
- // If tag is unclosable, don't close it and leave it in the original array,
157
- // So that it can be closed when it's no longer unclosable
158
- if (unclosableTags && unclosedTag && unclosableTags.find(element => element.tag === unclosedTag.tag)) {
159
- continue;
160
- }
161
- if (unclosedTag && typeof unclosedTag.tag === 'string') {
162
- if (!nodeHasFormat) {
163
- // Handles cases where the tag has not been closed before, e.g. if the previous node
164
- // was a text match transformer that did not account for closing tags of the next node (e.g. a link)
165
- closingTagsBefore += unclosedTag.tag;
166
- } else if (!nextNodeHasFormat) {
167
- closingTagsAfter += unclosedTag.tag;
168
- }
169
- }
170
- // Mutate the original array to remove the closed tag
171
- unclosedTags.pop();
172
- }
173
- break;
174
- }
175
- output = openingTags + output + closingTagsAfter;
176
- // Replace trimmed version of textContent ensuring surrounding whitespace is not modified
177
- return closingTagsBefore + textContent.replace(frozenString, () => output);
178
- }
179
- // Get next or previous text sibling a text node, including cases
180
- // when it's a child of inline element (e.g. link)
181
- function getTextSibling(node, backward) {
182
- let sibling = backward ? node.getPreviousSibling() : node.getNextSibling();
183
- if (!sibling) {
184
- const parent = node.getParentOrThrow();
185
- if (parent.isInline()) {
186
- sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling();
187
- }
188
- }
189
- while (sibling) {
190
- if ($isElementNode(sibling)) {
191
- if (!sibling.isInline()) {
192
- break;
193
- }
194
- const descendant = backward ? sibling.getLastDescendant() : sibling.getFirstDescendant();
195
- if ($isTextNode(descendant)) {
196
- return descendant;
197
- } else {
198
- sibling = backward ? sibling.getPreviousSibling() : sibling.getNextSibling();
199
- }
200
- }
201
- if ($isTextNode(sibling)) {
202
- return sibling;
203
- }
204
- if (!$isElementNode(sibling)) {
205
- return null;
206
- }
207
- }
208
- return null;
209
- }
210
- function hasFormat(node, format) {
211
- return $isTextNode(node) && node.hasFormat(format);
212
- }
213
- //# sourceMappingURL=MarkdownExport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownExport.js","names":["$getRoot","$isDecoratorNode","$isElementNode","$isLineBreakNode","$isTextNode","isEmptyParagraph","transformersByType","createMarkdownExport","transformers","shouldPreserveNewLines","byType","elementTransformers","multilineElement","element","isNewlineDelimited","textFormatTransformers","textFormat","filter","transformer","format","length","sort","a","b","includes","node","output","children","getChildren","forEach","child","i","result","exportTopLevelElements","textMatch","push","concat","join","textTransformersIndex","textMatchTransformers","export","_node","exportChildren","getTextContent","unclosedTags","unclosableTags","mainLoop","parentNode","textNode","textContent","exportTextFormat","textTransformers","frozenString","trim","hasFormat","replace","openingTags","closingTagsBefore","closingTagsAfter","prevNode","getTextSibling","nextNode","applied","Set","tag","has","add","find","unclosedTag","nodeHasFormat","nextNodeHasFormat","unhandledUnclosedTags","pop","backward","sibling","getPreviousSibling","getNextSibling","parent","getParentOrThrow","isInline","descendant","getLastDescendant","getFirstDescendant"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownExport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ElementNode, LexicalNode, TextFormatType, TextNode } from 'lexical'\n\nimport { $getRoot, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isTextNode } from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\n/**\n * Renders string from markdown. The selection is moved to the start after the operation.\n */\nexport function createMarkdownExport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines: boolean = false,\n): (node?: ElementNode) => string {\n const byType = transformersByType(transformers)\n const elementTransformers = [...byType.multilineElement, ...byType.element]\n const isNewlineDelimited = !shouldPreserveNewLines\n\n // Export only uses text formats that are responsible for single format\n // e.g. it will filter out *** (bold, italic) and instead use separate ** and *\n const textFormatTransformers = byType.textFormat\n .filter((transformer) => transformer.format.length === 1)\n // Make sure all text transformers that contain 'code' in their format are at the end of the array. Otherwise, formatted code like\n // <strong><code>code</code></strong> will be exported as `**Bold Code**`, as the code format will be applied first, and the bold format\n // will be applied second and thus skipped entirely, as the code format will prevent any further formatting.\n .sort((a, b) => {\n if (a.format.includes('code') && !b.format.includes('code')) {\n return 1\n } else if (!a.format.includes('code') && b.format.includes('code')) {\n return -1\n } else {\n return 0\n }\n })\n\n return (node) => {\n const output: string[] = []\n const children = (node || $getRoot()).getChildren()\n\n children.forEach((child, i) => {\n const result = exportTopLevelElements(\n child,\n elementTransformers,\n textFormatTransformers,\n byType.textMatch,\n )\n\n if (result != null) {\n output.push(\n // separate consecutive group of texts with a line break: eg. [\"hello\", \"world\"] -> [\"hello\", \"/nworld\"]\n isNewlineDelimited &&\n i > 0 &&\n !isEmptyParagraph(child) &&\n !isEmptyParagraph(children[i - 1]!)\n ? '\\n'.concat(result)\n : result,\n )\n }\n })\n // Ensure consecutive groups of texts are at least \\n\\n apart while each empty paragraph render as a newline.\n // Eg. [\"hello\", \"\", \"\", \"hi\", \"\\nworld\"] -> \"hello\\n\\n\\nhi\\n\\nworld\"\n return output.join('\\n')\n }\n}\n\nfunction exportTopLevelElements(\n node: LexicalNode,\n elementTransformers: Array<ElementTransformer | MultilineElementTransformer>,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n): null | string {\n for (const transformer of elementTransformers) {\n if (!transformer.export) {\n continue\n }\n const result = transformer.export(node, (_node) =>\n exportChildren(_node, textTransformersIndex, textMatchTransformers),\n )\n\n if (result != null) {\n return result\n }\n }\n\n if ($isElementNode(node)) {\n return exportChildren(node, textTransformersIndex, textMatchTransformers)\n } else if ($isDecoratorNode(node)) {\n return node.getTextContent()\n } else {\n return null\n }\n}\n\nfunction exportChildren(\n node: ElementNode,\n textTransformersIndex: Array<TextFormatTransformer>,\n textMatchTransformers: Array<TextMatchTransformer>,\n unclosedTags?: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n const output = []\n const children = node.getChildren()\n // keep track of unclosed tags from the very beginning\n if (!unclosedTags) {\n unclosedTags = []\n }\n if (!unclosableTags) {\n unclosableTags = []\n }\n\n mainLoop: for (const child of children) {\n for (const transformer of textMatchTransformers) {\n if (!transformer.export) {\n continue\n }\n\n const result = transformer.export(\n child,\n (parentNode) =>\n exportChildren(\n parentNode,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n // Add current unclosed tags to the list of unclosable tags - we don't want nested tags from\n // textmatch transformers to close the outer ones, as that may result in invalid markdown.\n // E.g. **text [text**](https://lexical.io)\n // is invalid markdown, as the closing ** is inside the link.\n //\n [...unclosableTags, ...unclosedTags],\n ),\n (textNode, textContent) =>\n exportTextFormat(\n textNode,\n textContent,\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n\n if (result != null) {\n output.push(result)\n continue mainLoop\n }\n }\n\n if ($isLineBreakNode(child)) {\n output.push('\\n')\n } else if ($isTextNode(child)) {\n output.push(\n exportTextFormat(\n child,\n child.getTextContent(),\n textTransformersIndex,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isElementNode(child)) {\n // empty paragraph returns \"\"\n output.push(\n exportChildren(\n child,\n textTransformersIndex,\n textMatchTransformers,\n unclosedTags,\n unclosableTags,\n ),\n )\n } else if ($isDecoratorNode(child)) {\n output.push(child.getTextContent())\n }\n }\n\n return output.join('')\n}\n\nfunction exportTextFormat(\n node: TextNode,\n textContent: string,\n textTransformers: Array<TextFormatTransformer>,\n // unclosed tags include the markdown tags that haven't been closed yet, and their associated formats\n unclosedTags: Array<{ format: TextFormatType; tag: string }>,\n unclosableTags?: Array<{ format: TextFormatType; tag: string }>,\n): string {\n // This function handles the case of a string looking like this: \" foo \"\n // Where it would be invalid markdown to generate: \"** foo **\"\n // We instead want to trim the whitespace out, apply formatting, and then\n // bring the whitespace back. So our returned string looks like this: \" **foo** \"\n const frozenString = textContent.trim()\n let output = frozenString\n\n if (!node.hasFormat('code')) {\n // Escape any markdown characters in the text content\n output = output.replace(/([*_`~\\\\])/g, '\\\\$1')\n }\n\n // the opening tags to be added to the result\n let openingTags = ''\n // the closing tags to be added to the result\n let closingTagsBefore = ''\n let closingTagsAfter = ''\n\n const prevNode = getTextSibling(node, true)\n const nextNode = getTextSibling(node, false)\n\n const applied = new Set()\n\n for (const transformer of textTransformers) {\n const format = transformer.format[0]!\n const tag = transformer.tag\n\n // dedup applied formats\n if (hasFormat(node, format) && !applied.has(format)) {\n // Multiple tags might be used for the same format (*, _)\n applied.add(format)\n\n // append the tag to openningTags, if it's not applied to the previous nodes,\n // or the nodes before that (which would result in an unclosed tag)\n if (!hasFormat(prevNode, format) || !unclosedTags.find((element) => element.tag === tag)) {\n unclosedTags.push({ format, tag })\n openingTags += tag\n }\n }\n }\n\n // close any tags in the same order they were applied, if necessary\n for (let i = 0; i < unclosedTags.length; i++) {\n const unclosedTag = unclosedTags[i]!\n const nodeHasFormat = hasFormat(node, unclosedTag.format)\n const nextNodeHasFormat = hasFormat(nextNode, unclosedTag.format)\n\n // prevent adding closing tag if next sibling will do it\n if (nodeHasFormat && nextNodeHasFormat) {\n continue\n }\n\n const unhandledUnclosedTags = [...unclosedTags] // Shallow copy to avoid modifying the original array\n\n while (unhandledUnclosedTags.length > i) {\n const unclosedTag = unhandledUnclosedTags.pop()\n\n // If tag is unclosable, don't close it and leave it in the original array,\n // So that it can be closed when it's no longer unclosable\n if (\n unclosableTags &&\n unclosedTag &&\n unclosableTags.find((element) => element.tag === unclosedTag.tag)\n ) {\n continue\n }\n\n if (unclosedTag && typeof unclosedTag.tag === 'string') {\n if (!nodeHasFormat) {\n // Handles cases where the tag has not been closed before, e.g. if the previous node\n // was a text match transformer that did not account for closing tags of the next node (e.g. a link)\n closingTagsBefore += unclosedTag.tag\n } else if (!nextNodeHasFormat) {\n closingTagsAfter += unclosedTag.tag\n }\n }\n // Mutate the original array to remove the closed tag\n unclosedTags.pop()\n }\n break\n }\n\n output = openingTags + output + closingTagsAfter\n // Replace trimmed version of textContent ensuring surrounding whitespace is not modified\n return closingTagsBefore + textContent.replace(frozenString, () => output)\n}\n\n// Get next or previous text sibling a text node, including cases\n// when it's a child of inline element (e.g. link)\nfunction getTextSibling(node: TextNode, backward: boolean): null | TextNode {\n let sibling = backward ? node.getPreviousSibling() : node.getNextSibling()\n\n if (!sibling) {\n const parent = node.getParentOrThrow()\n\n if (parent.isInline()) {\n sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling()\n }\n }\n\n while (sibling) {\n if ($isElementNode(sibling)) {\n if (!sibling.isInline()) {\n break\n }\n\n const descendant = backward ? sibling.getLastDescendant() : sibling.getFirstDescendant()\n\n if ($isTextNode(descendant)) {\n return descendant\n } else {\n sibling = backward ? sibling.getPreviousSibling() : sibling.getNextSibling()\n }\n }\n\n if ($isTextNode(sibling)) {\n return sibling\n }\n\n if (!$isElementNode(sibling)) {\n return null\n }\n }\n\n return null\n}\n\nfunction hasFormat(node: LexicalNode | null | undefined, format: TextFormatType): boolean {\n return $isTextNode(node) && node.hasFormat(format)\n}\n"],"mappings":"AAAA;;;;;;GAUA,SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ;AAU1F,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ;AAErD;;;AAGA,OAAO,SAASC,qBACdC,YAAgC,EAChCC,sBAAA,GAAkC,KAAK;EAEvC,MAAMC,MAAA,GAASJ,kBAAA,CAAmBE,YAAA;EAClC,MAAMG,mBAAA,GAAsB,C,GAAID,MAAA,CAAOE,gBAAgB,E,GAAKF,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xE,WAAA,CAAYsE,OAAA,GAAU;MACxB,OAAOA,OAAA;IACT;IAEA,IAAI,CAACxE,cAAA,CAAewE,OAAA,GAAU;MAC5B,OAAO;IACT;EACF;EAEA,OAAO;AACT;AAEA,SAASpB,UAAU7B,IAAoC,EAAEN,MAAsB;EAC7E,OAAOf,WAAA,CAAYqB,IAAA,KAASA,IAAA,CAAK6B,SAAS,CAACnC,MAAA;AAC7C","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import type { ElementNode } from 'lexical';
9
- import type { TextFormatTransformer, Transformer } from './MarkdownTransformers.js';
10
- export type TextFormatTransformersIndex = Readonly<{
11
- fullMatchRegExpByTag: Readonly<Record<string, RegExp>>;
12
- openTagsRegExp: RegExp;
13
- transformersByTag: Readonly<Record<string, TextFormatTransformer>>;
14
- }>;
15
- /**
16
- * Renders markdown from a string. The selection is moved to the start after the operation.
17
- */
18
- export declare function createMarkdownImport(transformers: Array<Transformer>, shouldPreserveNewLines?: boolean): (markdownString: string, node?: ElementNode) => void;
19
- //# sourceMappingURL=MarkdownImport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAc1C,OAAO,KAAK,EAGV,qBAAqB,EAErB,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAKlC,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAA;CACnE,CAAC,CAAA;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,EAChC,sBAAsB,UAAQ,GAC7B,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,IAAI,CAyCtD"}
@@ -1,198 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */import { $isListItemNode, $isListNode } from '@lexical/list';
8
- import { $isQuoteNode } from '@lexical/rich-text';
9
- import { $findMatchingParent } from '@lexical/utils';
10
- import { $createLineBreakNode, $createParagraphNode, $createTextNode, $getRoot, $getSelection, $isParagraphNode } from 'lexical';
11
- import { importTextTransformers } from './importTextTransformers.js';
12
- import { isEmptyParagraph, transformersByType } from './utils.js';
13
- /**
14
- * Renders markdown from a string. The selection is moved to the start after the operation.
15
- */
16
- export function createMarkdownImport(transformers, shouldPreserveNewLines = false) {
17
- const byType = transformersByType(transformers);
18
- const textFormatTransformersIndex = createTextFormatTransformersIndex(byType.textFormat);
19
- return (markdownString, node) => {
20
- const lines = markdownString.split('\n');
21
- const linesLength = lines.length;
22
- const root = node || $getRoot();
23
- root.clear();
24
- for (let i = 0; i < linesLength; i++) {
25
- const lineText = lines[i];
26
- const [imported, shiftedIndex] = $importMultiline(lines, i, byType.multilineElement, root);
27
- if (imported) {
28
- // If a multiline markdown element was imported, we don't want to process the lines that were part of it anymore.
29
- // There could be other sub-markdown elements (both multiline and normal ones) matching within this matched multiline element's children.
30
- // However, it would be the responsibility of the matched multiline transformer to decide how it wants to handle them.
31
- // We cannot handle those, as there is no way for us to know how to maintain the correct order of generated lexical nodes for possible children.
32
- i = shiftedIndex; // Next loop will start from the line after the last line of the multiline element
33
- continue;
34
- }
35
- $importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch);
36
- }
37
- // By default, removing empty paragraphs as md does not really
38
- // allow empty lines and uses them as delimiter.
39
- // If you need empty lines set shouldPreserveNewLines = true.
40
- const children = root.getChildren();
41
- for (const child of children) {
42
- if (!shouldPreserveNewLines && isEmptyParagraph(child) && root.getChildrenSize() > 1) {
43
- child.remove();
44
- }
45
- }
46
- if ($getSelection() !== null) {
47
- root.selectStart();
48
- }
49
- };
50
- }
51
- /**
52
- *
53
- * @returns first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed.
54
- */
55
- function $importMultiline(lines, startLineIndex, multilineElementTransformers, rootNode) {
56
- for (const transformer of multilineElementTransformers) {
57
- const {
58
- handleImportAfterStartMatch,
59
- regExpEnd,
60
- regExpStart,
61
- replace
62
- } = transformer;
63
- const startMatch = lines[startLineIndex]?.match(regExpStart);
64
- if (!startMatch) {
65
- continue; // Try next transformer
66
- }
67
- if (handleImportAfterStartMatch) {
68
- const result = handleImportAfterStartMatch({
69
- lines,
70
- rootNode,
71
- startLineIndex,
72
- startMatch,
73
- transformer
74
- });
75
- if (result === null) {
76
- continue;
77
- } else if (result) {
78
- return result;
79
- }
80
- }
81
- const regexpEndRegex = typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd;
82
- const isEndOptional = regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd ? regExpEnd.optional : !regExpEnd;
83
- let endLineIndex = startLineIndex;
84
- const linesLength = lines.length;
85
- // check every single line for the closing match. It could also be on the same line as the opening match.
86
- while (endLineIndex < linesLength) {
87
- const endMatch = regexpEndRegex ? lines[endLineIndex]?.match(regexpEndRegex) : null;
88
- if (!endMatch) {
89
- if (!isEndOptional || isEndOptional && endLineIndex < linesLength - 1 // Optional end, but didn't reach the end of the document yet => continue searching for potential closing match
90
- ) {
91
- endLineIndex++;
92
- continue; // Search next line for closing match
93
- }
94
- }
95
- // Now, check if the closing match matched is the same as the opening match.
96
- // If it is, we need to continue searching for the actual closing match.
97
- if (endMatch && startLineIndex === endLineIndex && endMatch.index === startMatch.index) {
98
- endLineIndex++;
99
- continue; // Search next line for closing match
100
- }
101
- // At this point, we have found the closing match. Next: calculate the lines in between open and closing match
102
- // This should not include the matches themselves, and be split up by lines
103
- const linesInBetween = [];
104
- if (endMatch && startLineIndex === endLineIndex) {
105
- linesInBetween.push(lines[startLineIndex].slice(startMatch[0].length, -endMatch[0].length));
106
- } else {
107
- for (let i = startLineIndex; i <= endLineIndex; i++) {
108
- const line = lines[i];
109
- if (i === startLineIndex) {
110
- const text = line.slice(startMatch[0].length);
111
- linesInBetween.push(text); // Also include empty text
112
- } else if (i === endLineIndex && endMatch) {
113
- const text = line.slice(0, -endMatch[0].length);
114
- linesInBetween.push(text); // Also include empty text
115
- } else {
116
- linesInBetween.push(line);
117
- }
118
- }
119
- }
120
- if (replace(rootNode, null, startMatch, endMatch, linesInBetween, true) !== false) {
121
- // Return here. This $importMultiline function is run line by line and should only process a single multiline element at a time.
122
- return [true, endLineIndex];
123
- }
124
- break;
125
- }
126
- }
127
- // No multiline transformer handled this line successfully
128
- return [false, startLineIndex];
129
- }
130
- function $importBlocks(lineText, rootNode, elementTransformers, textFormatTransformersIndex, textMatchTransformers) {
131
- const textNode = $createTextNode(lineText);
132
- const elementNode = $createParagraphNode();
133
- elementNode.append(textNode);
134
- rootNode.append(elementNode);
135
- for (const {
136
- regExp,
137
- replace
138
- } of elementTransformers) {
139
- const match = lineText.match(regExp);
140
- if (match) {
141
- textNode.setTextContent(lineText.slice(match[0].length));
142
- if (replace(elementNode, [textNode], match, true) !== false) {
143
- break;
144
- }
145
- }
146
- }
147
- importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers);
148
- // If no transformer found and we left with original paragraph node
149
- // can check if its content can be appended to the previous node
150
- // if it's a paragraph, quote or list
151
- if (elementNode.isAttached() && lineText.length > 0) {
152
- const previousNode = elementNode.getPreviousSibling();
153
- if ($isParagraphNode(previousNode) || $isQuoteNode(previousNode) || $isListNode(previousNode)) {
154
- let targetNode = previousNode;
155
- if ($isListNode(previousNode)) {
156
- const lastDescendant = previousNode.getLastDescendant();
157
- if (lastDescendant == null) {
158
- targetNode = null;
159
- } else {
160
- targetNode = $findMatchingParent(lastDescendant, $isListItemNode);
161
- }
162
- }
163
- if (targetNode != null && targetNode.getTextContentSize() > 0) {
164
- targetNode.splice(targetNode.getChildrenSize(), 0, [$createLineBreakNode(), ...elementNode.getChildren()]);
165
- elementNode.remove();
166
- }
167
- }
168
- }
169
- }
170
- function createTextFormatTransformersIndex(textTransformers) {
171
- const transformersByTag = {};
172
- const fullMatchRegExpByTag = {};
173
- const openTagsRegExp = [];
174
- const escapeRegExp = `(?<![\\\\])`;
175
- for (const transformer of textTransformers) {
176
- const {
177
- tag
178
- } = transformer;
179
- transformersByTag[tag] = transformer;
180
- const tagRegExp = tag.replace(/([*^+])/g, '\\$1');
181
- openTagsRegExp.push(tagRegExp);
182
- // Single-char tag (e.g. "*"),
183
- if (tag.length === 1) {
184
- fullMatchRegExpByTag[tag] = new RegExp(`(?<![\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?![\\\\${tagRegExp}])`);
185
- } else {
186
- // Multi‐char tags (e.g. "**")
187
- fullMatchRegExpByTag[tag] = new RegExp(`(?<!\\\\)(${tagRegExp})((\\\\${tagRegExp})?.*?[^\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?!\\\\)`);
188
- }
189
- }
190
- return {
191
- // Reg exp to find open tag + content + close tag
192
- fullMatchRegExpByTag,
193
- // Regexp to locate *any* potential opening tag (longest first).
194
- openTagsRegExp: new RegExp(`${escapeRegExp}(${openTagsRegExp.join('|')})`, 'g'),
195
- transformersByTag
196
- };
197
- }
198
- //# sourceMappingURL=MarkdownImport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownImport.js","names":["$isListItemNode","$isListNode","$isQuoteNode","$findMatchingParent","$createLineBreakNode","$createParagraphNode","$createTextNode","$getRoot","$getSelection","$isParagraphNode","importTextTransformers","isEmptyParagraph","transformersByType","createMarkdownImport","transformers","shouldPreserveNewLines","byType","textFormatTransformersIndex","createTextFormatTransformersIndex","textFormat","markdownString","node","lines","split","linesLength","length","root","clear","i","lineText","imported","shiftedIndex","$importMultiline","multilineElement","$importBlocks","element","textMatch","children","getChildren","child","getChildrenSize","remove","selectStart","startLineIndex","multilineElementTransformers","rootNode","transformer","handleImportAfterStartMatch","regExpEnd","regExpStart","replace","startMatch","match","result","regexpEndRegex","regExp","isEndOptional","optional","endLineIndex","endMatch","index","linesInBetween","push","slice","line","text","elementTransformers","textMatchTransformers","textNode","elementNode","append","setTextContent","isAttached","previousNode","getPreviousSibling","targetNode","lastDescendant","getLastDescendant","getTextContentSize","splice","textTransformers","transformersByTag","fullMatchRegExpByTag","openTagsRegExp","escapeRegExp","tag","tagRegExp","RegExp","join"],"sources":["../../../../src/packages/@lexical/markdown/MarkdownImport.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { ListItemNode } from '@lexical/list'\nimport type { ElementNode } from 'lexical'\n\nimport { $isListItemNode, $isListNode } from '@lexical/list'\nimport { $isQuoteNode } from '@lexical/rich-text'\nimport { $findMatchingParent } from '@lexical/utils'\nimport {\n $createLineBreakNode,\n $createParagraphNode,\n $createTextNode,\n $getRoot,\n $getSelection,\n $isParagraphNode,\n} from 'lexical'\n\nimport type {\n ElementTransformer,\n MultilineElementTransformer,\n TextFormatTransformer,\n TextMatchTransformer,\n Transformer,\n} from './MarkdownTransformers.js'\n\nimport { importTextTransformers } from './importTextTransformers.js'\nimport { isEmptyParagraph, transformersByType } from './utils.js'\n\nexport type TextFormatTransformersIndex = Readonly<{\n fullMatchRegExpByTag: Readonly<Record<string, RegExp>>\n openTagsRegExp: RegExp\n transformersByTag: Readonly<Record<string, TextFormatTransformer>>\n}>\n\n/**\n * Renders markdown from a string. The selection is moved to the start after the operation.\n */\nexport function createMarkdownImport(\n transformers: Array<Transformer>,\n shouldPreserveNewLines = false,\n): (markdownString: string, node?: ElementNode) => void {\n const byType = transformersByType(transformers)\n const textFormatTransformersIndex = createTextFormatTransformersIndex(byType.textFormat)\n\n return (markdownString, node) => {\n const lines = markdownString.split('\\n')\n const linesLength = lines.length\n const root = node || $getRoot()\n root.clear()\n\n for (let i = 0; i < linesLength; i++) {\n const lineText = lines[i]!\n\n const [imported, shiftedIndex] = $importMultiline(lines, i, byType.multilineElement, root)\n\n if (imported) {\n // If a multiline markdown element was imported, we don't want to process the lines that were part of it anymore.\n // There could be other sub-markdown elements (both multiline and normal ones) matching within this matched multiline element's children.\n // However, it would be the responsibility of the matched multiline transformer to decide how it wants to handle them.\n // We cannot handle those, as there is no way for us to know how to maintain the correct order of generated lexical nodes for possible children.\n i = shiftedIndex // Next loop will start from the line after the last line of the multiline element\n continue\n }\n\n $importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch)\n }\n\n // By default, removing empty paragraphs as md does not really\n // allow empty lines and uses them as delimiter.\n // If you need empty lines set shouldPreserveNewLines = true.\n const children = root.getChildren()\n for (const child of children) {\n if (!shouldPreserveNewLines && isEmptyParagraph(child) && root.getChildrenSize() > 1) {\n child.remove()\n }\n }\n\n if ($getSelection() !== null) {\n root.selectStart()\n }\n }\n}\n\n/**\n *\n * @returns first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed.\n */\nfunction $importMultiline(\n lines: Array<string>,\n startLineIndex: number,\n multilineElementTransformers: Array<MultilineElementTransformer>,\n rootNode: ElementNode,\n): [boolean, number] {\n for (const transformer of multilineElementTransformers) {\n const { handleImportAfterStartMatch, regExpEnd, regExpStart, replace } = transformer\n\n const startMatch = lines[startLineIndex]?.match(regExpStart)\n if (!startMatch) {\n continue // Try next transformer\n }\n\n if (handleImportAfterStartMatch) {\n const result = handleImportAfterStartMatch({\n lines,\n rootNode,\n startLineIndex,\n startMatch,\n transformer,\n })\n if (result === null) {\n continue\n } else if (result) {\n return result\n }\n }\n\n const regexpEndRegex: RegExp | undefined =\n typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd\n\n const isEndOptional =\n regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd\n ? regExpEnd.optional\n : !regExpEnd\n\n let endLineIndex = startLineIndex\n const linesLength = lines.length\n\n // check every single line for the closing match. It could also be on the same line as the opening match.\n while (endLineIndex < linesLength) {\n const endMatch = regexpEndRegex ? lines[endLineIndex]?.match(regexpEndRegex) : null\n if (!endMatch) {\n if (\n !isEndOptional ||\n (isEndOptional && endLineIndex < linesLength - 1) // Optional end, but didn't reach the end of the document yet => continue searching for potential closing match\n ) {\n endLineIndex++\n continue // Search next line for closing match\n }\n }\n\n // Now, check if the closing match matched is the same as the opening match.\n // If it is, we need to continue searching for the actual closing match.\n if (endMatch && startLineIndex === endLineIndex && endMatch.index === startMatch.index) {\n endLineIndex++\n continue // Search next line for closing match\n }\n\n // At this point, we have found the closing match. Next: calculate the lines in between open and closing match\n // This should not include the matches themselves, and be split up by lines\n const linesInBetween: string[] = []\n\n if (endMatch && startLineIndex === endLineIndex) {\n linesInBetween.push(lines[startLineIndex]!.slice(startMatch[0].length, -endMatch[0].length))\n } else {\n for (let i = startLineIndex; i <= endLineIndex; i++) {\n const line = lines[i]!\n if (i === startLineIndex) {\n const text = line.slice(startMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else if (i === endLineIndex && endMatch) {\n const text = line.slice(0, -endMatch[0].length)\n linesInBetween.push(text) // Also include empty text\n } else {\n linesInBetween.push(line)\n }\n }\n }\n\n if (replace(rootNode, null, startMatch, endMatch!, linesInBetween, true) !== false) {\n // Return here. This $importMultiline function is run line by line and should only process a single multiline element at a time.\n return [true, endLineIndex]\n }\n\n // The replace function returned false, despite finding the matching open and close tags => this transformer does not want to handle it.\n // Thus, we continue letting the remaining transformers handle the passed lines of text from the beginning\n break\n }\n }\n\n // No multiline transformer handled this line successfully\n return [false, startLineIndex]\n}\n\nfunction $importBlocks(\n lineText: string,\n rootNode: ElementNode,\n elementTransformers: Array<ElementTransformer>,\n textFormatTransformersIndex: TextFormatTransformersIndex,\n textMatchTransformers: Array<TextMatchTransformer>,\n) {\n const textNode = $createTextNode(lineText)\n const elementNode = $createParagraphNode()\n elementNode.append(textNode)\n rootNode.append(elementNode)\n\n for (const { regExp, replace } of elementTransformers) {\n const match = lineText.match(regExp)\n\n if (match) {\n textNode.setTextContent(lineText.slice(match[0].length))\n if (replace(elementNode, [textNode], match, true) !== false) {\n break\n }\n }\n }\n\n importTextTransformers(textNode, textFormatTransformersIndex, textMatchTransformers)\n\n // If no transformer found and we left with original paragraph node\n // can check if its content can be appended to the previous node\n // if it's a paragraph, quote or list\n if (elementNode.isAttached() && lineText.length > 0) {\n const previousNode = elementNode.getPreviousSibling()\n if ($isParagraphNode(previousNode) || $isQuoteNode(previousNode) || $isListNode(previousNode)) {\n let targetNode: ListItemNode | null | typeof previousNode = previousNode\n\n if ($isListNode(previousNode)) {\n const lastDescendant = previousNode.getLastDescendant()\n if (lastDescendant == null) {\n targetNode = null\n } else {\n targetNode = $findMatchingParent(lastDescendant, $isListItemNode)\n }\n }\n\n if (targetNode != null && targetNode.getTextContentSize() > 0) {\n targetNode.splice(targetNode.getChildrenSize(), 0, [\n $createLineBreakNode(),\n ...elementNode.getChildren(),\n ])\n elementNode.remove()\n }\n }\n }\n}\n\nfunction createTextFormatTransformersIndex(\n textTransformers: Array<TextFormatTransformer>,\n): TextFormatTransformersIndex {\n const transformersByTag: Record<string, TextFormatTransformer> = {}\n const fullMatchRegExpByTag: Record<string, RegExp> = {}\n const openTagsRegExp: string[] = []\n const escapeRegExp = `(?<![\\\\\\\\])`\n\n for (const transformer of textTransformers) {\n const { tag } = transformer\n transformersByTag[tag] = transformer\n const tagRegExp = tag.replace(/([*^+])/g, '\\\\$1')\n openTagsRegExp.push(tagRegExp)\n\n // Single-char tag (e.g. \"*\"),\n if (tag.length === 1) {\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<![\\\\\\\\${tagRegExp}])(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^${tagRegExp}\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?![\\\\\\\\${tagRegExp}])`,\n )\n } else {\n // Multi‐char tags (e.g. \"**\")\n fullMatchRegExpByTag[tag] = new RegExp(\n `(?<!\\\\\\\\)(${tagRegExp})((\\\\\\\\${tagRegExp})?.*?[^\\\\s](\\\\\\\\${tagRegExp})?)((?<!\\\\\\\\)|(?<=\\\\\\\\\\\\\\\\))(${tagRegExp})(?!\\\\\\\\)`,\n )\n }\n }\n\n return {\n // Reg exp to find open tag + content + close tag\n fullMatchRegExpByTag,\n\n // Regexp to locate *any* potential opening tag (longest first).\n openTagsRegExp: new RegExp(`${escapeRegExp}(${openTagsRegExp.join('|')})`, 'g'),\n transformersByTag,\n }\n}\n"],"mappings":"AAAA;;;;;;GAWA,SAASA,eAAe,EAAEC,WAAW,QAAQ;AAC7C,SAASC,YAAY,QAAQ;AAC7B,SAASC,mBAAmB,QAAQ;AACpC,SACEC,oBAAoB,EACpBC,oBAAoB,EACpBC,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,gBAAgB,QACX;AAUP,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ;AAQrD;;;AAGA,OAAO,SAASC,qBACdC,YAAgC,EAChCC,sBAAA,GAAyB,KAAK;EAE9B,MAAMC,MAAA,GAASJ,kBAAA,CAAmBE,YAAA;EAClC,MAAMG,2BAAA,GAA8BC,iCAAA,CAAkCF,MAAA,CAAOG,UAAU;EAEvF,OAAO,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,YAAA,GAAe,aAAa;EAElC,KAAK,MAAMtC,WAAA,IAAekC,gBAAA,EAAkB;IAC1C,MAAM;MAAEK;IAAG,CAAE,GAAGvC,WAAA;IAChBmC,iBAAiB,CAACI,GAAA,CAAI,GAAGvC,WAAA;IACzB,MAAMwC,SAAA,GAAYD,GAAA,CAAInC,OAAO,CAAC,YAAY;IAC1CiC,cAAA,CAAerB,IAAI,CAACwB,SAAA;IAEpB;IACA,IAAID,GAAA,CAAI5D,MAAM,KAAK,GAAG;MACpByD,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,YAAYD,SAAA,MAAeA,SAAA,UAAmBA,SAAA,UAAmBA,SAAA,YAAqBA,SAAA,gCAAyCA,SAAA,YAAqBA,SAAA,IAAa;IAErK,OAAO;MACL;MACAJ,oBAAoB,CAACG,GAAA,CAAI,GAAG,IAAIE,MAAA,CAC9B,aAAaD,SAAA,UAAmBA,SAAA,mBAA4BA,SAAA,gCAAyCA,SAAA,WAAoB;IAE7H;EACF;EAEA,OAAO;IACL;IACAJ,oBAAA;IAEA;IACAC,cAAA,EAAgB,IAAII,MAAA,CAAO,GAAGH,YAAA,IAAgBD,cAAA,CAAeK,IAAI,CAAC,OAAO,EAAE;IAC3EP;EACF;AACF","ignoreList":[]}
@@ -1,11 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import type { LexicalEditor } from 'lexical';
9
- import type { Transformer } from './MarkdownTransformers.js';
10
- export declare function registerMarkdownShortcuts(editor: LexicalEditor, transformers?: Array<Transformer>): () => void;
11
- //# sourceMappingURL=MarkdownShortcuts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownShortcuts.d.ts","sourceRoot":"","sources":["../../../../src/packages/@lexical/markdown/MarkdownShortcuts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAe,aAAa,EAAY,MAAM,SAAS,CAAA;AAYnE,OAAO,KAAK,EAKV,WAAW,EACZ,MAAM,2BAA2B,CAAA;AA4TlC,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,aAAa,EACrB,YAAY,GAAE,KAAK,CAAC,WAAW,CAAgB,GAC9C,MAAM,IAAI,CA8FZ"}