@lexical/markdown
Advanced tools
Comparing version 0.2.9 to 0.3.0
@@ -40,2 +40,3 @@ /** | ||
tag: string; | ||
intraword?: boolean; | ||
type: 'text-format'; | ||
@@ -42,0 +43,0 @@ }; |
@@ -21,3 +21,3 @@ /** | ||
* | ||
* | ||
* | ||
*/ | ||
@@ -42,10 +42,8 @@ function indexBy(list, callback) { | ||
return { | ||
// $FlowFixMe | ||
element: byType.element, | ||
// $FlowFixMe | ||
textFormat: byType['text-format'], | ||
// $FlowFixMe | ||
textMatch: byType['text-match'] | ||
}; | ||
} | ||
const PUNCTUATION_OR_SPACE = /[!-/:-@[-`{-~\s]/; | ||
@@ -58,3 +56,3 @@ /** | ||
* | ||
* | ||
* | ||
*/ | ||
@@ -123,3 +121,8 @@ function createMarkdownExport(transformers) { | ||
function exportTextFormat(node, textContent, textTransformers) { | ||
let output = textContent; | ||
// This function handles the case of a string looking like this: " foo " | ||
// Where it would be invalid markdown to generate: "** foo **" | ||
// We instead want to trim the whitespace out, apply formatting, and then | ||
// bring the whitespace back. So our returned string looks like this: " **foo** " | ||
const frozenString = textContent.trim(); | ||
let output = frozenString; | ||
const applied = new Set(); | ||
@@ -148,5 +151,6 @@ | ||
} | ||
} | ||
} // Replace trimmed version of textContent ensuring surrounding whitespace is not modified | ||
return output; | ||
return textContent.replace(frozenString, output); | ||
} // Get next or previous text sibling a text node, including cases | ||
@@ -204,3 +208,3 @@ // when it's a child of inline element (e.g. link) | ||
* | ||
* | ||
* | ||
*/ | ||
@@ -379,3 +383,4 @@ const CODE_BLOCK_REG_EXP = /^```(\w{1,10})?\s?$/; | ||
// before using match to find transformer | ||
const fullMatchRegExp = textTransformersIndex.fullMatchRegExpByTag[match.replace(/^\s/, '')]; | ||
const tag = match.replace(/^\s/, ''); | ||
const fullMatchRegExp = textTransformersIndex.fullMatchRegExpByTag[tag]; | ||
@@ -387,5 +392,20 @@ if (fullMatchRegExp == null) { | ||
const fullMatch = textContent.match(fullMatchRegExp); | ||
const transformer = textTransformersIndex.transformersByTag[tag]; | ||
if (fullMatch != null) { | ||
return fullMatch; | ||
if (fullMatch != null && transformer != null) { | ||
if (transformer.intraword !== false) { | ||
return fullMatch; | ||
} // For non-intraword transformers checking if it's within a word | ||
// or surrounded with space/punctuation/newline | ||
const { | ||
index | ||
} = fullMatch; | ||
const beforeChar = textContent[index - 1]; | ||
const afterChar = textContent[index + fullMatch[0].length]; | ||
if ((!beforeChar || PUNCTUATION_OR_SPACE.test(beforeChar)) && (!afterChar || PUNCTUATION_OR_SPACE.test(afterChar))) { | ||
return fullMatch; | ||
} | ||
} | ||
@@ -427,5 +447,4 @@ } | ||
* | ||
* | ||
* | ||
*/ | ||
const PUNCTUATION_OR_SPACE = /[!-/:-@[-`{-~\s]/; | ||
@@ -509,3 +528,3 @@ function runElementTransformers(parentNode, anchorNode, anchorOffset, elementTransformers) { | ||
function runTextFormatTransformers(editor, anchorNode, anchorOffset, textFormatTransformers) { | ||
function runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformers) { | ||
const textContent = anchorNode.getTextContent(); | ||
@@ -667,3 +686,3 @@ const closeTagEndIndex = anchorOffset - 1; | ||
runTextFormatTransformers(editor, anchorNode, anchorOffset, textFormatTransformersIndex); | ||
runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformersIndex); | ||
}; | ||
@@ -721,3 +740,3 @@ | ||
* | ||
* | ||
*/ | ||
@@ -800,3 +819,2 @@ | ||
replace: replaceWithBlock(match => { | ||
// $FlowFixMe[incompatible-cast] | ||
const tag = 'h' + match[1].length; | ||
@@ -937,3 +955,3 @@ return richText.$createHeadingNode(tag); | ||
* | ||
* | ||
* | ||
*/ | ||
@@ -940,0 +958,0 @@ const ELEMENT_TRANSFORMERS = [HEADING, QUOTE, CODE, UNORDERED_LIST, ORDERED_LIST]; // Order of text format transformers matters: |
@@ -7,22 +7,23 @@ /** | ||
*/ | ||
var n=require("lexical"),y=require("@lexical/code"),D=require("@lexical/link"),E=require("@lexical/list"),F=require("@lexical/rich-text");function G(a,b){const c={};for(const d of a)a=b(d),c[a]?c[a].push(d):c[a]=[d];return c}function H(a){a=G(a,b=>b.type);return{element:a.element,textFormat:a["text-format"],textMatch:a["text-match"]}} | ||
function aa(a){const b=H(a),c=b.textFormat.filter(d=>1===d.format.length);return()=>{const d=[];var e=n.$getRoot().getChildren();for(const f of e)e=ba(f,b.element,c,b.textMatch),null!=e&&d.push(e);return d.join("\n")}}function ba(a,b,c,d){for(const e of b)if(b=e.export(a,f=>J(f,c,d)),null!=b)return b;return n.$isElementNode(a)?J(a,c,d):null} | ||
function J(a,b,c){const d=[];a=a.getChildren();a:for(const e of a)if(n.$isLineBreakNode(e))d.push("\n");else if(n.$isTextNode(e))d.push(K(e,e.getTextContent(),b));else{for(const f of c)if(a=f.export(e,l=>J(l,b,c),(l,h)=>K(l,h,b)),null!=a){d.push(a);continue a}n.$isElementNode(e)&&d.push(J(e,b,c))}return d.join("")}function K(a,b,c){const d=new Set;for(const f of c){c=f.format[0];const l=f.tag;if(L(a,c)&&!d.has(c)){d.add(c);var e=M(a,!0);L(e,c)||(b=l+b);e=M(a,!1);L(e,c)||(b+=l)}}return b} | ||
function M(a,b){let c=b?a.getPreviousSibling():a.getNextSibling();c||(a=a.getParentOrThrow(),a.isInline()&&(c=b?a.getPreviousSibling():a.getNextSibling()));for(;c;){if(n.$isElementNode(c)){if(!c.isInline())break;a=b?c.getLastDescendant():c.getFirstDescendant();if(n.$isTextNode(a))return a;c=b?c.getPreviousSibling():c.getNextSibling()}if(n.$isTextNode(c))return c;if(!n.$isElementNode(c))break}return null}function L(a,b){return n.$isTextNode(a)&&a.hasFormat(b)}const N=/^```(\w{1,10})?\s?$/; | ||
function ca(a){const b=H(a),c=da(b.textFormat);return d=>{d=d.split("\n");const e=d.length,f=n.$getRoot();f.clear();for(let q=0;q<e;q++){var l=d[q];a:{var h=d,r=q;var u=f;var p=h[r].match(N);if(p)for(var t=r,m=h.length;++t<m;)if(h[t].match(N)){p=y.$createCodeNode(p[1]);h=n.$createTextNode(h.slice(r+1,t).join("\n"));p.append(h);u.append(p);u=[p,t];break a}u=[null,r]}const [k,g]=u;if(null!=k)q=g;else{p=f;m=b.element;u=c;t=b.textMatch;h=n.$createTextNode(l);r=n.$createParagraphNode();r.append(h);p.append(r); | ||
for(const {regExp:v,replace:w}of m)if(p=l.match(v)){h.setTextContent(l.slice(p[0].length));w(r,[h],p,!0);break}O(h,u,t)}}f.selectEnd()}} | ||
function O(a,b,c){const d=a.getTextContent();a:{var e=d.match(b.openTagsRegExp);if(null!=e)for(f of e)if(e=b.fullMatchRegExpByTag[f.replace(/^\s/,"")],null!=e&&(e=d.match(e),null!=e)){var f=e;break a}f=null}if(f){if(f[0]===d)var l=a;else{var h=f.index,r=h+f[0].length;0===h?[l,p]=a.splitText(r):[,l,p]=a.splitText(h,r)}l.setTextContent(f[2]);if(h=b.transformersByTag[f[1]])for(var u of h.format)l.hasFormat(u)||l.toggleFormat(u);l.hasFormat("code")||O(l,b,c);p&&O(p,b,c)}else a:for(b=a;b;){for(h of c)if(l= | ||
b.getTextContent().match(h.importRegExp)){var p=l.index;u=p+l[0].length;0===p?[r,b]=b.splitText(u):[,r,b]=b.splitText(p,u);h.replace(r,l);continue a}break}}function da(a){const b={},c={},d=[];for(const e of a){({tag:a}=e);b[a]=e;const 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}}const P=/[!-/:-@[-`{-~\s]/; | ||
function Q(a,b,c){const d=c.length;for(;b>=d;b--){const 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} | ||
const 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 h of e)if(E.$isListItemNode(h)){if(1===h.getChildrenSize()&& | ||
(e=h.getFirstChild(),E.$isListNode(e))){d.push(U(e,b,c+1));continue}e=" ".repeat(4*c);var l=a.getListType();l="number"===l?`${a.getStart()+f}. `:"check"===l?`- [${h.getChecked()?"x":" "}] `:"- ";d.push(e+l+b(h));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)=>F.$isQuoteNode(a)?"> "+b(a):null,regExp:/^>\s/, | ||
replace:S(()=>F.$createQuoteNode()),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?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"},ea={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:T("check"),type:"element"}, | ||
fa={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:T("number"),type:"element"},ha={format:["code"],tag:"`",type:"text-format"},ia={format:["bold","italic"],tag:"***",type:"text-format"},ja={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},ka={format:["bold"],tag:"**",type:"text-format"},la={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ma={format:["strikethrough"],tag:"~~",type:"text-format"},na={format:["italic"],tag:"*",type:"text-format"}, | ||
oa={format:["italic"],intraword:!1,tag:"_",type:"text-format"},pa={export:(a,b,c)=>{if(!D.$isLinkNode(a))return null;b=`[${a.getTextContent()}](${a.getURL()})`;const d=a.getFirstChild();return 1===a.getChildrenSize()&&n.$isTextNode(d)?c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))$/,replace:(a,b)=>{const [,c,d]=b;b=D.$createLinkNode(d);const e=n.$createTextNode(c);e.setFormat(a.getFormat());b.append(e);a.replace(b)},trigger:")",type:"text-match"},qa= | ||
[V,W,X,Y,fa],ra=[ha,ia,ja,ka,la,na,oa,ma],sa=[pa],Z=[...qa,...ra,...sa];exports.$convertFromMarkdownString=function(a,b=Z){return ca(b)(a)};exports.$convertToMarkdownString=function(a=Z){return aa(a)()};exports.BOLD_ITALIC_STAR=ia;exports.BOLD_ITALIC_UNDERSCORE=ja;exports.BOLD_STAR=ka;exports.BOLD_UNDERSCORE=la;exports.CHECK_LIST=ea;exports.CODE=X;exports.ELEMENT_TRANSFORMERS=qa;exports.HEADING=V;exports.INLINE_CODE=ha;exports.ITALIC_STAR=na;exports.ITALIC_UNDERSCORE=oa;exports.LINK=pa; | ||
exports.ORDERED_LIST=fa;exports.QUOTE=W;exports.STRIKETHROUGH=ma;exports.TEXT_FORMAT_TRANSFORMERS=ra;exports.TEXT_MATCH_TRANSFORMERS=sa;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=Y; | ||
exports.registerMarkdownShortcuts=function(a,b=Z){const c=H(b),d=G(c.textFormat,({tag:f})=>f[f.length-1]),e=G(c.textMatch,({trigger:f})=>f);return a.registerUpdateListener(({tags:f,dirtyLeaves:l,editorState:h,prevEditorState:r})=>{if(!f.has("historic")){var u=h.read(n.$getSelection);f=r.read(n.$getSelection);if(n.$isRangeSelection(f)&&n.$isRangeSelection(u)&&u.isCollapsed()){r=u.anchor.key;var p=u.anchor.offset,t=h._nodeMap.get(r);n.$isTextNode(t)&&l.has(r)&&(1===p||p===f.anchor.offset+1)&&a.update(()=> | ||
{if(!t.hasFormat("code")){var m=t.getParent();if(null!==m&&!y.$isCodeNode(m)){var q=u.anchor.offset;b:{var k=c.element,g=m.getParent();if(n.$isRootNode(g)&&m.getFirstChild()===t&&(g=t.getTextContent()," "===g[q-1]))for(const {regExp:I,replace:B}of k)if((k=g.match(I))&&k[0].length===q){g=t.getNextSiblings();const [C,z]=t.splitText(q);C.remove();g=z?[z,...g]:g;B(m,g,k,!1);m=!0;break b}m=!1}if(!m){b:{k=t.getTextContent();m=e[k[q-1]];if(null!=m){q<k.length&&(k=k.slice(0,q));for(w of m)if(m=k.match(w.regExp), | ||
null!==m){k=m.index;g=k+m[0].length;var v=void 0;0===k?[v]=t.splitText(g):[,v]=t.splitText(k,g);v.selectNext();w.replace(v,m);var w=!0;break b}}w=!1}if(!w)b:{g=t.getTextContent();--q;const I=g[q];if(w=d[I])for(const B of w){var {tag:A}=B;w=A.length;const C=q-w+1;if(!(1<w&&!R(g,C,A,0,w)||" "===g[C-1])&&(v=g[q+1],!1!==B.intraword||!v||P.test(v))){m=v=t;k=Q(g,C,A);for(var x=m;0>k&&(x=x.getPreviousSibling())&&!n.$isLineBreakNode(x);)n.$isTextNode(x)&&(k=x.getTextContent(),m=x,k=Q(k,k.length,A));if(!(0> | ||
k||m===v&&k+w===C||(A=m.getTextContent(),0<k&&A[k-1]===I||(x=A[k-1],!1===B.intraword&&x&&!P.test(x))))){g=v.getTextContent();g=g.slice(0,C)+g.slice(q+1);v.setTextContent(g);g=m===v?g:A;m.setTextContent(g.slice(0,k)+g.slice(k+w));g=n.$createRangeSelection();n.$setSelection(g);q=q-w*(m===v?2:1)+1;g.anchor.set(m.__key,k,"text");g.focus.set(v.__key,q,"text");for(const z of B.format)g.hasFormat(z)||g.formatText(z);g.anchor.set(g.focus.key,g.focus.offset,g.focus.type);for(const z of B.format)g.hasFormat(z)&& | ||
g.toggleFormat(z);break b}}}}}}}})}}})}; | ||
'use strict';var n=require("lexical"),y=require("@lexical/code"),D=require("@lexical/link"),E=require("@lexical/list"),F=require("@lexical/rich-text");function G(a,b){let c={};for(let d of a)a=b(d),c[a]?c[a].push(d):c[a]=[d];return c}function H(a){a=G(a,b=>b.type);return{element:a.element,textFormat:a["text-format"],textMatch:a["text-match"]}}let I=/[!-/:-@[-`{-~\s]/; | ||
function aa(a){let b=H(a),c=b.textFormat.filter(d=>1===d.format.length);return()=>{let d=[];var e=n.$getRoot().getChildren();for(let f of e)e=ba(f,b.element,c,b.textMatch),null!=e&&d.push(e);return d.join("\n")}}function ba(a,b,c,d){for(let e of b)if(b=e.export(a,f=>K(f,c,d)),null!=b)return b;return n.$isElementNode(a)?K(a,c,d):null} | ||
function K(a,b,c){let d=[];a=a.getChildren();a:for(let e of a)if(n.$isLineBreakNode(e))d.push("\n");else if(n.$isTextNode(e))d.push(L(e,e.getTextContent(),b));else{for(let f of c)if(a=f.export(e,m=>K(m,b,c),(m,h)=>L(m,h,b)),null!=a){d.push(a);continue a}n.$isElementNode(e)&&d.push(K(e,b,c))}return d.join("")} | ||
function L(a,b,c){let d=b.trim(),e=d,f=new Set;for(let h of c){c=h.format[0];let p=h.tag;if(M(a,c)&&!f.has(c)){f.add(c);var m=N(a,!0);M(m,c)||(e=p+e);m=N(a,!1);M(m,c)||(e+=p)}}return b.replace(d,e)} | ||
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(n.$isElementNode(c)){if(!c.isInline())break;a=b?c.getLastDescendant():c.getFirstDescendant();if(n.$isTextNode(a))return a;c=b?c.getPreviousSibling():c.getNextSibling()}if(n.$isTextNode(c))return c;if(!n.$isElementNode(c))break}return null}function M(a,b){return n.$isTextNode(a)&&a.hasFormat(b)}let O=/^```(\w{1,10})?\s?$/; | ||
function ca(a){let b=H(a),c=da(b.textFormat);return d=>{d=d.split("\n");let e=d.length,f=n.$getRoot();f.clear();for(let q=0;q<e;q++){var m=d[q];a:{var h=d,p=q;var r=f;var w=h[p].match(O);if(w)for(var t=p,l=h.length;++t<l;)if(h[t].match(O)){w=y.$createCodeNode(w[1]);h=n.$createTextNode(h.slice(p+1,t).join("\n"));w.append(h);r.append(w);r=[w,t];break a}r=[null,p]}let [k,g]=r;if(null!=k)q=g;else{w=f;l=b.element;r=c;t=b.textMatch;h=n.$createTextNode(m);p=n.$createParagraphNode();p.append(h);w.append(p); | ||
for(let {regExp:u,replace:v}of l)if(w=m.match(u)){h.setTextContent(m.slice(w[0].length));v(p,[h],w,!0);break}P(h,r,t)}}f.selectEnd()}} | ||
function P(a,b,c){let d=a.getTextContent(),e=ea(d,b);if(e){if(e[0]===d)var f=a;else{var m=e.index,h=m+e[0].length;0===m?[f,r]=a.splitText(h):[,f,r]=a.splitText(m,h)}f.setTextContent(e[2]);if(m=b.transformersByTag[e[1]])for(var p of m.format)f.hasFormat(p)||f.toggleFormat(p);f.hasFormat("code")||P(f,b,c);r&&P(r,b,c)}else a:for(b=a;b;){for(m of c)if(f=b.getTextContent().match(m.importRegExp)){var r=f.index;p=r+f[0].length;0===r?[h,b]=b.splitText(p):[,h,b]=b.splitText(r,p);m.replace(h,f);continue a}break}} | ||
function ea(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}=c;d=a[e-1];e=a[e+c[0].length];if(!(d&&!I.test(d)||e&&!I.test(e)))return c}}return null} | ||
function da(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} | ||
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 h of e)if(E.$isListItemNode(h)){if(1===h.getChildrenSize()&& | ||
(e=h.getFirstChild(),E.$isListNode(e))){d.push(U(e,b,c+1));continue}e=" ".repeat(4*c);var m=a.getListType();m="number"===m?`${a.getStart()+f}. `:"check"===m?`- [${h.getChecked()?"x":" "}] `:"- ";d.push(e+m+b(h));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)=>F.$isQuoteNode(a)?"> "+b(a):null,regExp:/^>\s/, | ||
replace:S(()=>F.$createQuoteNode()),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?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"},fa={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:T("check"),type:"element"}, | ||
ha={export:(a,b)=>E.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:T("number"),type:"element"},ia={format:["code"],tag:"`",type:"text-format"},ja={format:["bold","italic"],tag:"***",type:"text-format"},ka={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},la={format:["bold"],tag:"**",type:"text-format"},ma={format:["bold"],intraword:!1,tag:"__",type:"text-format"},na={format:["strikethrough"],tag:"~~",type:"text-format"},oa={format:["italic"],tag:"*",type:"text-format"}, | ||
pa={format:["italic"],intraword:!1,tag:"_",type:"text-format"},qa={export:(a,b,c)=>{if(!D.$isLinkNode(a))return null;b=`[${a.getTextContent()}](${a.getURL()})`;const d=a.getFirstChild();return 1===a.getChildrenSize()&&n.$isTextNode(d)?c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))$/,replace:(a,b)=>{const [,c,d]=b;b=D.$createLinkNode(d);const e=n.$createTextNode(c);e.setFormat(a.getFormat());b.append(e);a.replace(b)},trigger:")",type:"text-match"},ra= | ||
[V,W,X,Y,ha],sa=[ia,ja,ka,la,ma,oa,pa,na],ta=[qa],Z=[...ra,...sa,...ta];exports.$convertFromMarkdownString=function(a,b=Z){return ca(b)(a)};exports.$convertToMarkdownString=function(a=Z){return aa(a)()};exports.BOLD_ITALIC_STAR=ja;exports.BOLD_ITALIC_UNDERSCORE=ka;exports.BOLD_STAR=la;exports.BOLD_UNDERSCORE=ma;exports.CHECK_LIST=fa;exports.CODE=X;exports.ELEMENT_TRANSFORMERS=ra;exports.HEADING=V;exports.INLINE_CODE=ia;exports.ITALIC_STAR=oa;exports.ITALIC_UNDERSCORE=pa;exports.LINK=qa; | ||
exports.ORDERED_LIST=ha;exports.QUOTE=W;exports.STRIKETHROUGH=na;exports.TEXT_FORMAT_TRANSFORMERS=sa;exports.TEXT_MATCH_TRANSFORMERS=ta;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=Y; | ||
exports.registerMarkdownShortcuts=function(a,b=Z){let c=H(b),d=G(c.textFormat,({tag:f})=>f[f.length-1]),e=G(c.textMatch,({trigger:f})=>f);return a.registerUpdateListener(({tags:f,dirtyLeaves:m,editorState:h,prevEditorState:p})=>{if(!f.has("historic")){var r=h.read(n.$getSelection);f=p.read(n.$getSelection);if(n.$isRangeSelection(f)&&n.$isRangeSelection(r)&&r.isCollapsed()){p=r.anchor.key;var w=r.anchor.offset,t=h._nodeMap.get(p);n.$isTextNode(t)&&m.has(p)&&(1===w||w===f.anchor.offset+1)&&a.update(()=> | ||
{if(!t.hasFormat("code")){var l=t.getParent();if(null!==l&&!y.$isCodeNode(l)){var q=r.anchor.offset;b:{var k=c.element,g=l.getParent();if(n.$isRootNode(g)&&l.getFirstChild()===t&&(g=t.getTextContent()," "===g[q-1]))for(let {regExp:J,replace:B}of k)if((k=g.match(J))&&k[0].length===q){g=t.getNextSiblings();let [C,z]=t.splitText(q);C.remove();g=z?[z,...g]:g;B(l,g,k,!1);l=!0;break b}l=!1}if(!l){b:{k=t.getTextContent();l=e[k[q-1]];if(null!=l){q<k.length&&(k=k.slice(0,q));for(v of l)if(l=k.match(v.regExp), | ||
null!==l){k=l.index;g=k+l[0].length;var u=void 0;0===k?[u]=t.splitText(g):[,u]=t.splitText(k,g);u.selectNext();v.replace(u,l);var v=!0;break b}}v=!1}if(!v)b:{g=t.getTextContent();--q;let J=g[q];if(v=d[J])for(let B of v){var {tag:A}=B;v=A.length;let C=q-v+1;if(!(1<v&&!R(g,C,A,0,v)||" "===g[C-1])&&(u=g[q+1],!1!==B.intraword||!u||I.test(u))){l=u=t;k=Q(g,C,A);for(var x=l;0>k&&(x=x.getPreviousSibling())&&!n.$isLineBreakNode(x);)n.$isTextNode(x)&&(k=x.getTextContent(),l=x,k=Q(k,k.length,A));if(!(0>k||l=== | ||
u&&k+v===C||(A=l.getTextContent(),0<k&&A[k-1]===J||(x=A[k-1],!1===B.intraword&&x&&!I.test(x))))){g=u.getTextContent();g=g.slice(0,C)+g.slice(q+1);u.setTextContent(g);g=l===u?g:A;l.setTextContent(g.slice(0,k)+g.slice(k+v));g=n.$createRangeSelection();n.$setSelection(g);q=q-v*(l===u?2:1)+1;g.anchor.set(l.__key,k,"text");g.focus.set(u.__key,q,"text");for(let z of B.format)g.hasFormat(z)||g.formatText(z);g.anchor.set(g.focus.key,g.focus.offset,g.focus.type);for(let z of B.format)g.hasFormat(z)&&g.toggleFormat(z); | ||
break b}}}}}}}})}}})} |
@@ -11,14 +11,14 @@ { | ||
"license": "MIT", | ||
"version": "0.2.9", | ||
"version": "0.3.0", | ||
"main": "LexicalMarkdown.js", | ||
"peerDependencies": { | ||
"lexical": "0.2.9" | ||
"lexical": "0.3.0" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.2.9", | ||
"@lexical/code": "0.2.9", | ||
"@lexical/text": "0.2.9", | ||
"@lexical/rich-text": "0.2.9", | ||
"@lexical/list": "0.2.9", | ||
"@lexical/link": "0.2.9" | ||
"@lexical/utils": "0.3.0", | ||
"@lexical/code": "0.3.0", | ||
"@lexical/text": "0.3.0", | ||
"@lexical/rich-text": "0.3.0", | ||
"@lexical/list": "0.3.0", | ||
"@lexical/link": "0.3.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
50234
941
0
+ Added@lexical/clipboard@0.3.0(transitive)
+ Added@lexical/code@0.3.0(transitive)
+ Added@lexical/html@0.3.0(transitive)
+ Added@lexical/link@0.3.0(transitive)
+ Added@lexical/list@0.3.0(transitive)
+ Added@lexical/rich-text@0.3.0(transitive)
+ Added@lexical/selection@0.3.0(transitive)
+ Added@lexical/table@0.3.0(transitive)
+ Added@lexical/text@0.3.0(transitive)
+ Added@lexical/utils@0.3.0(transitive)
+ Addedlexical@0.3.0(transitive)
- Removed@lexical/clipboard@0.2.9(transitive)
- Removed@lexical/code@0.2.9(transitive)
- Removed@lexical/link@0.2.9(transitive)
- Removed@lexical/list@0.2.9(transitive)
- Removed@lexical/rich-text@0.2.9(transitive)
- Removed@lexical/selection@0.2.9(transitive)
- Removed@lexical/table@0.2.9(transitive)
- Removed@lexical/text@0.2.9(transitive)
- Removed@lexical/utils@0.2.9(transitive)
- Removedlexical@0.2.9(transitive)
Updated@lexical/code@0.3.0
Updated@lexical/link@0.3.0
Updated@lexical/list@0.3.0
Updated@lexical/rich-text@0.3.0
Updated@lexical/text@0.3.0
Updated@lexical/utils@0.3.0