@lexical/markdown 0.1.18 → 0.1.21
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/LexicalMarkdown.dev.js +223 -75
- package/LexicalMarkdown.prod.js +26 -23
- package/package.json +8 -8
package/LexicalMarkdown.dev.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var lexical = require('lexical');
|
|
10
9
|
var code = require('@lexical/code');
|
|
11
10
|
var list = require('@lexical/list');
|
|
11
|
+
var lexical = require('lexical');
|
|
12
12
|
var link = require('@lexical/link');
|
|
13
13
|
var richText = require('@lexical/rich-text');
|
|
14
14
|
var text = require('@lexical/text');
|
|
@@ -23,7 +23,7 @@ var text = require('@lexical/text');
|
|
|
23
23
|
*/
|
|
24
24
|
/*
|
|
25
25
|
How to add a new syntax to capture and transform.
|
|
26
|
-
1. Create a new enumeration by adding to
|
|
26
|
+
1. Create a new enumeration by adding to MarkdownFormatKind.
|
|
27
27
|
2. Add a new criteria with a regEx pattern. See markdownStrikethrough as an example.
|
|
28
28
|
3. Add your block criteria (e.g. '# ') to allMarkdownCriteria or
|
|
29
29
|
your text criteria (e.g. *MyItalic*) to allMarkdownCriteriaForTextNodes.
|
|
@@ -52,7 +52,7 @@ const triggers = [spaceTrigger
|
|
|
52
52
|
]; // Todo: speed up performance by having non-capture group variations of the regex.
|
|
53
53
|
|
|
54
54
|
const autoFormatBase = {
|
|
55
|
-
|
|
55
|
+
markdownFormatKind: null,
|
|
56
56
|
regEx: /(?:)/,
|
|
57
57
|
regExForAutoFormatting: /(?:)/,
|
|
58
58
|
requiresParagraphStart: false
|
|
@@ -61,89 +61,89 @@ const paragraphStartBase = { ...autoFormatBase,
|
|
|
61
61
|
requiresParagraphStart: true
|
|
62
62
|
};
|
|
63
63
|
const markdownHeader1 = { ...paragraphStartBase,
|
|
64
|
-
|
|
64
|
+
markdownFormatKind: 'paragraphH1',
|
|
65
65
|
regEx: /^(?:#)/,
|
|
66
66
|
regExForAutoFormatting: /^(?:# )/
|
|
67
67
|
};
|
|
68
68
|
const markdownHeader2 = { ...paragraphStartBase,
|
|
69
|
-
|
|
69
|
+
markdownFormatKind: 'paragraphH2',
|
|
70
70
|
regEx: /^(?:##)/,
|
|
71
71
|
regExForAutoFormatting: /^(?:## )/
|
|
72
72
|
};
|
|
73
73
|
const markdownHeader3 = { ...paragraphStartBase,
|
|
74
|
-
|
|
74
|
+
markdownFormatKind: 'paragraphH2',
|
|
75
75
|
regEx: /^(?:###)/,
|
|
76
76
|
regExForAutoFormatting: /^(?:### )/
|
|
77
77
|
};
|
|
78
78
|
const markdownBlockQuote = { ...paragraphStartBase,
|
|
79
|
-
|
|
79
|
+
markdownFormatKind: 'paragraphBlockQuote',
|
|
80
80
|
regEx: /^(?:>)/,
|
|
81
81
|
regExForAutoFormatting: /^(?:> )/
|
|
82
82
|
};
|
|
83
83
|
const markdownUnorderedListDash = { ...paragraphStartBase,
|
|
84
|
-
|
|
84
|
+
markdownFormatKind: 'paragraphUnorderedList',
|
|
85
85
|
regEx: /^(?:- )/,
|
|
86
86
|
regExForAutoFormatting: /^(?:- )/
|
|
87
87
|
};
|
|
88
88
|
const markdownUnorderedListAsterisk = { ...paragraphStartBase,
|
|
89
|
-
|
|
89
|
+
markdownFormatKind: 'paragraphUnorderedList',
|
|
90
90
|
regEx: /^(?:\* )/,
|
|
91
91
|
regExForAutoFormatting: /^(?:\* )/
|
|
92
92
|
};
|
|
93
93
|
const markdownCodeBlock = { ...paragraphStartBase,
|
|
94
|
-
|
|
94
|
+
markdownFormatKind: 'paragraphCodeBlock',
|
|
95
95
|
regEx: /^(```)$/,
|
|
96
96
|
regExForAutoFormatting: /^(```)([a-z]*)( )/
|
|
97
97
|
};
|
|
98
98
|
const markdownOrderedList = { ...paragraphStartBase,
|
|
99
|
-
|
|
99
|
+
markdownFormatKind: 'paragraphOrderedList',
|
|
100
100
|
regEx: /^(\d+)\.\s/,
|
|
101
101
|
regExForAutoFormatting: /^(\d+)\.\s/
|
|
102
102
|
};
|
|
103
103
|
const markdownHorizontalRule = { ...paragraphStartBase,
|
|
104
|
-
|
|
104
|
+
markdownFormatKind: 'horizontalRule',
|
|
105
105
|
regEx: /^(?:\*\*\*)$/,
|
|
106
106
|
regExForAutoFormatting: /^(?:\*\*\* )/
|
|
107
107
|
};
|
|
108
108
|
const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
|
|
109
|
-
|
|
109
|
+
markdownFormatKind: 'horizontalRule',
|
|
110
110
|
regEx: /^(?:---)$/,
|
|
111
111
|
regExForAutoFormatting: /^(?:--- )/
|
|
112
112
|
};
|
|
113
113
|
const markdownItalic = { ...autoFormatBase,
|
|
114
|
-
|
|
114
|
+
markdownFormatKind: 'italic',
|
|
115
115
|
regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*)/,
|
|
116
116
|
regExForAutoFormatting: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/
|
|
117
117
|
};
|
|
118
118
|
const markdownBold = { ...autoFormatBase,
|
|
119
|
-
|
|
119
|
+
markdownFormatKind: 'bold',
|
|
120
120
|
regEx: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)/,
|
|
121
121
|
regExForAutoFormatting: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/
|
|
122
122
|
};
|
|
123
123
|
const markdownBoldWithUnderlines = { ...autoFormatBase,
|
|
124
|
-
|
|
124
|
+
markdownFormatKind: 'bold',
|
|
125
125
|
regEx: /(__)(\s*)([^__]*)(\s*)(__)/,
|
|
126
126
|
regExForAutoFormatting: /(__)(\s*)([^__]*)(\s*)(__)(\s)$/
|
|
127
127
|
};
|
|
128
128
|
const markdownBoldItalic = { ...autoFormatBase,
|
|
129
|
-
|
|
129
|
+
markdownFormatKind: 'bold_italic',
|
|
130
130
|
regEx: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)/,
|
|
131
131
|
regExForAutoFormatting: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/
|
|
132
132
|
}; // Markdown does not support underline, but we can allow folks to use
|
|
133
133
|
// the HTML tags for underline.
|
|
134
134
|
|
|
135
135
|
const fakeMarkdownUnderline = { ...autoFormatBase,
|
|
136
|
-
|
|
136
|
+
markdownFormatKind: 'underline',
|
|
137
137
|
regEx: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>)/,
|
|
138
138
|
regExForAutoFormatting: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>)(\s)$/
|
|
139
139
|
};
|
|
140
140
|
const markdownStrikethrough = { ...autoFormatBase,
|
|
141
|
-
|
|
141
|
+
markdownFormatKind: 'strikethrough',
|
|
142
142
|
regEx: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~)/,
|
|
143
143
|
regExForAutoFormatting: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/
|
|
144
144
|
};
|
|
145
145
|
const markdownLink = { ...autoFormatBase,
|
|
146
|
-
|
|
146
|
+
markdownFormatKind: 'link',
|
|
147
147
|
regEx: /(\[)(.+)(\]\()([^ ]+)(?: \"(?:.+)\")?(\))/,
|
|
148
148
|
regExForAutoFormatting: /(\[)(.+)(\]\()([^ ]+)(?: \"(?:.+)\")?(\))(\s)$/
|
|
149
149
|
};
|
|
@@ -151,11 +151,13 @@ const allMarkdownCriteriaForTextNodes = [markdownBoldItalic, markdownItalic, mar
|
|
|
151
151
|
const allMarkdownCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allMarkdownCriteriaForTextNodes];
|
|
152
152
|
function getInitialScanningContext(editor, isAutoFormatting, textNodeWithOffset, triggerState) {
|
|
153
153
|
return {
|
|
154
|
+
currentElementNode: null,
|
|
154
155
|
editor,
|
|
155
156
|
isAutoFormatting,
|
|
157
|
+
isWithinCodeBlock: false,
|
|
156
158
|
joinedText: null,
|
|
157
159
|
markdownCriteria: {
|
|
158
|
-
|
|
160
|
+
markdownFormatKind: 'noTransformation',
|
|
159
161
|
regEx: /(?:)/,
|
|
160
162
|
// Empty reg ex.
|
|
161
163
|
regExForAutoFormatting: /(?:)/,
|
|
@@ -172,7 +174,7 @@ function getInitialScanningContext(editor, isAutoFormatting, textNodeWithOffset,
|
|
|
172
174
|
function resetScanningContext(scanningContext) {
|
|
173
175
|
scanningContext.joinedText = '';
|
|
174
176
|
scanningContext.markdownCriteria = {
|
|
175
|
-
|
|
177
|
+
markdownFormatKind: 'noTransformation',
|
|
176
178
|
regEx: /(?:)/,
|
|
177
179
|
// Empty reg ex.
|
|
178
180
|
regExForAutoFormatting: /(?:)/,
|
|
@@ -186,6 +188,13 @@ function resetScanningContext(scanningContext) {
|
|
|
186
188
|
scanningContext.textNodeWithOffset = null;
|
|
187
189
|
return scanningContext;
|
|
188
190
|
}
|
|
191
|
+
function getCodeBlockCriteria() {
|
|
192
|
+
return markdownCodeBlock;
|
|
193
|
+
}
|
|
194
|
+
function getPatternMatchResultsForCodeBlock(scanningContext, text) {
|
|
195
|
+
const markdownCriteria = getCodeBlockCriteria();
|
|
196
|
+
return getPatternMatchResultsWithRegEx(text, true, false, scanningContext.isAutoFormatting ? markdownCriteria.regExForAutoFormatting : markdownCriteria.regEx);
|
|
197
|
+
}
|
|
189
198
|
|
|
190
199
|
function getPatternMatchResultsWithRegEx(textToSearch, matchMustAppearAtStartOfString, matchMustAppearAtEndOfString, regEx) {
|
|
191
200
|
const patternMatchResults = {
|
|
@@ -233,7 +242,7 @@ function getPatternMatchResultsForParagraphs(markdownCriteria, scanningContext)
|
|
|
233
242
|
|
|
234
243
|
if (textNodeWithOffset.node.getPreviousSibling() === null) {
|
|
235
244
|
const textToSearch = textNodeWithOffset.node.getTextContent();
|
|
236
|
-
return getPatternMatchResultsWithRegEx(textToSearch, true, false, markdownCriteria.regExForAutoFormatting);
|
|
245
|
+
return getPatternMatchResultsWithRegEx(textToSearch, true, false, scanningContext.isAutoFormatting ? markdownCriteria.regExForAutoFormatting : markdownCriteria.regEx);
|
|
237
246
|
}
|
|
238
247
|
|
|
239
248
|
return null;
|
|
@@ -259,38 +268,51 @@ function getPatternMatchResultsForText(markdownCriteria, scanningContext) {
|
|
|
259
268
|
|
|
260
269
|
function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNode) {
|
|
261
270
|
let newNode = null;
|
|
271
|
+
const shouldDelete = false;
|
|
262
272
|
const children = element.getChildren();
|
|
263
273
|
const markdownCriteria = scanningContext.markdownCriteria;
|
|
264
274
|
const patternMatchResults = scanningContext.patternMatchResults;
|
|
265
275
|
|
|
266
|
-
if (markdownCriteria.
|
|
267
|
-
switch (markdownCriteria.
|
|
276
|
+
if (markdownCriteria.markdownFormatKind != null) {
|
|
277
|
+
switch (markdownCriteria.markdownFormatKind) {
|
|
268
278
|
case 'paragraphH1':
|
|
269
279
|
{
|
|
270
280
|
newNode = richText.$createHeadingNode('h1');
|
|
271
281
|
newNode.append(...children);
|
|
272
|
-
return
|
|
282
|
+
return {
|
|
283
|
+
newNode,
|
|
284
|
+
shouldDelete
|
|
285
|
+
};
|
|
273
286
|
}
|
|
274
287
|
|
|
275
288
|
case 'paragraphH2':
|
|
276
289
|
{
|
|
277
290
|
newNode = richText.$createHeadingNode('h2');
|
|
278
291
|
newNode.append(...children);
|
|
279
|
-
return
|
|
292
|
+
return {
|
|
293
|
+
newNode,
|
|
294
|
+
shouldDelete
|
|
295
|
+
};
|
|
280
296
|
}
|
|
281
297
|
|
|
282
298
|
case 'paragraphH3':
|
|
283
299
|
{
|
|
284
300
|
newNode = richText.$createHeadingNode('h3');
|
|
285
301
|
newNode.append(...children);
|
|
286
|
-
return
|
|
302
|
+
return {
|
|
303
|
+
newNode,
|
|
304
|
+
shouldDelete
|
|
305
|
+
};
|
|
287
306
|
}
|
|
288
307
|
|
|
289
308
|
case 'paragraphBlockQuote':
|
|
290
309
|
{
|
|
291
310
|
newNode = richText.$createQuoteNode();
|
|
292
311
|
newNode.append(...children);
|
|
293
|
-
return
|
|
312
|
+
return {
|
|
313
|
+
newNode,
|
|
314
|
+
shouldDelete
|
|
315
|
+
};
|
|
294
316
|
}
|
|
295
317
|
|
|
296
318
|
case 'paragraphUnorderedList':
|
|
@@ -299,7 +321,10 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
|
|
|
299
321
|
const listItem = list.$createListItemNode();
|
|
300
322
|
listItem.append(...children);
|
|
301
323
|
newNode.append(listItem);
|
|
302
|
-
return
|
|
324
|
+
return {
|
|
325
|
+
newNode,
|
|
326
|
+
shouldDelete
|
|
327
|
+
};
|
|
303
328
|
}
|
|
304
329
|
|
|
305
330
|
case 'paragraphOrderedList':
|
|
@@ -310,12 +335,55 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
|
|
|
310
335
|
const listItem = list.$createListItemNode();
|
|
311
336
|
listItem.append(...children);
|
|
312
337
|
newNode.append(listItem);
|
|
313
|
-
return
|
|
338
|
+
return {
|
|
339
|
+
newNode,
|
|
340
|
+
shouldDelete
|
|
341
|
+
};
|
|
314
342
|
}
|
|
315
343
|
|
|
316
344
|
case 'paragraphCodeBlock':
|
|
317
345
|
{
|
|
318
346
|
// Toggle code and paragraph nodes.
|
|
347
|
+
if (scanningContext.isAutoFormatting === false) {
|
|
348
|
+
const shouldToggle = scanningContext.patternMatchResults.regExCaptureGroups.length > 0;
|
|
349
|
+
|
|
350
|
+
if (shouldToggle) {
|
|
351
|
+
scanningContext.isWithinCodeBlock = scanningContext.isWithinCodeBlock !== true; // When toggling, always clear the code block element node.
|
|
352
|
+
|
|
353
|
+
scanningContext.currentElementNode = null;
|
|
354
|
+
return {
|
|
355
|
+
newNode: null,
|
|
356
|
+
shouldDelete: true
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (scanningContext.isWithinCodeBlock) {
|
|
361
|
+
// Create the code block and return it to the caller.
|
|
362
|
+
if (scanningContext.currentElementNode == null) {
|
|
363
|
+
const newCodeBlockNode = code.$createCodeNode();
|
|
364
|
+
newCodeBlockNode.append(...children);
|
|
365
|
+
scanningContext.currentElementNode = newCodeBlockNode;
|
|
366
|
+
return {
|
|
367
|
+
newNode: newCodeBlockNode,
|
|
368
|
+
shouldDelete: false
|
|
369
|
+
};
|
|
370
|
+
} // Build up the code block with a line break and the children.
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
if (scanningContext.currentElementNode != null) {
|
|
374
|
+
const codeBlockNode = scanningContext.currentElementNode;
|
|
375
|
+
const lineBreakNode = lexical.$createLineBreakNode();
|
|
376
|
+
codeBlockNode.append(lineBreakNode);
|
|
377
|
+
codeBlockNode.append(...children);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
newNode: null,
|
|
383
|
+
shouldDelete: true
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
319
387
|
if (scanningContext.triggerState != null && scanningContext.triggerState.isCodeBlock) {
|
|
320
388
|
newNode = lexical.$createParagraphNode();
|
|
321
389
|
} else {
|
|
@@ -328,53 +396,70 @@ function getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNod
|
|
|
328
396
|
}
|
|
329
397
|
|
|
330
398
|
newNode.append(...children);
|
|
331
|
-
return
|
|
399
|
+
return {
|
|
400
|
+
newNode,
|
|
401
|
+
shouldDelete
|
|
402
|
+
};
|
|
332
403
|
}
|
|
333
404
|
|
|
334
405
|
case 'horizontalRule':
|
|
335
406
|
{
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
407
|
+
if (createHorizontalRuleNode != null) {
|
|
408
|
+
// return null for newNode. Insert the HR here.
|
|
409
|
+
const horizontalRuleNode = createHorizontalRuleNode();
|
|
410
|
+
element.insertBefore(horizontalRuleNode);
|
|
411
|
+
}
|
|
412
|
+
|
|
339
413
|
break;
|
|
340
414
|
}
|
|
341
415
|
}
|
|
342
416
|
}
|
|
343
417
|
|
|
344
|
-
return
|
|
418
|
+
return {
|
|
419
|
+
newNode,
|
|
420
|
+
shouldDelete
|
|
421
|
+
};
|
|
345
422
|
}
|
|
346
423
|
|
|
347
424
|
function transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode) {
|
|
348
425
|
const textNodeWithOffset = getTextNodeWithOffsetOrThrow(scanningContext);
|
|
349
426
|
const element = textNodeWithOffset.node.getParentOrThrow();
|
|
350
|
-
const text = scanningContext.patternMatchResults.regExCaptureGroups[0].text; // Remove the text which we matched.
|
|
351
427
|
|
|
352
|
-
|
|
428
|
+
if (scanningContext.patternMatchResults.regExCaptureGroups.length > 0) {
|
|
429
|
+
const text = scanningContext.patternMatchResults.regExCaptureGroups[0].text; // Remove the text which we matched.
|
|
353
430
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
textNode.
|
|
431
|
+
const textNode = textNodeWithOffset.node.spliceText(0, text.length, '', true);
|
|
432
|
+
|
|
433
|
+
if (textNode.getTextContent() === '') {
|
|
434
|
+
textNode.selectPrevious();
|
|
435
|
+
textNode.remove();
|
|
436
|
+
}
|
|
357
437
|
} // Transform the current element kind to the new element kind.
|
|
358
438
|
|
|
359
439
|
|
|
360
|
-
const
|
|
440
|
+
const {
|
|
441
|
+
newNode,
|
|
442
|
+
shouldDelete
|
|
443
|
+
} = getNewNodeForCriteria(scanningContext, element, createHorizontalRuleNode);
|
|
361
444
|
|
|
362
|
-
if (
|
|
363
|
-
element.
|
|
445
|
+
if (shouldDelete) {
|
|
446
|
+
element.remove();
|
|
447
|
+
} else if (newNode !== null) {
|
|
448
|
+
element.replace(newNode);
|
|
364
449
|
}
|
|
365
450
|
}
|
|
366
451
|
function transformTextNodeForText(scanningContext) {
|
|
367
452
|
const markdownCriteria = scanningContext.markdownCriteria;
|
|
368
453
|
|
|
369
|
-
if (markdownCriteria.
|
|
370
|
-
const formatting = getTextFormatType(markdownCriteria.
|
|
454
|
+
if (markdownCriteria.markdownFormatKind != null) {
|
|
455
|
+
const formatting = getTextFormatType(markdownCriteria.markdownFormatKind);
|
|
371
456
|
|
|
372
457
|
if (formatting != null) {
|
|
373
458
|
transformTextNodeWithFormatting(formatting, scanningContext);
|
|
374
459
|
return;
|
|
375
460
|
}
|
|
376
461
|
|
|
377
|
-
if (markdownCriteria.
|
|
462
|
+
if (markdownCriteria.markdownFormatKind === 'link') {
|
|
378
463
|
transformTextNodeWithLink(scanningContext);
|
|
379
464
|
}
|
|
380
465
|
}
|
|
@@ -466,13 +551,13 @@ function getJoinedTextLength(patternMatchResults) {
|
|
|
466
551
|
return patternMatchResults.regExCaptureGroups[lastGroupIndex].offsetInParent + patternMatchResults.regExCaptureGroups[lastGroupIndex].text.length;
|
|
467
552
|
}
|
|
468
553
|
|
|
469
|
-
function getTextFormatType(
|
|
470
|
-
switch (
|
|
554
|
+
function getTextFormatType(markdownFormatKind) {
|
|
555
|
+
switch (markdownFormatKind) {
|
|
471
556
|
case 'italic':
|
|
472
557
|
case 'bold':
|
|
473
558
|
case 'underline':
|
|
474
559
|
case 'strikethrough':
|
|
475
|
-
return [
|
|
560
|
+
return [markdownFormatKind];
|
|
476
561
|
|
|
477
562
|
case 'bold_italic':
|
|
478
563
|
{
|
|
@@ -689,7 +774,7 @@ function getCriteriaWithPatternMatchResults(markdownCriteriaArray, scanningConte
|
|
|
689
774
|
for (let i = 0; i < count; i++) {
|
|
690
775
|
const markdownCriteria = markdownCriteriaArray[i]; // Skip code block nodes, unless the autoFormatKind calls for toggling the code block.
|
|
691
776
|
|
|
692
|
-
if (currentTriggerState != null && currentTriggerState.isCodeBlock === false || markdownCriteria.
|
|
777
|
+
if (currentTriggerState != null && currentTriggerState.isCodeBlock === false || markdownCriteria.markdownFormatKind === 'paragraphCodeBlock') {
|
|
693
778
|
const patternMatchResults = getPatternMatchResultsForCriteria(markdownCriteria, scanningContext);
|
|
694
779
|
|
|
695
780
|
if (patternMatchResults != null) {
|
|
@@ -776,7 +861,7 @@ function findScanningContext(editor, currentTriggerState, priorTriggerState) {
|
|
|
776
861
|
const currentTextContentLength = currentTriggerState.textContent.length;
|
|
777
862
|
const triggerOffset = currentTriggerState.anchorOffset - triggerStringLength;
|
|
778
863
|
|
|
779
|
-
if ((currentTriggerState.hasParentNode === true && currentTriggerState.isSimpleText && currentTriggerState.isSelectionCollapsed && currentTriggerState.
|
|
864
|
+
if ((currentTriggerState.hasParentNode === true && currentTriggerState.isSimpleText && currentTriggerState.isSelectionCollapsed && currentTriggerState.anchorOffset !== priorTriggerState.anchorOffset && triggerOffset >= 0 && triggerOffset + triggerStringLength <= currentTextContentLength && currentTriggerState.textContent.substr(triggerOffset, triggerStringLength) === triggerString && // Some code differentiation needed if trigger kind is not a simple space character.
|
|
780
865
|
currentTriggerState.textContent !== priorTriggerState.textContent) === false) {
|
|
781
866
|
return null;
|
|
782
867
|
}
|
|
@@ -794,17 +879,62 @@ function findScanningContext(editor, currentTriggerState, priorTriggerState) {
|
|
|
794
879
|
*
|
|
795
880
|
*/
|
|
796
881
|
function convertStringToLexical(text, editor) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
882
|
+
if (!text.length) {
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const nodes = [];
|
|
887
|
+
const splitLines = text.split('\n');
|
|
888
|
+
const splitLinesCount = splitLines.length;
|
|
889
|
+
|
|
890
|
+
for (let i = 0; i < splitLinesCount; i++) {
|
|
891
|
+
if (splitLines[i].length > 0) {
|
|
892
|
+
nodes.push(lexical.$createParagraphNode().append(lexical.$createTextNode(splitLines[i])));
|
|
893
|
+
} else {
|
|
894
|
+
nodes.push(lexical.$createParagraphNode());
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
if (nodes.length) {
|
|
899
|
+
const root = lexical.$getRoot();
|
|
900
|
+
root.clear();
|
|
901
|
+
root.append(...nodes);
|
|
902
|
+
return root;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
return null;
|
|
801
906
|
}
|
|
802
907
|
|
|
803
|
-
function convertElementNodeContainingMarkdown(scanningContext, elementNode) {
|
|
804
|
-
// Handle
|
|
805
|
-
|
|
806
|
-
if (lexical.$isParagraphNode(elementNode)) {
|
|
908
|
+
function convertElementNodeContainingMarkdown(scanningContext, elementNode, createHorizontalRuleNode) {
|
|
909
|
+
const textContent = elementNode.getTextContent(); // Handle paragraph nodes below.
|
|
910
|
+
|
|
911
|
+
if (lexical.$isParagraphNode(elementNode) && elementNode.getChildren().length) {
|
|
807
912
|
const paragraphNode = elementNode;
|
|
913
|
+
const firstChild = paragraphNode.getFirstChild();
|
|
914
|
+
const firstChildIsTextNode = lexical.$isTextNode(firstChild); // Handle conversion to code block.
|
|
915
|
+
|
|
916
|
+
if (scanningContext.isWithinCodeBlock === true) {
|
|
917
|
+
if (!(firstChild != null && firstChildIsTextNode)) {
|
|
918
|
+
throw Error(`Expect paragraph containing only text nodes.`);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
scanningContext.textNodeWithOffset = {
|
|
922
|
+
node: firstChild,
|
|
923
|
+
offset: 0
|
|
924
|
+
};
|
|
925
|
+
const patternMatchResults = getPatternMatchResultsForCodeBlock(scanningContext, textContent);
|
|
926
|
+
|
|
927
|
+
if (patternMatchResults != null) {
|
|
928
|
+
// Toggle transform to or from code block.
|
|
929
|
+
scanningContext.patternMatchResults = patternMatchResults;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
scanningContext.markdownCriteria = getCodeBlockCriteria(); // Perform text transformation here.
|
|
933
|
+
|
|
934
|
+
transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode);
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
|
|
808
938
|
const allCriteria = getAllMarkdownCriteria();
|
|
809
939
|
const count = allCriteria.length;
|
|
810
940
|
|
|
@@ -812,9 +942,7 @@ function convertElementNodeContainingMarkdown(scanningContext, elementNode) {
|
|
|
812
942
|
const criteria = allCriteria[i];
|
|
813
943
|
|
|
814
944
|
if (criteria.requiresParagraphStart === true) {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
if (!lexical.$isTextNode(firstChild)) {
|
|
945
|
+
if (!(firstChild != null && firstChildIsTextNode)) {
|
|
818
946
|
throw Error(`Expect paragraph containing only text nodes.`);
|
|
819
947
|
}
|
|
820
948
|
|
|
@@ -828,28 +956,47 @@ function convertElementNodeContainingMarkdown(scanningContext, elementNode) {
|
|
|
828
956
|
if (patternMatchResults != null) {
|
|
829
957
|
// Lazy fill-in the particular format criteria and any matching result information.
|
|
830
958
|
scanningContext.markdownCriteria = criteria;
|
|
831
|
-
scanningContext.patternMatchResults = patternMatchResults; //
|
|
959
|
+
scanningContext.patternMatchResults = patternMatchResults; // Perform text transformation here.
|
|
960
|
+
|
|
961
|
+
transformTextNodeForParagraphs(scanningContext, createHorizontalRuleNode);
|
|
962
|
+
return;
|
|
832
963
|
}
|
|
833
964
|
}
|
|
834
965
|
}
|
|
835
966
|
}
|
|
836
967
|
}
|
|
837
968
|
|
|
838
|
-
function convertMarkdownForElementNodes(
|
|
969
|
+
function convertMarkdownForElementNodes(editor, createHorizontalRuleNode) {
|
|
839
970
|
// Please see the declaration of ScanningContext for a detailed explanation.
|
|
840
971
|
const scanningContext = getInitialScanningContext(editor, false, null, null);
|
|
841
|
-
const
|
|
972
|
+
const root = lexical.$getRoot();
|
|
973
|
+
let done = false;
|
|
974
|
+
let startIndex = 0;
|
|
842
975
|
|
|
843
|
-
|
|
844
|
-
|
|
976
|
+
while (!done) {
|
|
977
|
+
done = true;
|
|
978
|
+
const elementNodes = root.getChildren();
|
|
979
|
+
const countOfElementNodes = elementNodes.length;
|
|
845
980
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
} // Reset the scanning information that relates to the particular element node.
|
|
981
|
+
for (let i = startIndex; i < countOfElementNodes; i++) {
|
|
982
|
+
const elementNode = elementNodes[i];
|
|
849
983
|
|
|
984
|
+
if (lexical.$isElementNode(elementNode)) {
|
|
985
|
+
convertElementNodeContainingMarkdown(scanningContext, elementNode, createHorizontalRuleNode);
|
|
986
|
+
} // Reset the scanning information that relates to the particular element node.
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
resetScanningContext(scanningContext);
|
|
990
|
+
|
|
991
|
+
if (root.getChildren().length !== countOfElementNodes) {
|
|
992
|
+
// The conversion added or removed an from root's children.
|
|
993
|
+
startIndex = i;
|
|
994
|
+
done = false;
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
} // while
|
|
850
999
|
|
|
851
|
-
resetScanningContext(scanningContext);
|
|
852
|
-
}
|
|
853
1000
|
}
|
|
854
1001
|
|
|
855
1002
|
/**
|
|
@@ -885,8 +1032,9 @@ function registerMarkdownShortcuts(editor, createHorizontalRuleNode) {
|
|
|
885
1032
|
});
|
|
886
1033
|
}
|
|
887
1034
|
function $convertFromMarkdownString(markdownString, editor, createHorizontalRuleNode) {
|
|
888
|
-
convertStringToLexical(markdownString)
|
|
889
|
-
|
|
1035
|
+
if (convertStringToLexical(markdownString) != null) {
|
|
1036
|
+
convertMarkdownForElementNodes(editor, createHorizontalRuleNode);
|
|
1037
|
+
}
|
|
890
1038
|
}
|
|
891
1039
|
|
|
892
1040
|
exports.$convertFromMarkdownString = $convertFromMarkdownString;
|
package/LexicalMarkdown.prod.js
CHANGED
|
@@ -4,26 +4,29 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
const
|
|
9
|
-
regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)/,regExForAutoFormatting:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...
|
|
10
|
-
{...
|
|
11
|
-
{...
|
|
12
|
-
regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/},...
|
|
13
|
-
function
|
|
14
|
-
function
|
|
15
|
-
b=
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
a
|
|
19
|
-
c.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
exports
|
|
29
|
-
|
|
7
|
+
var k=require("@lexical/code"),p=require("@lexical/list"),q=require("lexical"),t=require("@lexical/link"),u=require("@lexical/rich-text"),v=require("@lexical/text");function w(b){throw Error(`Minified Lexical error #${b}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
8
|
+
const y=[{triggerKind:"space_trigger",triggerString:" "}],z={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},A={...z,requiresParagraphStart:!0},B={...A,markdownFormatKind:"paragraphCodeBlock",regEx:/^(```)$/,regExForAutoFormatting:/^(```)([a-z]*)( )/},C=[{...z,markdownFormatKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)/,regExForAutoFormatting:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/},{...z,markdownFormatKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)/,
|
|
9
|
+
regExForAutoFormatting:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...z,markdownFormatKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)/,regExForAutoFormatting:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...z,markdownFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)/,regExForAutoFormatting:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...z,markdownFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},{...z,markdownFormatKind:"strikethrough",
|
|
10
|
+
regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)/,regExForAutoFormatting:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...z,markdownFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))/,regExForAutoFormatting:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],D=[{...A,markdownFormatKind:"paragraphH1",regEx:/^(?:#)/,regExForAutoFormatting:/^(?:# )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:##)/,regExForAutoFormatting:/^(?:## )/},{...A,markdownFormatKind:"paragraphH2",regEx:/^(?:###)/,regExForAutoFormatting:/^(?:### )/},
|
|
11
|
+
{...A,markdownFormatKind:"paragraphBlockQuote",regEx:/^(?:>)/,regExForAutoFormatting:/^(?:> )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(?:- )/,regExForAutoFormatting:/^(?:- )/},{...A,markdownFormatKind:"paragraphUnorderedList",regEx:/^(?:\* )/,regExForAutoFormatting:/^(?:\* )/},{...A,markdownFormatKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/,regExForAutoFormatting:/^(\d+)\.\s/},B,{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:\*\*\*)$/,regExForAutoFormatting:/^(?:\*\*\* )/},
|
|
12
|
+
{...A,markdownFormatKind:"horizontalRule",regEx:/^(?:---)$/,regExForAutoFormatting:/^(?:--- )/},...C];function E(b,e,d,c){return{currentElementNode:null,editor:b,isAutoFormatting:e,isWithinCodeBlock:!1,joinedText:null,markdownCriteria:{markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null},patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:d,triggerState:c}}
|
|
13
|
+
function F(b,e,d,c){const a={regExCaptureGroups:[]};c=b.match(c);if(null!==c&&0<c.length&&(!1===e||0===c.index)&&(!1===d||c.index+c[0].length===b.length)){b=c.length;e=c.index;for(d=0;d<b;d++){const f=c[d];a.regExCaptureGroups.push({offsetInParent:e,text:f});0<d&&(e+=f.length)}return a}return null}function I(b){b=b.textNodeWithOffset;null==b&&w(82);return b}
|
|
14
|
+
function J(b,e){var d=I(e);return null===d.node.getPreviousSibling()?(d=d.node.getTextContent(),F(d,!0,!1,e.isAutoFormatting?b.regExForAutoFormatting:b.regEx)):null}
|
|
15
|
+
function K(b,e){var d=I(b);const c=d.node.getParentOrThrow();0<b.patternMatchResults.regExCaptureGroups.length&&(d=d.node.spliceText(0,b.patternMatchResults.regExCaptureGroups[0].text.length,"",!0),""===d.getTextContent()&&(d.selectPrevious(),d.remove()));a:{var a=null;d=c.getChildren();const g=b.markdownCriteria,l=b.patternMatchResults;if(null!=g.markdownFormatKind)switch(g.markdownFormatKind){case "paragraphH1":a=u.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=u.$createHeadingNode("h2");
|
|
16
|
+
a.append(...d);break;case "paragraphH3":a=u.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=u.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=p.$createListNode("ul");b=p.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<l.regExCaptureGroups.length?l.regExCaptureGroups[l.regExCaptureGroups.length-1].text:"1",10);a=p.$createListNode("ol",a);b=p.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphCodeBlock":if(!1===
|
|
17
|
+
b.isAutoFormatting){if(0<b.patternMatchResults.regExCaptureGroups.length){b.isWithinCodeBlock=!0!==b.isWithinCodeBlock;b.currentElementNode=null;d={newNode:null,shouldDelete:!0};break a}if(b.isWithinCodeBlock){if(null==b.currentElementNode){a=k.$createCodeNode();a.append(...d);b.currentElementNode=a;d={newNode:a,shouldDelete:!1};break a}null!=b.currentElementNode&&(a=b.currentElementNode,b=q.$createLineBreakNode(),a.append(b),a.append(...d))}d={newNode:null,shouldDelete:!0};break a}null!=b.triggerState&&
|
|
18
|
+
b.triggerState.isCodeBlock?a=q.$createParagraphNode():(a=k.$createCodeNode(),b=3<=l.regExCaptureGroups.length?l.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":null!=e&&(d=e(),c.insertBefore(d))}d={newNode:a,shouldDelete:!1}}const {newNode:f,shouldDelete:h}=d;h?c.remove():null!==f&&c.replace(f)}
|
|
19
|
+
function L(b,e,d,c,a){var f=a.patternMatchResults;const h=f.regExCaptureGroups;var g=h.length;if(b>=g||e>=g)return null;a=I(a).node.getParentOrThrow();g=f.regExCaptureGroups.length;2>g?f=0:(--g,f=f.regExCaptureGroups[g].offsetInParent+f.regExCaptureGroups[g].text.length);b=h[b];e=h[e];c=c?e.offsetInParent+e.text.length:e.offsetInParent;d=v.$findNodeWithOffsetFromJoinedText(d?b.offsetInParent+b.text.length:b.offsetInParent,f,1,a);c=v.$findNodeWithOffsetFromJoinedText(c,f,1,a);if(null==d||null==c)return null;
|
|
20
|
+
a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset,"text");a.focus.set(c.node.getKey(),c.offset,"text");return a}function M(b,e,d){const c=d.patternMatchResults.regExCaptureGroups;d=L(b,e,!1,!0,d);if(null!=d&&(q.$setSelection(d),d=q.$getSelection(),null!=d&&q.$isRangeSelection(d)&&!1===d.isCollapsed())){d.removeText();d=0;const a=c.length;for(let f=b;f<a;f++){const h=c[f];f>b&&(h.offsetInParent-=d);f<=e&&(d+=h.text.length,h.text="")}}}
|
|
21
|
+
function P(b){var e=b.patternMatchResults.regExCaptureGroups.length;2>e||(--e,b=L(e,e,!0,!0,b),null!=b&&q.$setSelection(b))}
|
|
22
|
+
function Q(b,e,d){b.update(()=>{if(!0===e.markdownCriteria.requiresParagraphStart)K(e,d);else{var c=e.markdownCriteria;if(null!=c.markdownFormatKind){a:{var a=c.markdownFormatKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){if(c=a,7===e.patternMatchResults.regExCaptureGroups.length){M(5,5,e);M(1,1,e);a=e.patternMatchResults.regExCaptureGroups;3<a.length||w(65);if(0!==a[3].text.length&&(a=
|
|
23
|
+
L(3,3,!1,!0,e),null!=a&&(q.$setSelection(a),a=q.$getSelection(),q.$isRangeSelection(a))))for(var f=0;f<c.length;f++)a.formatText(c[f]);P(e)}}else if("link"===c.markdownFormatKind&&(c=e.patternMatchResults.regExCaptureGroups,7===c.length&&(f=c[2].text,c=c[4].text,0!==f.length&&0!==c.length))){M(1,5,e);a=e.patternMatchResults.regExCaptureGroups;if(!(1>=a.length)){f={offsetInParent:a[1].offsetInParent,text:f};var h=L(1,1,!1,!1,e);if(null!=h&&(q.$setSelection(h),h=q.$getSelection(),null!=h&&q.$isRangeSelection(h)&&
|
|
24
|
+
h.isCollapsed())){h.insertText(f.text);a.splice(1,0,f);f=f.text.length;h=a.length;for(let g=2;g<h;g++)a[g].offsetInParent+=f}}a=L(1,1,!1,!0,e);null!=a&&(q.$setSelection(a),e.editor.dispatchCommand(t.TOGGLE_LINK_COMMAND,c),P(e))}}}},{tag:"history-push"})}
|
|
25
|
+
function R(b,e){let d=null;b.getEditorState().read(()=>{var c=q.$getSelection();if(q.$isRangeSelection(c)){var a=c.anchor.getNode();c=q.$isTextNode(a)?{node:a,offset:c.anchor.offset}:null}else c=null;if(null!==c){c=E(b,!0,c,e);a:{a=!1===e.isParentAListItemNode?D:C;const g=c.triggerState,l=a.length;for(let n=0;n<l;n++){const r=a[n];if(null!=g&&!1===g.isCodeBlock||"paragraphCodeBlock"===r.markdownFormatKind){var f=r,h=c;if(!0===f.requiresParagraphStart)f=J(f,h);else{if(null==h.joinedText){const m=I(h).node.getParentOrThrow();
|
|
26
|
+
q.$isElementNode(m)?null==h.joinedText&&(h.joinedText=v.$joinTextNodesInElementNode(m,"\u0004",I(h))):w(52,m.__key)}f=F(h.joinedText,!1,!0,f.regExForAutoFormatting)}if(null!=f){a={markdownCriteria:r,patternMatchResults:f};break a}}}a={markdownCriteria:null,patternMatchResults:null}}null!==a.markdownCriteria&&null!==a.patternMatchResults&&(d=c,d.markdownCriteria=a.markdownCriteria,d.patternMatchResults=a.patternMatchResults)}});return d}
|
|
27
|
+
function S(b){let e=null;b.read(()=>{const d=q.$getSelection();if(q.$isRangeSelection(d)&&d.isCollapsed()){var c=d.anchor.getNode(),a=c.getParent(),f=p.$isListItemNode(a);e={anchorOffset:d.anchor.offset,hasParentNode:null!==a,isCodeBlock:k.$isCodeNode(c),isParentAListItemNode:f,isSelectionCollapsed:!0,isSimpleText:q.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return e}
|
|
28
|
+
exports.$convertFromMarkdownString=function(b,e,d){if(b.length){var c=[];b=b.split("\n");var a=b.length;for(var f=0;f<a;f++)0<b[f].length?c.push(q.$createParagraphNode().append(q.$createTextNode(b[f]))):c.push(q.$createParagraphNode());c.length?(b=q.$getRoot(),b.clear(),b.append(...c),c=b):c=null}else c=null;if(null!=c)for(e=E(e,!1,null,null),c=q.$getRoot(),b=!1,a=0;!b;){b=!0;f=c.getChildren();const r=f.length;for(let m=a;m<r;m++){var h=f[m];if(q.$isElementNode(h)){var g=e,l=h;h=d;var n=l.getTextContent();
|
|
29
|
+
if(q.$isParagraphNode(l)&&l.getChildren().length){const x=l.getFirstChild(),N=q.$isTextNode(x);if(!0===g.isWithinCodeBlock)null!=x&&N||w(80),g.textNodeWithOffset={node:x,offset:0},l=F(n,!0,!1,g.isAutoFormatting?B.regExForAutoFormatting:B.regEx),null!=l&&(g.patternMatchResults=l),g.markdownCriteria=B,K(g,h);else{n=D.length;for(let G=0;G<n;G++){const H=D[G];if(!0===H.requiresParagraphStart){null!=x&&N||w(80);g.textNodeWithOffset={node:x,offset:0};g.joinedText=l.getTextContent();const O=J(H,g);if(null!=
|
|
30
|
+
O){g.markdownCriteria=H;g.patternMatchResults=O;K(g,h);break}}}}}}g=e;g.joinedText="";g.markdownCriteria={markdownFormatKind:"noTransformation",regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:null};g.patternMatchResults={regExCaptureGroups:[]};g.triggerState=null;g.textNodeWithOffset=null;if(c.getChildren().length!==r){a=m;b=!1;break}}}};
|
|
31
|
+
exports.registerMarkdownShortcuts=function(b,e){let d=null;return b.registerUpdateListener(({tags:c})=>{if(!1===c.has("historic")){c=S(b.getEditorState());if(null==c)var a=null;else a:{a=c;var f=d;if(null==a||null==f)a=null;else{var h=y.length;for(let g=0;g<h;g++){const l=y[g].triggerString,n=l.length,r=a.textContent.length,m=a.anchorOffset-n;if(!1===(!0===a.hasParentNode&&a.isSimpleText&&a.isSelectionCollapsed&&a.anchorOffset!==f.anchorOffset&&0<=m&&m+n<=r&&a.textContent.substr(m,n)===l&&a.textContent!==
|
|
32
|
+
f.textContent)){a=null;break a}}a=R(b,a)}}null!=a&&Q(b,a,e);d=c}else d=null})};
|
package/package.json
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.21",
|
|
12
12
|
"main": "LexicalMarkdown.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.1.
|
|
14
|
+
"lexical": "0.1.21"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.1.
|
|
18
|
-
"@lexical/code": "0.1.
|
|
19
|
-
"@lexical/text": "0.1.
|
|
20
|
-
"@lexical/rich-text": "0.1.
|
|
21
|
-
"@lexical/list": "0.1.
|
|
22
|
-
"@lexical/link": "0.1.
|
|
17
|
+
"@lexical/utils": "0.1.21",
|
|
18
|
+
"@lexical/code": "0.1.21",
|
|
19
|
+
"@lexical/text": "0.1.21",
|
|
20
|
+
"@lexical/rich-text": "0.1.21",
|
|
21
|
+
"@lexical/list": "0.1.21",
|
|
22
|
+
"@lexical/link": "0.1.21"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|