@lexical/markdown 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalMarkdown.dev.js +80 -10
- package/LexicalMarkdown.prod.js +23 -22
- package/README.md +3 -3
- package/package.json +8 -8
package/LexicalMarkdown.dev.js
CHANGED
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
var lexical = require('lexical');
|
|
10
10
|
var code = require('@lexical/code');
|
|
11
|
-
var link = require('@lexical/link');
|
|
12
11
|
var list = require('@lexical/list');
|
|
13
12
|
var richText = require('@lexical/rich-text');
|
|
13
|
+
var utils = require('@lexical/utils');
|
|
14
|
+
var link = require('@lexical/link');
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -68,7 +69,7 @@ function createMarkdownExport(transformers) {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
return output.join('\n');
|
|
72
|
+
return output.join('\n\n');
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -199,6 +200,7 @@ function hasFormat(node, format) {
|
|
|
199
200
|
* LICENSE file in the root directory of this source tree.
|
|
200
201
|
*
|
|
201
202
|
*/
|
|
203
|
+
const MARKDOWN_EMPTY_LINE_REG_EXP = /^\s{0,3}$/;
|
|
202
204
|
const CODE_BLOCK_REG_EXP = /^```(\w{1,10})?\s?$/;
|
|
203
205
|
function createMarkdownImport(transformers) {
|
|
204
206
|
const byType = transformersByType(transformers);
|
|
@@ -223,6 +225,16 @@ function createMarkdownImport(transformers) {
|
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
importBlocks(lineText, root, byType.element, textFormatTransformersIndex, byType.textMatch);
|
|
228
|
+
} // Removing empty paragraphs as md does not really
|
|
229
|
+
// allow empty lines and uses them as dilimiter
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
const children = root.getChildren();
|
|
233
|
+
|
|
234
|
+
for (const child of children) {
|
|
235
|
+
if (lexical.$isParagraphNode(child) && MARKDOWN_EMPTY_LINE_REG_EXP.test(child.getTextContent())) {
|
|
236
|
+
child.remove();
|
|
237
|
+
}
|
|
226
238
|
}
|
|
227
239
|
|
|
228
240
|
root.selectEnd();
|
|
@@ -230,7 +242,8 @@ function createMarkdownImport(transformers) {
|
|
|
230
242
|
}
|
|
231
243
|
|
|
232
244
|
function importBlocks(lineText, rootNode, elementTransformers, textFormatTransformersIndex, textMatchTransformers) {
|
|
233
|
-
const
|
|
245
|
+
const lineTextTrimmed = lineText.trim();
|
|
246
|
+
const textNode = lexical.$createTextNode(lineTextTrimmed);
|
|
234
247
|
const elementNode = lexical.$createParagraphNode();
|
|
235
248
|
elementNode.append(textNode);
|
|
236
249
|
rootNode.append(elementNode);
|
|
@@ -248,7 +261,32 @@ function importBlocks(lineText, rootNode, elementTransformers, textFormatTransfo
|
|
|
248
261
|
}
|
|
249
262
|
}
|
|
250
263
|
|
|
251
|
-
importTextFormatTransformers(textNode, textFormatTransformersIndex, textMatchTransformers);
|
|
264
|
+
importTextFormatTransformers(textNode, textFormatTransformersIndex, textMatchTransformers); // If no transformer found and we left with original paragraph node
|
|
265
|
+
// can check if its content can be appended to the previous node
|
|
266
|
+
// if it's a paragraph, quote or list
|
|
267
|
+
|
|
268
|
+
if (elementNode.isAttached() && lineTextTrimmed.length > 0) {
|
|
269
|
+
const previousNode = elementNode.getPreviousSibling();
|
|
270
|
+
|
|
271
|
+
if (lexical.$isParagraphNode(previousNode) || richText.$isQuoteNode(previousNode) || list.$isListNode(previousNode)) {
|
|
272
|
+
let targetNode = previousNode;
|
|
273
|
+
|
|
274
|
+
if (list.$isListNode(previousNode)) {
|
|
275
|
+
const lastDescendant = previousNode.getLastDescendant();
|
|
276
|
+
|
|
277
|
+
if (lastDescendant == null) {
|
|
278
|
+
targetNode = null;
|
|
279
|
+
} else {
|
|
280
|
+
targetNode = utils.$findMatchingParent(lastDescendant, list.$isListItemNode);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (targetNode != null && targetNode.getTextContentSize() > 0) {
|
|
285
|
+
targetNode.splice(targetNode.getChildrenSize(), 0, [lexical.$createLineBreakNode(), ...elementNode.getChildren()]);
|
|
286
|
+
elementNode.remove();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
252
290
|
}
|
|
253
291
|
|
|
254
292
|
function importCodeBlock(lines, startLineIndex, rootNode) {
|
|
@@ -299,7 +337,7 @@ function importTextFormatTransformers(textNode, textFormatTransformersIndex, tex
|
|
|
299
337
|
if (match[0] === textContent) {
|
|
300
338
|
currentNode = textNode;
|
|
301
339
|
} else {
|
|
302
|
-
const startIndex = match.index;
|
|
340
|
+
const startIndex = match.index || 0;
|
|
303
341
|
const endIndex = startIndex + match[0].length;
|
|
304
342
|
|
|
305
343
|
if (startIndex === 0) {
|
|
@@ -342,7 +380,7 @@ function importTextMatchTransformers(textNode_, textMatchTransformers) {
|
|
|
342
380
|
continue;
|
|
343
381
|
}
|
|
344
382
|
|
|
345
|
-
const startIndex = match.index;
|
|
383
|
+
const startIndex = match.index || 0;
|
|
346
384
|
const endIndex = startIndex + match[0].length;
|
|
347
385
|
let replaceNode;
|
|
348
386
|
|
|
@@ -389,7 +427,7 @@ function findOutermostMatch(textContent, textTransformersIndex) {
|
|
|
389
427
|
|
|
390
428
|
|
|
391
429
|
const {
|
|
392
|
-
index
|
|
430
|
+
index = 0
|
|
393
431
|
} = fullMatch;
|
|
394
432
|
const beforeChar = textContent[index - 1];
|
|
395
433
|
const afterChar = textContent[index + fullMatch[0].length];
|
|
@@ -494,7 +532,7 @@ function runTextMatchTransformers(anchorNode, anchorOffset, transformersByTrigge
|
|
|
494
532
|
continue;
|
|
495
533
|
}
|
|
496
534
|
|
|
497
|
-
const startIndex = match.index;
|
|
535
|
+
const startIndex = match.index || 0;
|
|
498
536
|
const endIndex = startIndex + match[0].length;
|
|
499
537
|
let replaceNode;
|
|
500
538
|
|
|
@@ -598,6 +636,7 @@ function runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransform
|
|
|
598
636
|
closeNode.setTextContent(closeNodeText);
|
|
599
637
|
const openNodeText = openNode === closeNode ? closeNodeText : prevOpenNodeText;
|
|
600
638
|
openNode.setTextContent(openNodeText.slice(0, openTagStartIndex) + openNodeText.slice(openTagStartIndex + tagLength));
|
|
639
|
+
const selection = lexical.$getSelection();
|
|
601
640
|
const nextSelection = lexical.$createRangeSelection();
|
|
602
641
|
lexical.$setSelection(nextSelection); // Adjust offset based on deleted chars
|
|
603
642
|
|
|
@@ -620,6 +659,10 @@ function runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransform
|
|
|
620
659
|
}
|
|
621
660
|
}
|
|
622
661
|
|
|
662
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
663
|
+
nextSelection.format = selection.format;
|
|
664
|
+
}
|
|
665
|
+
|
|
623
666
|
return true;
|
|
624
667
|
}
|
|
625
668
|
|
|
@@ -806,10 +849,37 @@ const HEADING = {
|
|
|
806
849
|
};
|
|
807
850
|
const QUOTE = {
|
|
808
851
|
export: (node, exportChildren) => {
|
|
809
|
-
|
|
852
|
+
if (!richText.$isQuoteNode(node)) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
const lines = exportChildren(node).split('\n');
|
|
857
|
+
const output = [];
|
|
858
|
+
|
|
859
|
+
for (const line of lines) {
|
|
860
|
+
output.push('> ' + line);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
return output.join('\n');
|
|
810
864
|
},
|
|
811
865
|
regExp: /^>\s/,
|
|
812
|
-
replace:
|
|
866
|
+
replace: (parentNode, children, _match, isImport) => {
|
|
867
|
+
if (isImport) {
|
|
868
|
+
const previousNode = parentNode.getPreviousSibling();
|
|
869
|
+
|
|
870
|
+
if (richText.$isQuoteNode(previousNode)) {
|
|
871
|
+
previousNode.splice(previousNode.getChildrenSize(), 0, [lexical.$createLineBreakNode(), ...children]);
|
|
872
|
+
previousNode.select(0, 0);
|
|
873
|
+
parentNode.remove();
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const node = richText.$createQuoteNode();
|
|
879
|
+
node.append(...children);
|
|
880
|
+
parentNode.replace(node);
|
|
881
|
+
node.select(0, 0);
|
|
882
|
+
},
|
|
813
883
|
type: 'element'
|
|
814
884
|
};
|
|
815
885
|
const CODE = {
|
package/LexicalMarkdown.prod.js
CHANGED
|
@@ -4,25 +4,26 @@
|
|
|
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
|
-
'use strict';var
|
|
8
|
-
function
|
|
9
|
-
function K(a,b,c){let d=[];a=a.getChildren();a:for(let e of a)if(
|
|
10
|
-
function L(a,b,c){let d=b.trim(),e=d,f=new Set;for(let
|
|
11
|
-
function N(a,b){let c=b?a.getPreviousSibling():a.getNextSibling();c||(a=a.getParentOrThrow(),a.isInline()&&(c=b?a.getPreviousSibling():a.getNextSibling()));for(;c;){if(
|
|
12
|
-
function
|
|
13
|
-
for(let {regExp:
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
let
|
|
18
|
-
(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
exports.
|
|
25
|
-
|
|
26
|
-
null!==
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
'use strict';var k=require("lexical"),y=require("@lexical/code"),E=require("@lexical/list"),F=require("@lexical/rich-text"),aa=require("@lexical/utils"),G=require("@lexical/link");function H(a,b){let c={};for(let d of a)a=b(d),c[a]?c[a].push(d):c[a]=[d];return c}function I(a){a=H(a,b=>b.type);return{element:a.element,textFormat:a["text-format"],textMatch:a["text-match"]}}let J=/[!-/:-@[-`{-~\s]/;
|
|
8
|
+
function ba(a){let b=I(a),c=b.textFormat.filter(d=>1===d.format.length);return()=>{let d=[];var e=k.$getRoot().getChildren();for(let f of e)e=ca(f,b.element,c,b.textMatch),null!=e&&d.push(e);return d.join("\n\n")}}function ca(a,b,c,d){for(let e of b)if(b=e.export(a,f=>K(f,c,d)),null!=b)return b;return k.$isElementNode(a)?K(a,c,d):null}
|
|
9
|
+
function K(a,b,c){let d=[];a=a.getChildren();a:for(let e of a)if(k.$isLineBreakNode(e))d.push("\n");else if(k.$isTextNode(e))d.push(L(e,e.getTextContent(),b));else{for(let f of c)if(a=f.export(e,h=>K(h,b,c),(h,p)=>L(h,p,b)),null!=a){d.push(a);continue a}k.$isElementNode(e)&&d.push(K(e,b,c))}return d.join("")}
|
|
10
|
+
function L(a,b,c){let d=b.trim(),e=d,f=new Set;for(let p of c){c=p.format[0];let r=p.tag;if(M(a,c)&&!f.has(c)){f.add(c);var h=N(a,!0);M(h,c)||(e=r+e);h=N(a,!1);M(h,c)||(e+=r)}}return b.replace(d,e)}
|
|
11
|
+
function N(a,b){let c=b?a.getPreviousSibling():a.getNextSibling();c||(a=a.getParentOrThrow(),a.isInline()&&(c=b?a.getPreviousSibling():a.getNextSibling()));for(;c;){if(k.$isElementNode(c)){if(!c.isInline())break;a=b?c.getLastDescendant():c.getFirstDescendant();if(k.$isTextNode(a))return a;c=b?c.getPreviousSibling():c.getNextSibling()}if(k.$isTextNode(c))return c;if(!k.$isElementNode(c))break}return null}function M(a,b){return k.$isTextNode(a)&&a.hasFormat(b)}let da=/^\s{0,3}$/,O=/^```(\w{1,10})?\s?$/;
|
|
12
|
+
function ea(a){let b=I(a),c=fa(b.textFormat);return d=>{var e=d.split("\n");let f=e.length;d=k.$getRoot();d.clear();for(let g=0;g<f;g++){var h=e[g];a:{var p=e,r=g;var l=d;var x=p[r].match(O);if(x)for(var q=r,m=p.length;++q<m;)if(p[q].match(O)){x=y.$createCodeNode(x[1]);p=k.$createTextNode(p.slice(r+1,q).join("\n"));x.append(p);l.append(x);l=[x,q];break a}l=[null,r]}let [n,u]=l;if(null!=n)g=u;else{l=h;m=d;var v=b.element;q=c;p=b.textMatch;r=l.trim();x=k.$createTextNode(r);h=k.$createParagraphNode();
|
|
13
|
+
h.append(x);m.append(h);for(let {regExp:w,replace:t}of v)if(m=l.match(w)){x.setTextContent(l.slice(m[0].length));t(h,[x],m,!0);break}P(x,q,p);h.isAttached()&&0<r.length&&(l=h.getPreviousSibling(),k.$isParagraphNode(l)||F.$isQuoteNode(l)||E.$isListNode(l))&&(q=l,E.$isListNode(l)&&(l=l.getLastDescendant(),q=null==l?null:aa.$findMatchingParent(l,E.$isListItemNode)),null!=q&&0<q.getTextContentSize()&&(q.splice(q.getChildrenSize(),0,[k.$createLineBreakNode(),...h.getChildren()]),h.remove()))}}e=d.getChildren();
|
|
14
|
+
for(let g of e)k.$isParagraphNode(g)&&da.test(g.getTextContent())&&g.remove();d.selectEnd()}}
|
|
15
|
+
function P(a,b,c){let d=a.getTextContent(),e=ha(d,b);if(e){if(e[0]===d)var f=a;else{var h=e.index||0,p=h+e[0].length;0===h?[f,l]=a.splitText(p):[,f,l]=a.splitText(h,p)}f.setTextContent(e[2]);if(h=b.transformersByTag[e[1]])for(var r of h.format)f.hasFormat(r)||f.toggleFormat(r);f.hasFormat("code")||P(f,b,c);l&&P(l,b,c)}else a:for(b=a;b;){for(h of c)if(f=b.getTextContent().match(h.importRegExp)){var l=f.index||0;r=l+f[0].length;0===l?[p,b]=b.splitText(r):[,p,b]=b.splitText(l,r);h.replace(p,f);continue a}break}}
|
|
16
|
+
function ha(a,b){var c=a.match(b.openTagsRegExp);if(null==c)return null;for(let f of c){var d=f.replace(/^\s/,"");c=b.fullMatchRegExpByTag[d];if(null!=c&&(c=a.match(c),d=b.transformersByTag[d],null!=c&&null!=d)){if(!1!==d.intraword)return c;var {index:e=0}=c;d=a[e-1];e=a[e+c[0].length];if(!(d&&!J.test(d)||e&&!J.test(e)))return c}}return null}
|
|
17
|
+
function fa(a){let b={},c={},d=[];for(let e of a){({tag:a}=e);b[a]=e;let f=a.replace(/(\*|\^)/g,"\\$1");d.push(f);c[a]=new RegExp(`(${f})(?![${f}\\s])(.*?[^${f}\\s])${f}(?!${f})`)}return{fullMatchRegExpByTag:c,openTagsRegExp:new RegExp("("+d.join("|")+")","g"),transformersByTag:b}}function Q(a,b,c){let d=c.length;for(;b>=d;b--){let e=b-d;if(R(a,e,c,0,d)&&" "!==a[e+d])return e}return-1}function R(a,b,c,d,e){for(let f=0;f<e;f++)if(a[b+f]!==c[d+f])return!1;return!0}
|
|
18
|
+
let S=a=>(b,c,d)=>{d=a(d);d.append(...c);b.replace(d);d.select(0,0)},T=a=>(b,c,d)=>{var e=b.getPreviousSibling();const f=E.$createListItemNode("check"===a?"x"===d[3]:void 0);E.$isListNode(e)&&e.getListType()===a?(e.append(f),b.remove()):(e=E.$createListNode(a,"number"===a?Number(d[2]):void 0),e.append(f),b.replace(e));f.append(...c);f.select(0,0);(b=Math.floor(d[1].length/4))&&f.setIndent(b)},U=(a,b,c)=>{const d=[];var e=a.getChildren();let f=0;for(const p of e)if(E.$isListItemNode(p)){if(1===p.getChildrenSize()&&
|
|
19
|
+
(e=p.getFirstChild(),E.$isListNode(e))){d.push(U(e,b,c+1));continue}e=" ".repeat(4*c);var h=a.getListType();h="number"===h?`${a.getStart()+f}. `:"check"===h?`- [${p.getChecked()?"x":" "}] `:"- ";d.push(e+h+b(p));f++}return d.join("\n")},V={export:(a,b)=>{if(!F.$isHeadingNode(a))return null;const c=Number(a.getTag().slice(1));return"#".repeat(c)+" "+b(a)},regExp:/^(#{1,6})\s/,replace:S(a=>F.$createHeadingNode("h"+a[1].length)),type:"element"},W={export:(a,b)=>{if(!F.$isQuoteNode(a))return null;a=b(a).split("\n");
|
|
20
|
+
b=[];for(const c of a)b.push("> "+c);return b.join("\n")},regExp:/^>\s/,replace:(a,b,c,d)=>{if(d&&(c=a.getPreviousSibling(),F.$isQuoteNode(c))){c.splice(c.getChildrenSize(),0,[k.$createLineBreakNode(),...b]);c.select(0,0);a.remove();return}c=F.$createQuoteNode();c.append(...b);a.replace(c);c.select(0,0)},type:"element"},X={export:a=>{if(!y.$isCodeNode(a))return null;const b=a.getTextContent();return"```"+(a.getLanguage()||"")+(b?"\n"+b:"")+"\n```"},regExp:/^```(\w{1,10})?\s/,replace:S(a=>y.$createCodeNode(a?
|
|
21
|
+
a[1]:void 0)),type:"element"},Y={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)[-*+]\s/,replace:T("bullet"),type:"element"},ia={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:T("check"),type:"element"},ja={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:T("number"),type:"element"},ka={format:["code"],tag:"`",type:"text-format"},la={format:["bold","italic"],tag:"***",type:"text-format"},ma={format:["bold",
|
|
22
|
+
"italic"],intraword:!1,tag:"___",type:"text-format"},na={format:["bold"],tag:"**",type:"text-format"},pa={format:["bold"],intraword:!1,tag:"__",type:"text-format"},qa={format:["strikethrough"],tag:"~~",type:"text-format"},ra={format:["italic"],tag:"*",type:"text-format"},sa={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ta={export:(a,b,c)=>{if(!G.$isLinkNode(a))return null;b=`[${a.getTextContent()}](${a.getURL()})`;const d=a.getFirstChild();return 1===a.getChildrenSize()&&k.$isTextNode(d)?
|
|
23
|
+
c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))$/,replace:(a,b)=>{const [,c,d]=b;b=G.$createLinkNode(d);const e=k.$createTextNode(c);e.setFormat(a.getFormat());b.append(e);a.replace(b)},trigger:")",type:"text-match"},ua=[V,W,X,Y,ja],va=[ka,la,ma,na,pa,ra,sa,qa],wa=[ta],Z=[...ua,...va,...wa];exports.$convertFromMarkdownString=function(a,b=Z){return ea(b)(a)};exports.$convertToMarkdownString=function(a=Z){return ba(a)()};exports.BOLD_ITALIC_STAR=la;
|
|
24
|
+
exports.BOLD_ITALIC_UNDERSCORE=ma;exports.BOLD_STAR=na;exports.BOLD_UNDERSCORE=pa;exports.CHECK_LIST=ia;exports.CODE=X;exports.ELEMENT_TRANSFORMERS=ua;exports.HEADING=V;exports.INLINE_CODE=ka;exports.ITALIC_STAR=ra;exports.ITALIC_UNDERSCORE=sa;exports.LINK=ta;exports.ORDERED_LIST=ja;exports.QUOTE=W;exports.STRIKETHROUGH=qa;exports.TEXT_FORMAT_TRANSFORMERS=va;exports.TEXT_MATCH_TRANSFORMERS=wa;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=Y;
|
|
25
|
+
exports.registerMarkdownShortcuts=function(a,b=Z){let c=I(b),d=H(c.textFormat,({tag:f})=>f[f.length-1]),e=H(c.textMatch,({trigger:f})=>f);return a.registerUpdateListener(({tags:f,dirtyLeaves:h,editorState:p,prevEditorState:r})=>{if(!f.has("historic")){var l=p.read(k.$getSelection);f=r.read(k.$getSelection);if(k.$isRangeSelection(f)&&k.$isRangeSelection(l)&&l.isCollapsed()){r=l.anchor.key;var x=l.anchor.offset,q=p._nodeMap.get(r);k.$isTextNode(q)&&h.has(r)&&(1===x||x===f.anchor.offset+1)&&a.update(()=>
|
|
26
|
+
{if(!q.hasFormat("code")){var m=q.getParent();if(null!==m&&!y.$isCodeNode(m)){var v=l.anchor.offset;b:{var g=c.element,n=m.getParent();if(k.$isRootNode(n)&&m.getFirstChild()===q&&(n=q.getTextContent()," "===n[v-1]))for(let {regExp:B,replace:C}of g)if((g=n.match(B))&&g[0].length===v){n=q.getNextSiblings();let [D,oa]=q.splitText(v);D.remove();n=oa?[oa,...n]:n;C(m,n,g,!1);m=!0;break b}m=!1}if(!m){b:{g=q.getTextContent();m=e[g[v-1]];if(null!=m){v<g.length&&(g=g.slice(0,v));for(w of m)if(m=g.match(w.regExp),
|
|
27
|
+
null!==m){g=m.index||0;n=g+m[0].length;var u=void 0;0===g?[u]=q.splitText(n):[,u]=q.splitText(g,n);u.selectNext();w.replace(u,m);var w=!0;break b}}w=!1}if(!w)b:{n=q.getTextContent();--v;var t=n[v];if(w=d[t])for(let B of w){var {tag:A}=B;w=A.length;let C=v-w+1;if(!(1<w&&!R(n,C,A,0,w)||" "===n[C-1])&&(u=n[v+1],!1!==B.intraword||!u||J.test(u))){m=u=q;g=Q(n,C,A);for(var z=m;0>g&&(z=z.getPreviousSibling())&&!k.$isLineBreakNode(z);)k.$isTextNode(z)&&(g=z.getTextContent(),m=z,g=Q(g,g.length,A));if(!(0>g||
|
|
28
|
+
m===u&&g+w===C||(A=m.getTextContent(),0<g&&A[g-1]===t||(z=A[g-1],!1===B.intraword&&z&&!J.test(z))))){n=u.getTextContent();n=n.slice(0,C)+n.slice(v+1);u.setTextContent(n);n=m===u?n:A;m.setTextContent(n.slice(0,g)+n.slice(g+w));n=k.$getSelection();t=k.$createRangeSelection();k.$setSelection(t);v=v-w*(m===u?2:1)+1;t.anchor.set(m.__key,g,"text");t.focus.set(u.__key,v,"text");for(let D of B.format)t.hasFormat(D)||t.formatText(D);t.anchor.set(t.focus.key,t.focus.offset,t.focus.type);for(let D of B.format)t.hasFormat(D)&&
|
|
29
|
+
t.toggleFormat(D);k.$isRangeSelection(n)&&(t.format=n.format);break b}}}}}}}})}}})}
|
package/README.md
CHANGED
|
@@ -22,9 +22,9 @@ editor.update(() => {
|
|
|
22
22
|
|
|
23
23
|
It can also be used for initializing editor's state from markdown string. Here's an example with react `<RichTextPlugin>`
|
|
24
24
|
```jsx
|
|
25
|
-
<LexicalComposer
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
<LexicalComposer initialConfig={{
|
|
26
|
+
editorState: () => $convertFromMarkdownString(markdown, TRANSFORMERS)
|
|
27
|
+
}}>
|
|
28
28
|
<RichTextPlugin />
|
|
29
29
|
</LexicalComposer>
|
|
30
30
|
```
|
package/package.json
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.6",
|
|
12
12
|
"main": "LexicalMarkdown.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.3.
|
|
14
|
+
"lexical": "0.3.6"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.3.
|
|
18
|
-
"@lexical/code": "0.3.
|
|
19
|
-
"@lexical/text": "0.3.
|
|
20
|
-
"@lexical/rich-text": "0.3.
|
|
21
|
-
"@lexical/list": "0.3.
|
|
22
|
-
"@lexical/link": "0.3.
|
|
17
|
+
"@lexical/utils": "0.3.6",
|
|
18
|
+
"@lexical/code": "0.3.6",
|
|
19
|
+
"@lexical/text": "0.3.6",
|
|
20
|
+
"@lexical/rich-text": "0.3.6",
|
|
21
|
+
"@lexical/list": "0.3.6",
|
|
22
|
+
"@lexical/link": "0.3.6"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|