@lexical/markdown
Advanced tools
Comparing version 0.17.2-nightly.20240913.0 to 0.17.2-nightly.20240916.0
@@ -855,2 +855,12 @@ /** | ||
const ORDERED_LIST_REGEX = /^(\s*)(\d{1,})\.\s/; | ||
const UNORDERED_LIST_REGEX = /^(\s*)[-*+]\s/; | ||
const CHECK_LIST_REGEX = /^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i; | ||
const HEADING_REGEX = /^(#{1,6})\s/; | ||
const QUOTE_REGEX = /^>\s/; | ||
const CODE_START_REGEX = /^[ \t]*```(\w+)?/; | ||
const CODE_END_REGEX = /[ \t]*```$/; | ||
const CODE_SINGLE_LINE_REGEX = /^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/; | ||
const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/; | ||
const TABLE_ROW_DIVIDER_REG_EXP = /^(\| ?:?-*:? ?)+\|\s?$/; | ||
const createBlockNode = createNode => { | ||
@@ -941,3 +951,3 @@ return (parentNode, children, match) => { | ||
}, | ||
regExp: /^(#{1,6})\s/, | ||
regExp: HEADING_REGEX, | ||
replace: createBlockNode(match => { | ||
@@ -962,3 +972,3 @@ const tag = 'h' + match[1].length; | ||
}, | ||
regExp: /^>\s/, | ||
regExp: QUOTE_REGEX, | ||
replace: (parentNode, children, _match, isImport) => { | ||
@@ -992,5 +1002,5 @@ if (isImport) { | ||
optional: true, | ||
regExp: /[ \t]*```$/ | ||
regExp: CODE_END_REGEX | ||
}, | ||
regExpStart: /^[ \t]*```(\w+)?/, | ||
regExpStart: CODE_START_REGEX, | ||
replace: (rootNode, children, startMatch, endMatch, linesInBetween, isImport) => { | ||
@@ -1046,3 +1056,3 @@ let codeBlockNode; | ||
}, | ||
regExp: /^(\s*)[-*+]\s/, | ||
regExp: UNORDERED_LIST_REGEX, | ||
replace: listReplace('bullet'), | ||
@@ -1056,3 +1066,3 @@ type: 'element' | ||
}, | ||
regExp: /^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i, | ||
regExp: CHECK_LIST_REGEX, | ||
replace: listReplace('check'), | ||
@@ -1066,3 +1076,3 @@ type: 'element' | ||
}, | ||
regExp: /^(\s*)(\d{1,})\.\s/, | ||
regExp: ORDERED_LIST_REGEX, | ||
replace: listReplace('number'), | ||
@@ -1156,3 +1166,40 @@ type: 'element' | ||
}; | ||
function normalizeMarkdown(input) { | ||
const lines = input.split('\n'); | ||
let inCodeBlock = false; | ||
const sanitizedLines = []; | ||
for (let i = 0; i < lines.length; i++) { | ||
const line = lines[i]; | ||
const lastLine = sanitizedLines[sanitizedLines.length - 1]; | ||
// Code blocks of ```single line``` don't toggle the inCodeBlock flag | ||
if (CODE_SINGLE_LINE_REGEX.test(line)) { | ||
sanitizedLines.push(line); | ||
continue; | ||
} | ||
// Detect the start or end of a code block | ||
if (CODE_START_REGEX.test(line) || CODE_END_REGEX.test(line)) { | ||
inCodeBlock = !inCodeBlock; | ||
sanitizedLines.push(line); | ||
continue; | ||
} | ||
// If we are inside a code block, keep the line unchanged | ||
if (inCodeBlock) { | ||
sanitizedLines.push(line); | ||
continue; | ||
} | ||
// In markdown the concept of "empty paragraphs" does not exist. | ||
// Blocks must be separated by an empty line. Non-empty adjacent lines must be merged. | ||
if (line === '' || lastLine === '' || !lastLine || HEADING_REGEX.test(lastLine) || HEADING_REGEX.test(line) || QUOTE_REGEX.test(line) || ORDERED_LIST_REGEX.test(line) || UNORDERED_LIST_REGEX.test(line) || CHECK_LIST_REGEX.test(line) || TABLE_ROW_REG_EXP.test(line) || TABLE_ROW_DIVIDER_REG_EXP.test(line)) { | ||
sanitizedLines.push(line); | ||
} else { | ||
sanitizedLines[sanitizedLines.length - 1] = lastLine + line; | ||
} | ||
} | ||
return sanitizedLines.join('\n'); | ||
} | ||
/** | ||
@@ -1181,4 +1228,5 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
function $convertFromMarkdownString(markdown, transformers = TRANSFORMERS, node, shouldPreserveNewLines = false) { | ||
const sanitizedMarkdown = shouldPreserveNewLines ? markdown : normalizeMarkdown(markdown); | ||
const importMarkdown = createMarkdownImport(transformers, shouldPreserveNewLines); | ||
return importMarkdown(markdown, node); | ||
return importMarkdown(sanitizedMarkdown, node); | ||
} | ||
@@ -1185,0 +1233,0 @@ |
@@ -9,34 +9,35 @@ /** | ||
'use strict';var n=require("lexical"),x=require("@lexical/list"),E=require("@lexical/rich-text"),aa=require("@lexical/utils"),F=require("@lexical/code"),G=require("@lexical/link");function H(a,c){let b={};for(let e of a)a=c(e),b[a]?b[a].push(e):b[a]=[e];return b}function I(a){a=H(a,c=>c.type);return{element:a.element||[],multilineElement:a["multiline-element"]||[],textFormat:a["text-format"]||[],textMatch:a["text-match"]||[]}}let J=/[!-/:-@[-`{-~\s]/,ba=/^\s{0,3}$/; | ||
function K(a){if(!n.$isParagraphNode(a))return!1;let c=a.getFirstChild();return null==c||1===a.getChildrenSize()&&n.$isTextNode(c)&&ba.test(c.getTextContent())}function ca(a,c=!1){let b=I(a),e=[...b.multilineElement,...b.element],d=!c,f=b.textFormat.filter(h=>1===h.format.length);return h=>{let m=[];h=(h||n.$getRoot()).getChildren();for(let k=0;k<h.length;k++){let t=h[k],y=da(t,e,f,b.textMatch);null!=y&&m.push(d&&0<k&&!K(t)&&!K(h[k-1])?"\n".concat(y):y)}return m.join("\n")}} | ||
function da(a,c,b,e){for(let d of c)if(d.export&&(c=d.export(a,f=>L(f,b,e)),null!=c))return c;return n.$isElementNode(a)?L(a,b,e):n.$isDecoratorNode(a)?a.getTextContent():null} | ||
function L(a,c,b){let e=[];a=a.getChildren();a:for(let d of a){for(let f of b)if(a=f.export(d,h=>L(h,c,b),(h,m)=>M(h,m,c)),null!=a){e.push(a);continue a}n.$isLineBreakNode(d)?e.push("\n"):n.$isTextNode(d)?e.push(M(d,d.getTextContent(),c)):n.$isElementNode(d)?e.push(L(d,c,b)):n.$isDecoratorNode(d)&&e.push(d.getTextContent())}return e.join("")} | ||
function M(a,c,b){let e=c.trim(),d=e,f=new Set;for(let m of b){b=m.format[0];let k=m.tag;if(O(a,b)&&!f.has(b)){f.add(b);var h=P(a,!0);O(h,b)||(d=k+d);h=P(a,!1);O(h,b)||(d+=k)}}return c.replace(e,()=>d)} | ||
'use strict';var n=require("lexical"),x=require("@lexical/list"),E=require("@lexical/rich-text"),aa=require("@lexical/utils"),F=require("@lexical/code"),G=require("@lexical/link");function H(a,c){let b={};for(let f of a)a=c(f),b[a]?b[a].push(f):b[a]=[f];return b}function I(a){a=H(a,c=>c.type);return{element:a.element||[],multilineElement:a["multiline-element"]||[],textFormat:a["text-format"]||[],textMatch:a["text-match"]||[]}}let J=/[!-/:-@[-`{-~\s]/,ba=/^\s{0,3}$/; | ||
function K(a){if(!n.$isParagraphNode(a))return!1;let c=a.getFirstChild();return null==c||1===a.getChildrenSize()&&n.$isTextNode(c)&&ba.test(c.getTextContent())}function ca(a,c=!1){let b=I(a),f=[...b.multilineElement,...b.element],d=!c,e=b.textFormat.filter(h=>1===h.format.length);return h=>{let g=[];h=(h||n.$getRoot()).getChildren();for(let k=0;k<h.length;k++){let t=h[k],y=da(t,f,e,b.textMatch);null!=y&&g.push(d&&0<k&&!K(t)&&!K(h[k-1])?"\n".concat(y):y)}return g.join("\n")}} | ||
function da(a,c,b,f){for(let d of c)if(d.export&&(c=d.export(a,e=>L(e,b,f)),null!=c))return c;return n.$isElementNode(a)?L(a,b,f):n.$isDecoratorNode(a)?a.getTextContent():null} | ||
function L(a,c,b){let f=[];a=a.getChildren();a:for(let d of a){for(let e of b)if(a=e.export(d,h=>L(h,c,b),(h,g)=>M(h,g,c)),null!=a){f.push(a);continue a}n.$isLineBreakNode(d)?f.push("\n"):n.$isTextNode(d)?f.push(M(d,d.getTextContent(),c)):n.$isElementNode(d)?f.push(L(d,c,b)):n.$isDecoratorNode(d)&&f.push(d.getTextContent())}return f.join("")} | ||
function M(a,c,b){let f=c.trim(),d=f,e=new Set;for(let g of b){b=g.format[0];let k=g.tag;if(O(a,b)&&!e.has(b)){e.add(b);var h=P(a,!0);O(h,b)||(d=k+d);h=P(a,!1);O(h,b)||(d+=k)}}return c.replace(f,()=>d)} | ||
function P(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();b||(a=a.getParentOrThrow(),a.isInline()&&(b=c?a.getPreviousSibling():a.getNextSibling()));for(;b;){if(n.$isElementNode(b)){if(!b.isInline())break;a=c?b.getLastDescendant():b.getFirstDescendant();if(n.$isTextNode(a))return a;b=c?b.getPreviousSibling():b.getNextSibling()}if(n.$isTextNode(b))return b;if(!n.$isElementNode(b))break}return null}function O(a,c){return n.$isTextNode(a)&&a.hasFormat(c)} | ||
let Q="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,ea=Q&&"documentMode"in document?document.documentMode:null;Q&&"InputEvent"in window&&!ea?"getTargetRanges"in new window.InputEvent("input"):!1; | ||
let R=Q&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),S=Q&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,fa=Q&&/^(?=.*Chrome).*/i.test(navigator.userAgent),T=Q&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!fa; | ||
function ha(a,c=!1){let b=I(a),e=ia(b.textFormat);return(d,f)=>{d=d.split("\n");let h=d.length;f=f||n.$getRoot();f.clear();for(let u=0;u<h;u++){var m=d[u];a:{var k=d;var t=u,y=b.multilineElement,w=f;for(let {regExpStart:A,regExpEnd:v,replace:C}of y)if(y=k[t].match(A)){var p="object"===typeof v&&"regExp"in v?v.regExp:v,r=v&&"object"===typeof v&&"optional"in v?v.optional:!v,g=t,l=k.length;for(;g<l;){var q=p?k[g].match(p):null;if(q||r&&!(r&&g<l-1))if(q&&t===g&&q.index===y.index)g++;else{p=[];if(q&&t=== | ||
g)p.push(k[t].slice(y[0].length,-q[0].length));else for(r=t;r<=g;r++)r===t?(l=k[r].slice(y[0].length),p.push(l)):r===g&&q?(l=k[r].slice(0,-q[0].length),p.push(l)):p.push(k[r]);if(!1!==C(w,null,y,q,p,!0)){k=[!0,g];break a}break}else g++}}k=[!1,t]}let [z,D]=k;if(z)u=D;else{k=m;g=f;q=b.element;t=e;w=b.textMatch;y=n.$createTextNode(k);m=n.$createParagraphNode();m.append(y);g.append(m);for(let {regExp:A,replace:v}of q)if(g=k.match(A))if(y.setTextContent(k.slice(g[0].length)),!1!==v(m,[y],g,!0))break;U(y, | ||
t,w);m.isAttached()&&0<k.length&&(k=m.getPreviousSibling(),n.$isParagraphNode(k)||E.$isQuoteNode(k)||x.$isListNode(k))&&(t=k,x.$isListNode(k)&&(k=k.getLastDescendant(),t=null==k?null:aa.$findMatchingParent(k,x.$isListItemNode)),null!=t&&0<t.getTextContentSize()&&(t.splice(t.getChildrenSize(),0,[n.$createLineBreakNode(),...m.getChildren()]),m.remove()))}}d=f.getChildren();for(let u of d)!c&&K(u)&&1<f.getChildrenSize()&&u.remove();null!==n.$getSelection()&&f.selectStart()}} | ||
function U(a,c,b){var e=a.getTextContent();let d=ja(e,c);if(d){var f,h;if(d[0]===e)var m=a;else{e=d.index||0;let k=e+d[0].length;0===e?[m,f]=a.splitText(k):[h,m,f]=a.splitText(e,k)}m.setTextContent(d[2]);if(a=c.transformersByTag[d[1]])for(let k of a.format)m.hasFormat(k)||m.toggleFormat(k);m.hasFormat("code")||U(m,c,b);h&&U(h,c,b);f&&U(f,c,b)}else V(a,b)} | ||
function V(a,c){a:for(;a;){for(let b of c){let e=a.getTextContent().match(b.importRegExp);if(!e)continue;let d=e.index||0,f=d+e[0].length,h,m;0===d?[h,a]=a.splitText(f):[,h,m]=a.splitText(d,f);m&&V(m,c);b.replace(h,e);continue a}break}} | ||
function ja(a,c){var b=a.match(c.openTagsRegExp);if(null==b)return null;for(let f of b){var e=f.replace(/^\s/,"");b=c.fullMatchRegExpByTag[e];if(null!=b&&(b=a.match(b),e=c.transformersByTag[e],null!=b&&null!=e)){if(!1!==e.intraword)return b;var {index:d=0}=b;e=a[d-1];d=a[d+b[0].length];if(!(e&&!J.test(e)||d&&!J.test(d)))return b}}return null} | ||
function ia(a){let c={},b={},e=[];for(let d of a){({tag:a}=d);c[a]=d;let f=a.replace(/(\*|\^|\+)/g,"\\$1");e.push(f);b[a]=R||S||T?new RegExp(`(${f})(?![${f}\\s])(.*?[^${f}\\s])${f}(?!${f})`):new RegExp(`(?<![\\\\${f}])(${f})((\\\\${f})?.*?[^${f}\\s](\\\\${f})?)((?<!\\\\)|(?<=\\\\\\\\))(${f})(?![\\\\${f}])`)}return{fullMatchRegExpByTag:b,openTagsRegExp:new RegExp((R||S||T?"":"(?<![\\\\])")+"("+e.join("|")+")","g"),transformersByTag:c}}var ka; | ||
function W(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}ka=W&&W.__esModule&&Object.prototype.hasOwnProperty.call(W,"default")?W["default"]:W; | ||
function la(a,c,b){let e=b.length;for(;c>=e;c--){let d=c-e;if(ma(a,d,b,0,e)&&" "!==a[d+e])return d}return-1}function ma(a,c,b,e,d){for(let f=0;f<d;f++)if(a[c+f]!==b[e+f])return!1;return!0} | ||
let na=a=>(c,b,e)=>{e=a(e);e.append(...b);c.replace(e);e.select(0,0)},X=a=>(c,b,e)=>{var d=c.getPreviousSibling(),f=c.getNextSibling();const h=x.$createListItemNode("check"===a?"x"===e[3]:void 0);x.$isListNode(f)&&f.getListType()===a?(d=f.getFirstChild(),null!==d?d.insertBefore(h):f.append(h),c.remove()):x.$isListNode(d)&&d.getListType()===a?(d.append(h),c.remove()):(f=x.$createListNode(a,"number"===a?Number(e[2]):void 0),f.append(h),c.replace(f));h.append(...b);h.select(0,0);b=e[1];c=b.match(/\t/g); | ||
b=b.match(/ /g);e=0;c&&(e+=c.length);b&&(e+=Math.floor(b.length/4));(c=e)&&h.setIndent(c)},Y=(a,c,b)=>{const e=[];var d=a.getChildren();let f=0;for(const m of d)if(x.$isListItemNode(m)){if(1===m.getChildrenSize()&&(d=m.getFirstChild(),x.$isListNode(d))){e.push(Y(d,c,b+1));continue}d=" ".repeat(4*b);var h=a.getListType();h="number"===h?`${a.getStart()+f}. `:"check"===h?`- [${m.getChecked()?"x":" "}] `:"- ";e.push(d+h+c(m));f++}return e.join("\n")},oa={dependencies:[E.HeadingNode],export:(a,c)=>{if(!E.$isHeadingNode(a))return null; | ||
const b=Number(a.getTag().slice(1));return"#".repeat(b)+" "+c(a)},regExp:/^(#{1,6})\s/,replace:na(a=>E.$createHeadingNode("h"+a[1].length)),type:"element"},pa={dependencies:[E.QuoteNode],export:(a,c)=>{if(!E.$isQuoteNode(a))return null;a=c(a).split("\n");c=[];for(const b of a)c.push("> "+b);return c.join("\n")},regExp:/^>\s/,replace:(a,c,b,e)=>{if(e&&(b=a.getPreviousSibling(),E.$isQuoteNode(b))){b.splice(b.getChildrenSize(),0,[n.$createLineBreakNode(),...c]);b.select(0,0);a.remove();return}b=E.$createQuoteNode(); | ||
b.append(...c);a.replace(b);b.select(0,0)},type:"element"},qa={dependencies:[F.CodeNode],export:a=>{if(!F.$isCodeNode(a))return null;const c=a.getTextContent();return"```"+(a.getLanguage()||"")+(c?"\n"+c:"")+"\n```"},regExpEnd:{optional:!0,regExp:/[ \t]*```$/},regExpStart:/^[ \t]*```(\w+)?/,replace:(a,c,b,e,d,f)=>{if(!c&&d){if(1===d.length)e?(c=F.$createCodeNode(),b=b[1]+d[0]):(c=F.$createCodeNode(b[1]),b=d[0].startsWith(" ")?d[0].slice(1):d[0]);else{c=F.$createCodeNode(b[1]);if(0===d[0].trim().length)for(;0< | ||
d.length&&!d[0].length;)d.shift();else d[0]=d[0].startsWith(" ")?d[0].slice(1):d[0];for(;0<d.length&&!d[d.length-1].length;)d.pop();b=d.join("\n")}b=n.$createTextNode(b);c.append(b);a.append(c)}else c&&na(h=>F.$createCodeNode(h?h[1]:void 0))(a,c,b,f)},type:"multiline-element"},ra={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:/^(\s*)[-*+]\s/,replace:X("bullet"),type:"element"},sa={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)? | ||
Y(a,c,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:X("check"),type:"element"},ta={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:X("number"),type:"element"},ua={format:["code"],tag:"`",type:"text-format"},va={format:["highlight"],tag:"==",type:"text-format"},wa={format:["bold","italic"],tag:"***",type:"text-format"},xa={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},za={format:["bold"],tag:"**", | ||
type:"text-format"},Aa={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Ba={format:["strikethrough"],tag:"~~",type:"text-format"},Ca={format:["italic"],tag:"*",type:"text-format"},Da={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Ea={dependencies:[G.LinkNode],export:(a,c,b)=>{if(!G.$isLinkNode(a))return null;c=(c=a.getTitle())?`[${a.getTextContent()}](${a.getURL()} "${c}")`:`[${a.getTextContent()}](${a.getURL()})`;const e=a.getFirstChild();return 1===a.getChildrenSize()&&n.$isTextNode(e)? | ||
b(e,c):c},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(a,c)=>{const [,b,e,d]=c;c=G.$createLinkNode(e,{title:d});const f=n.$createTextNode(b);f.setFormat(a.getFormat());c.append(f);a.replace(c)},trigger:")",type:"text-match"},Fa=[oa,pa,ra,ta],Ga=[qa],Ha=[ua,wa,xa,za,Aa,va,Ca,Da,Ba],Ia=[Ea],Z=[...Fa,...Ga,...Ha,...Ia]; | ||
exports.$convertFromMarkdownString=function(a,c=Z,b,e=!1){return ha(c,e)(a,b)};exports.$convertToMarkdownString=function(a=Z,c,b=!1){return ca(a,b)(c)};exports.BOLD_ITALIC_STAR=wa;exports.BOLD_ITALIC_UNDERSCORE=xa;exports.BOLD_STAR=za;exports.BOLD_UNDERSCORE=Aa;exports.CHECK_LIST=sa;exports.CODE=qa;exports.ELEMENT_TRANSFORMERS=Fa;exports.HEADING=oa;exports.HIGHLIGHT=va;exports.INLINE_CODE=ua;exports.ITALIC_STAR=Ca;exports.ITALIC_UNDERSCORE=Da;exports.LINK=Ea; | ||
exports.MULTILINE_ELEMENT_TRANSFORMERS=Ga;exports.ORDERED_LIST=ta;exports.QUOTE=pa;exports.STRIKETHROUGH=Ba;exports.TEXT_FORMAT_TRANSFORMERS=Ha;exports.TEXT_MATCH_TRANSFORMERS=Ia;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=ra; | ||
exports.registerMarkdownShortcuts=function(a,c=Z){let b=I(c),e=H(b.textFormat,({tag:f})=>f[f.length-1]),d=H(b.textMatch,({trigger:f})=>f);for(let f of c)if(c=f.type,"element"===c||"text-match"===c||"multiline-element"===c){c=f.dependencies;for(let h of c)a.hasNode(h)||ka(173,h.getType())}return a.registerUpdateListener(({tags:f,dirtyLeaves:h,editorState:m,prevEditorState:k})=>{if(!f.has("collaboration")&&!f.has("historic")&&!a.isComposing()){var t=m.read(n.$getSelection);f=k.read(n.$getSelection); | ||
if(n.$isRangeSelection(f)&&n.$isRangeSelection(t)&&t.isCollapsed()){k=t.anchor.key;var y=t.anchor.offset,w=m._nodeMap.get(k);!n.$isTextNode(w)||!h.has(k)||1!==y&&y>f.anchor.offset+1||a.update(()=>{if(!w.hasFormat("code")){var p=w.getParent();if(null!==p&&!F.$isCodeNode(p)){var r=t.anchor.offset;b:{var g=b.element;var l=p.getParent();if(n.$isRootOrShadowRoot(l)&&p.getFirstChild()===w&&(l=w.getTextContent()," "===l[r-1]))for(let {regExp:v,replace:C}of g)if((g=l.match(v))&&g[0].length===(g[0].endsWith(" ")? | ||
r:r-1)){var q=w.getNextSiblings();let [B,N]=w.splitText(r);B.remove();q=N?[N,...q]:q;if(!1!==C(p,q,g,!1)){l=!0;break b}}l=!1}if(!l){b:{g=b.multilineElement;l=p.getParent();if(n.$isRootOrShadowRoot(l)&&p.getFirstChild()===w&&(l=w.getTextContent()," "===l[r-1]))for(let {regExpStart:v,replace:C,regExpEnd:B}of g)if(!(B&&!("optional"in B)||B&&"optional"in B&&!B.optional)&&(g=l.match(v))&&g[0].length===(g[0].endsWith(" ")?r:r-1)){q=w.getNextSiblings();let [N,ya]=w.splitText(r);N.remove();q=ya?[ya,...q]: | ||
q;if(!1!==C(p,q,g,null,null,!1)){p=!0;break b}}p=!1}if(!p){b:{l=w.getTextContent();p=d[l[r-1]];if(null!=p){r<l.length&&(l=l.slice(0,r));for(z of p)if(p=l.match(z.regExp),null!==p){l=p.index||0;g=l+p[0].length;var u=void 0;0===l?[u]=w.splitText(g):[,u]=w.splitText(l,g);u.selectNext(0,0);z.replace(u,p);var z=!0;break b}}z=!1}if(!z)b:if(g=w.getTextContent(),--r,q=g[r],z=e[q])for(let v of z){var {tag:D}=v;z=D.length;let C=r-z+1;if(!(1<z&&!ma(g,C,D,0,z)||" "===g[C-1])&&(u=g[r+1],!1!==v.intraword||!u|| | ||
J.test(u))){p=u=w;l=la(g,C,D);for(var A=p;0>l&&(A=A.getPreviousSibling())&&!n.$isLineBreakNode(A);)n.$isTextNode(A)&&(l=A.getTextContent(),p=A,l=la(l,l.length,D));if(!(0>l||p===u&&l+z===C||(D=p.getTextContent(),0<l&&D[l-1]===q||(A=D[l-1],!1===v.intraword&&A&&!J.test(A))))){g=u.getTextContent();g=g.slice(0,C)+g.slice(r+1);u.setTextContent(g);g=p===u?g:D;p.setTextContent(g.slice(0,l)+g.slice(l+z));g=n.$getSelection();q=n.$createRangeSelection();n.$setSelection(q);r=r-z*(p===u?2:1)+1;q.anchor.set(p.__key, | ||
l,"text");q.focus.set(u.__key,r,"text");for(let B of v.format)q.hasFormat(B)||q.formatText(B);q.anchor.set(q.focus.key,q.focus.offset,q.focus.type);for(let B of v.format)q.hasFormat(B)&&q.toggleFormat(B);n.$isRangeSelection(g)&&(q.format=g.format);break b}}}}}}}})}}})} | ||
function ha(a,c=!1){let b=I(a),f=ia(b.textFormat);return(d,e)=>{d=d.split("\n");let h=d.length;e=e||n.$getRoot();e.clear();for(let u=0;u<h;u++){var g=d[u];a:{var k=d;var t=u,y=b.multilineElement,w=e;for(let {regExpStart:A,regExpEnd:v,replace:C}of y)if(y=k[t].match(A)){var p="object"===typeof v&&"regExp"in v?v.regExp:v,r=v&&"object"===typeof v&&"optional"in v?v.optional:!v,l=t,m=k.length;for(;l<m;){var q=p?k[l].match(p):null;if(q||r&&!(r&&l<m-1))if(q&&t===l&&q.index===y.index)l++;else{p=[];if(q&&t=== | ||
l)p.push(k[t].slice(y[0].length,-q[0].length));else for(r=t;r<=l;r++)r===t?(m=k[r].slice(y[0].length),p.push(m)):r===l&&q?(m=k[r].slice(0,-q[0].length),p.push(m)):p.push(k[r]);if(!1!==C(w,null,y,q,p,!0)){k=[!0,l];break a}break}else l++}}k=[!1,t]}let [z,D]=k;if(z)u=D;else{k=g;l=e;q=b.element;t=f;w=b.textMatch;y=n.$createTextNode(k);g=n.$createParagraphNode();g.append(y);l.append(g);for(let {regExp:A,replace:v}of q)if(l=k.match(A))if(y.setTextContent(k.slice(l[0].length)),!1!==v(g,[y],l,!0))break;U(y, | ||
t,w);g.isAttached()&&0<k.length&&(k=g.getPreviousSibling(),n.$isParagraphNode(k)||E.$isQuoteNode(k)||x.$isListNode(k))&&(t=k,x.$isListNode(k)&&(k=k.getLastDescendant(),t=null==k?null:aa.$findMatchingParent(k,x.$isListItemNode)),null!=t&&0<t.getTextContentSize()&&(t.splice(t.getChildrenSize(),0,[n.$createLineBreakNode(),...g.getChildren()]),g.remove()))}}d=e.getChildren();for(let u of d)!c&&K(u)&&1<e.getChildrenSize()&&u.remove();null!==n.$getSelection()&&e.selectStart()}} | ||
function U(a,c,b){var f=a.getTextContent();let d=ja(f,c);if(d){var e,h;if(d[0]===f)var g=a;else{f=d.index||0;let k=f+d[0].length;0===f?[g,e]=a.splitText(k):[h,g,e]=a.splitText(f,k)}g.setTextContent(d[2]);if(a=c.transformersByTag[d[1]])for(let k of a.format)g.hasFormat(k)||g.toggleFormat(k);g.hasFormat("code")||U(g,c,b);h&&U(h,c,b);e&&U(e,c,b)}else ka(a,b)} | ||
function ka(a,c){a:for(;a;){for(let b of c){let f=a.getTextContent().match(b.importRegExp);if(!f)continue;let d=f.index||0,e=d+f[0].length,h,g;0===d?[h,a]=a.splitText(e):[,h,g]=a.splitText(d,e);g&&ka(g,c);b.replace(h,f);continue a}break}} | ||
function ja(a,c){var b=a.match(c.openTagsRegExp);if(null==b)return null;for(let e of b){var f=e.replace(/^\s/,"");b=c.fullMatchRegExpByTag[f];if(null!=b&&(b=a.match(b),f=c.transformersByTag[f],null!=b&&null!=f)){if(!1!==f.intraword)return b;var {index:d=0}=b;f=a[d-1];d=a[d+b[0].length];if(!(f&&!J.test(f)||d&&!J.test(d)))return b}}return null} | ||
function ia(a){let c={},b={},f=[];for(let d of a){({tag:a}=d);c[a]=d;let e=a.replace(/(\*|\^|\+)/g,"\\$1");f.push(e);b[a]=R||S||T?new RegExp(`(${e})(?![${e}\\s])(.*?[^${e}\\s])${e}(?!${e})`):new RegExp(`(?<![\\\\${e}])(${e})((\\\\${e})?.*?[^${e}\\s](\\\\${e})?)((?<!\\\\)|(?<=\\\\\\\\))(${e})(?![\\\\${e}])`)}return{fullMatchRegExpByTag:b,openTagsRegExp:new RegExp((R||S||T?"":"(?<![\\\\])")+"("+f.join("|")+")","g"),transformersByTag:c}}var la; | ||
function V(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}la=V&&V.__esModule&&Object.prototype.hasOwnProperty.call(V,"default")?V["default"]:V; | ||
function ma(a,c,b){let f=b.length;for(;c>=f;c--){let d=c-f;if(na(a,d,b,0,f)&&" "!==a[d+f])return d}return-1}function na(a,c,b,f,d){for(let e=0;e<d;e++)if(a[c+e]!==b[f+e])return!1;return!0} | ||
let oa=/^(\s*)(\d{1,})\.\s/,pa=/^(\s*)[-*+]\s/,qa=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,W=/^(#{1,6})\s/,ra=/^>\s/,sa=/^[ \t]*```(\w+)?/,ta=/[ \t]*```$/,ua=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,va=/^(?:\|)(.+)(?:\|)\s?$/,wa=/^(\| ?:?-*:? ?)+\|\s?$/,xa=a=>(c,b,f)=>{f=a(f);f.append(...b);c.replace(f);f.select(0,0)},X=a=>(c,b,f)=>{var d=c.getPreviousSibling(),e=c.getNextSibling();const h=x.$createListItemNode("check"===a?"x"===f[3]:void 0);x.$isListNode(e)&&e.getListType()===a?(d=e.getFirstChild(), | ||
null!==d?d.insertBefore(h):e.append(h),c.remove()):x.$isListNode(d)&&d.getListType()===a?(d.append(h),c.remove()):(e=x.$createListNode(a,"number"===a?Number(f[2]):void 0),e.append(h),c.replace(e));h.append(...b);h.select(0,0);b=f[1];c=b.match(/\t/g);b=b.match(/ /g);f=0;c&&(f+=c.length);b&&(f+=Math.floor(b.length/4));(c=f)&&h.setIndent(c)},Y=(a,c,b)=>{const f=[];var d=a.getChildren();let e=0;for(const g of d)if(x.$isListItemNode(g)){if(1===g.getChildrenSize()&&(d=g.getFirstChild(),x.$isListNode(d))){f.push(Y(d, | ||
c,b+1));continue}d=" ".repeat(4*b);var h=a.getListType();h="number"===h?`${a.getStart()+e}. `:"check"===h?`- [${g.getChecked()?"x":" "}] `:"- ";f.push(d+h+c(g));e++}return f.join("\n")},ya={dependencies:[E.HeadingNode],export:(a,c)=>{if(!E.$isHeadingNode(a))return null;const b=Number(a.getTag().slice(1));return"#".repeat(b)+" "+c(a)},regExp:W,replace:xa(a=>E.$createHeadingNode("h"+a[1].length)),type:"element"},za={dependencies:[E.QuoteNode],export:(a,c)=>{if(!E.$isQuoteNode(a))return null;a=c(a).split("\n"); | ||
c=[];for(const b of a)c.push("> "+b);return c.join("\n")},regExp:ra,replace:(a,c,b,f)=>{if(f&&(b=a.getPreviousSibling(),E.$isQuoteNode(b))){b.splice(b.getChildrenSize(),0,[n.$createLineBreakNode(),...c]);b.select(0,0);a.remove();return}b=E.$createQuoteNode();b.append(...c);a.replace(b);b.select(0,0)},type:"element"},Aa={dependencies:[F.CodeNode],export:a=>{if(!F.$isCodeNode(a))return null;const c=a.getTextContent();return"```"+(a.getLanguage()||"")+(c?"\n"+c:"")+"\n```"},regExpEnd:{optional:!0,regExp:ta}, | ||
regExpStart:sa,replace:(a,c,b,f,d,e)=>{if(!c&&d){if(1===d.length)f?(c=F.$createCodeNode(),b=b[1]+d[0]):(c=F.$createCodeNode(b[1]),b=d[0].startsWith(" ")?d[0].slice(1):d[0]);else{c=F.$createCodeNode(b[1]);if(0===d[0].trim().length)for(;0<d.length&&!d[0].length;)d.shift();else d[0]=d[0].startsWith(" ")?d[0].slice(1):d[0];for(;0<d.length&&!d[d.length-1].length;)d.pop();b=d.join("\n")}b=n.$createTextNode(b);c.append(b);a.append(c)}else c&&xa(h=>F.$createCodeNode(h?h[1]:void 0))(a,c,b,e)},type:"multiline-element"}, | ||
Ba={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:pa,replace:X("bullet"),type:"element"},Ca={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:qa,replace:X("check"),type:"element"},Da={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:oa,replace:X("number"),type:"element"},Ea={format:["code"],tag:"`",type:"text-format"},Ga={format:["highlight"],tag:"==",type:"text-format"}, | ||
Ha={format:["bold","italic"],tag:"***",type:"text-format"},Ia={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Ja={format:["bold"],tag:"**",type:"text-format"},Ka={format:["bold"],intraword:!1,tag:"__",type:"text-format"},La={format:["strikethrough"],tag:"~~",type:"text-format"},Ma={format:["italic"],tag:"*",type:"text-format"},Na={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Oa={dependencies:[G.LinkNode],export:(a,c,b)=>{if(!G.$isLinkNode(a))return null;c=(c=a.getTitle())? | ||
`[${a.getTextContent()}](${a.getURL()} "${c}")`:`[${a.getTextContent()}](${a.getURL()})`;const f=a.getFirstChild();return 1===a.getChildrenSize()&&n.$isTextNode(f)?b(f,c):c},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(a,c)=>{const [,b,f,d]=c;c=G.$createLinkNode(f,{title:d});const e=n.$createTextNode(b);e.setFormat(a.getFormat());c.append(e);a.replace(c)},trigger:")",type:"text-match"}, | ||
Pa=[ya,za,Ba,Da],Qa=[Aa],Ra=[Ea,Ha,Ia,Ja,Ka,Ga,Ma,Na,La],Sa=[Oa],Z=[...Pa,...Qa,...Ra,...Sa];exports.$convertFromMarkdownString=function(a,c=Z,b,f=!1){if(!f){a=a.split("\n");let d=!1,e=[];for(let h=0;h<a.length;h++){let g=a[h],k=e[e.length-1];ua.test(g)?e.push(g):sa.test(g)||ta.test(g)?(d=!d,e.push(g)):d?e.push(g):""===g||""===k||!k||W.test(k)||W.test(g)||ra.test(g)||oa.test(g)||pa.test(g)||qa.test(g)||va.test(g)||wa.test(g)?e.push(g):e[e.length-1]=k+g}a=e.join("\n")}return ha(c,f)(a,b)}; | ||
exports.$convertToMarkdownString=function(a=Z,c,b=!1){return ca(a,b)(c)};exports.BOLD_ITALIC_STAR=Ha;exports.BOLD_ITALIC_UNDERSCORE=Ia;exports.BOLD_STAR=Ja;exports.BOLD_UNDERSCORE=Ka;exports.CHECK_LIST=Ca;exports.CODE=Aa;exports.ELEMENT_TRANSFORMERS=Pa;exports.HEADING=ya;exports.HIGHLIGHT=Ga;exports.INLINE_CODE=Ea;exports.ITALIC_STAR=Ma;exports.ITALIC_UNDERSCORE=Na;exports.LINK=Oa;exports.MULTILINE_ELEMENT_TRANSFORMERS=Qa;exports.ORDERED_LIST=Da;exports.QUOTE=za;exports.STRIKETHROUGH=La; | ||
exports.TEXT_FORMAT_TRANSFORMERS=Ra;exports.TEXT_MATCH_TRANSFORMERS=Sa;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=Ba; | ||
exports.registerMarkdownShortcuts=function(a,c=Z){let b=I(c),f=H(b.textFormat,({tag:e})=>e[e.length-1]),d=H(b.textMatch,({trigger:e})=>e);for(let e of c)if(c=e.type,"element"===c||"text-match"===c||"multiline-element"===c){c=e.dependencies;for(let h of c)a.hasNode(h)||la(173,h.getType())}return a.registerUpdateListener(({tags:e,dirtyLeaves:h,editorState:g,prevEditorState:k})=>{if(!e.has("collaboration")&&!e.has("historic")&&!a.isComposing()){var t=g.read(n.$getSelection);e=k.read(n.$getSelection); | ||
if(n.$isRangeSelection(e)&&n.$isRangeSelection(t)&&t.isCollapsed()){k=t.anchor.key;var y=t.anchor.offset,w=g._nodeMap.get(k);!n.$isTextNode(w)||!h.has(k)||1!==y&&y>e.anchor.offset+1||a.update(()=>{if(!w.hasFormat("code")){var p=w.getParent();if(null!==p&&!F.$isCodeNode(p)){var r=t.anchor.offset;b:{var l=b.element;var m=p.getParent();if(n.$isRootOrShadowRoot(m)&&p.getFirstChild()===w&&(m=w.getTextContent()," "===m[r-1]))for(let {regExp:v,replace:C}of l)if((l=m.match(v))&&l[0].length===(l[0].endsWith(" ")? | ||
r:r-1)){var q=w.getNextSiblings();let [B,N]=w.splitText(r);B.remove();q=N?[N,...q]:q;if(!1!==C(p,q,l,!1)){m=!0;break b}}m=!1}if(!m){b:{l=b.multilineElement;m=p.getParent();if(n.$isRootOrShadowRoot(m)&&p.getFirstChild()===w&&(m=w.getTextContent()," "===m[r-1]))for(let {regExpStart:v,replace:C,regExpEnd:B}of l)if(!(B&&!("optional"in B)||B&&"optional"in B&&!B.optional)&&(l=m.match(v))&&l[0].length===(l[0].endsWith(" ")?r:r-1)){q=w.getNextSiblings();let [N,Fa]=w.splitText(r);N.remove();q=Fa?[Fa,...q]: | ||
q;if(!1!==C(p,q,l,null,null,!1)){p=!0;break b}}p=!1}if(!p){b:{m=w.getTextContent();p=d[m[r-1]];if(null!=p){r<m.length&&(m=m.slice(0,r));for(z of p)if(p=m.match(z.regExp),null!==p){m=p.index||0;l=m+p[0].length;var u=void 0;0===m?[u]=w.splitText(l):[,u]=w.splitText(m,l);u.selectNext(0,0);z.replace(u,p);var z=!0;break b}}z=!1}if(!z)b:if(l=w.getTextContent(),--r,q=l[r],z=f[q])for(let v of z){var {tag:D}=v;z=D.length;let C=r-z+1;if(!(1<z&&!na(l,C,D,0,z)||" "===l[C-1])&&(u=l[r+1],!1!==v.intraword||!u|| | ||
J.test(u))){p=u=w;m=ma(l,C,D);for(var A=p;0>m&&(A=A.getPreviousSibling())&&!n.$isLineBreakNode(A);)n.$isTextNode(A)&&(m=A.getTextContent(),p=A,m=ma(m,m.length,D));if(!(0>m||p===u&&m+z===C||(D=p.getTextContent(),0<m&&D[m-1]===q||(A=D[m-1],!1===v.intraword&&A&&!J.test(A))))){l=u.getTextContent();l=l.slice(0,C)+l.slice(r+1);u.setTextContent(l);l=p===u?l:D;p.setTextContent(l.slice(0,m)+l.slice(m+z));l=n.$getSelection();q=n.$createRangeSelection();n.$setSelection(q);r=r-z*(p===u?2:1)+1;q.anchor.set(p.__key, | ||
m,"text");q.focus.set(u.__key,r,"text");for(let B of v.format)q.hasFormat(B)||q.formatText(B);q.anchor.set(q.focus.key,q.focus.offset,q.focus.type);for(let B of v.format)q.hasFormat(B)&&q.toggleFormat(B);n.$isRangeSelection(l)&&(q.format=l.format);break b}}}}}}}})}}})} |
@@ -107,1 +107,2 @@ /** | ||
export declare const LINK: TextMatchTransformer; | ||
export declare function normalizeMarkdown(input: string): string; |
@@ -11,13 +11,13 @@ { | ||
"license": "MIT", | ||
"version": "0.17.2-nightly.20240913.0", | ||
"version": "0.17.2-nightly.20240916.0", | ||
"main": "LexicalMarkdown.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/code": "0.17.2-nightly.20240913.0", | ||
"@lexical/link": "0.17.2-nightly.20240913.0", | ||
"@lexical/list": "0.17.2-nightly.20240913.0", | ||
"@lexical/rich-text": "0.17.2-nightly.20240913.0", | ||
"@lexical/text": "0.17.2-nightly.20240913.0", | ||
"@lexical/utils": "0.17.2-nightly.20240913.0", | ||
"lexical": "0.17.2-nightly.20240913.0" | ||
"@lexical/code": "0.17.2-nightly.20240916.0", | ||
"@lexical/link": "0.17.2-nightly.20240916.0", | ||
"@lexical/list": "0.17.2-nightly.20240916.0", | ||
"@lexical/rich-text": "0.17.2-nightly.20240916.0", | ||
"@lexical/text": "0.17.2-nightly.20240916.0", | ||
"@lexical/utils": "0.17.2-nightly.20240916.0", | ||
"lexical": "0.17.2-nightly.20240916.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
147230
2770
+ Added@lexical/clipboard@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/code@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/html@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/link@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/list@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/rich-text@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/selection@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/table@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/text@0.17.2-nightly.20240916.0(transitive)
+ Added@lexical/utils@0.17.2-nightly.20240916.0(transitive)
+ Addedlexical@0.17.2-nightly.20240916.0(transitive)
- Removed@lexical/clipboard@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/code@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/html@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/link@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/list@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/rich-text@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/selection@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/table@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/text@0.17.2-nightly.20240913.0(transitive)
- Removed@lexical/utils@0.17.2-nightly.20240913.0(transitive)
- Removedlexical@0.17.2-nightly.20240913.0(transitive)