@lexical/markdown 0.44.1-nightly.20260519.0 → 0.45.1-dev.0
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 → dist/LexicalMarkdown.dev.js} +1 -1
- package/{LexicalMarkdown.dev.mjs → dist/LexicalMarkdown.dev.mjs} +1 -1
- package/dist/LexicalMarkdown.prod.js +9 -0
- package/dist/LexicalMarkdown.prod.mjs +9 -0
- package/package.json +37 -22
- package/src/MarkdownExport.ts +627 -0
- package/src/MarkdownImport.ts +363 -0
- package/src/MarkdownShortcuts.ts +677 -0
- package/src/MarkdownTransformers.ts +962 -0
- package/src/importTextFormatTransformer.ts +389 -0
- package/src/importTextMatchTransformer.ts +110 -0
- package/src/importTextTransformers.ts +141 -0
- package/src/index.ts +138 -0
- package/src/utils.ts +472 -0
- package/LexicalMarkdown.prod.js +0 -9
- package/LexicalMarkdown.prod.mjs +0 -9
- /package/{LexicalMarkdown.js → dist/LexicalMarkdown.js} +0 -0
- /package/{LexicalMarkdown.js.flow → dist/LexicalMarkdown.js.flow} +0 -0
- /package/{LexicalMarkdown.mjs → dist/LexicalMarkdown.mjs} +0 -0
- /package/{LexicalMarkdown.node.mjs → dist/LexicalMarkdown.node.mjs} +0 -0
- /package/{MarkdownExport.d.ts → dist/MarkdownExport.d.ts} +0 -0
- /package/{MarkdownImport.d.ts → dist/MarkdownImport.d.ts} +0 -0
- /package/{MarkdownShortcuts.d.ts → dist/MarkdownShortcuts.d.ts} +0 -0
- /package/{MarkdownTransformers.d.ts → dist/MarkdownTransformers.d.ts} +0 -0
- /package/{importTextFormatTransformer.d.ts → dist/importTextFormatTransformer.d.ts} +0 -0
- /package/{importTextMatchTransformer.d.ts → dist/importTextMatchTransformer.d.ts} +0 -0
- /package/{importTextTransformers.d.ts → dist/importTextTransformers.d.ts} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{utils.d.ts → dist/utils.d.ts} +0 -0
package/LexicalMarkdown.prod.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import{$isParagraphNode as t,$isTextNode as e,createState as n,$setState as o,$createTextNode as r,$getState as i,$findMatchingParent as s,$createLineBreakNode as l,$isLineBreakNode as c,$getRoot as a,$isElementNode as f,$isDecoratorNode as u,$getSelection as d,$createParagraphNode as g,$createTabNode as p,mergeRegister as h,COLLABORATION_TAG as x,HISTORIC_TAG as m,COMPOSITION_END_TAG as C,$isRangeSelection as T,$addUpdateTag as E,HISTORY_PUSH_TAG as $,KEY_ENTER_COMMAND as v,COMMAND_PRIORITY_LOW as I,$isRootOrShadowRoot as y,$createRangeSelection as S,$setSelection as b}from"lexical";import{$sliceSelectedTextNodeContent as w}from"@lexical/selection";import{CodeNode as k,$createCodeNode as N,$isCodeNode as F}from"@lexical/code-core";import{LinkNode as L,$isLinkNode as O,$createLinkNode as M,$isAutoLinkNode as R}from"@lexical/link";import{ListNode as B,ListItemNode as _,$isListNode as j,$createListItemNode as A,$createListNode as P,$isListItemNode as z}from"@lexical/list";import{HeadingNode as W,QuoteNode as U,$isHeadingNode as D,$isQuoteNode as H,$createQuoteNode as K,$createHeadingNode as q}from"@lexical/rich-text";import{$findMatchingParent as G}from"@lexical/utils";function J(t,e){const n={};for(const o of t){const t=e(o);t&&(n[t]?n[t].push(o):n[t]=[o])}return n}function Q(t){const e=J(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const V=/[!-/:-@[-`{-~\s]/,X=/[ \t\n\r\f]/,Y=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,Z=/^\s{0,3}$/;function tt(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&Z.test(o.getTextContent())}function et(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}const nt=/^(\s*)(\d{1,})\.\s/,ot=/^(\s*)[-*+]\s/,rt=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,it=/^(#{1,6})\s/,st=/^>\s/,lt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,ct=/^[ \t]*`{3,}$/,at=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,ft=/^(?:\|)(.+)(?:\|)\s?$/,ut=/^(\| ?:?-*:? ?)+\|\s?$/,dt=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,gt=/^<\/[a-z_][\w-]*\s*>/i,pt=t=>new RegExp(`(?:${t.source})$`,t.flags),ht=n("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),xt=n("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),mt=n("mdHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0});function Ct(t){if(t.endsWith("\\"))return[t.slice(0,-1),"\\"];const e=t.match(/^(.*?\S)( {2,})$/);return e?[e[1],e[2]]:null}function Tt(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e(r))return null;const i=r.getTextContent(),s=Ct(i);if(null!==s){const[t,e]=s;return r.setTextContent(t),e}return/^ {2,}$/.test(i)&&function(t,e){for(let n=e-1;n>=0;n--){if(c(t[n]))return!1;if(/\S/.test(t[n].getTextContent()))return!0}return!1}(n,o)?(r.setTextContent(""),i):null}function Et(t){const e=l(),n=Tt(t);return null!==n&&o(e,mt,n),e}const $t=t=>(e,n,o,r)=>{const i=t(o);i.append(...n),e.replace(i),r||i.select(0,0)};const vt=t=>(e,n,r,i)=>{const s=e.getPreviousSibling(),l=e.getNextSibling(),c=A("check"===t?"x"===r[3]:void 0),a=r[0].trim()[0],f="bullet"!==t&&"check"!==t||a!==ht.parse(a)?void 0:a;if(j(l)&&l.getListType()===t){f&&o(l,ht,f);const t=l.getFirstChild();null!==t?t.insertBefore(c):l.append(c),e.remove()}else if(j(s)&&s.getListType()===t)f&&o(s,ht,f),s.append(c),e.remove();else{const n=P(t,"number"===t?Number(r[2]):void 0);f&&o(n,ht,f),n.append(c),e.replace(n)}c.append(...n),i||c.select(0,0);const u=function(t){const e=t.match(/\t/g),n=t.match(/ /g);let o=0;return e&&(o+=e.length),n&&(o+=Math.floor(n.length/4)),o}(r[1]);u&&c.setIndent(u)},It=(t,e,n,o)=>{const r=[],s=t.getChildren();let l=0;for(const c of s)if(z(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(j(t)){const i=It(t,e,n+1,o);i&&r.push(i);continue}}if(o&&!c.getChildren().some(t=>t.isSelected(o)))continue;const s=" ".repeat(4*n),a=t.getListType(),f=i(t,ht),u="number"===a?`${t.getStart()+l}. `:"check"===a?`${f} [${c.getChecked()?"x":" "}] `:f+" ";let d=e(c);"number"!==a&&(d=d.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),r.push(s+u+d),l++}return r.join("\n")},yt={dependencies:[W],export:(t,e)=>{if(!D(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:it,replace:$t(t=>{const e="h"+t[1].length;return q(e)}),triggerOnEnter:!0,type:"element"},St={dependencies:[U],export:(t,e)=>{if(!H(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:st,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(H(n))return n.splice(n.getChildrenSize(),0,[Et(n),...e]),void t.remove()}const r=K();r.append(...e),t.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},bt={dependencies:[k],export:t=>{if(!F(t))return null;const e=t.getTextContent();let n=i(t,xt);if(e.indexOf(n)>-1){const t=e.match(/`{3,}/g);if(t){const e=Math.max(...t.map(t=>t.length));n="`".repeat(e+1)}}return n+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n"+n},handleImportAfterStartMatch:({lines:t,rootNode:e,startLineIndex:n,startMatch:o})=>{const r=o[1],i=r.trim().length,s=t[n],l=o.index+r.length,c=s.slice(l),a=new RegExp(`\`{${i},}$`);if(a.test(c)){const t=c.match(a),r=c.slice(0,c.lastIndexOf(t[0])),i=[...o];return i[2]="",bt.replace(e,null,i,t,[r],!0),[!0,n]}const f=new RegExp(`^[ \\t]*\`{${i},}$`);for(let r=n+1;r<t.length;r++){const i=t[r];if(f.test(i)){const l=i.match(f),c=t.slice(n+1,r),a=s.slice(o[0].length);return a.length>0&&c.unshift(a),bt.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),d=s.slice(o[0].length);return d.length>0&&u.unshift(d),bt.replace(e,null,o,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:ct},regExpStart:lt,replace:(t,e,n,i,s,l)=>{let c,a;const f=n[1]?n[1].trim():"```",u=n[2]||void 0;if(!e&&s){if(1===s.length)i?(c=N(u),a=s[0]):(c=N(u),a=s[0].startsWith(" ")?s[0].slice(1):s[0]);else{for(c=N(u),s.length>0&&(0===s[0].trim().length?s.shift():s[0].startsWith(" ")&&(s[0]=s[0].slice(1)));s.length>0&&!s[s.length-1].length;)s.pop();a=s.join("\n")}o(c,xt,f);const e=r(a);c.append(e),t.append(c)}else e&&$t(t=>N(t?t[2]:void 0))(t,e,n,l)},type:"multiline-element"},wt={dependencies:[B,_],export:(t,e,n)=>j(t)?It(t,e,0,n):null,regExp:ot,replace:vt("bullet"),triggerOnEnter:!0,type:"element"},kt={dependencies:[B,_],export:(t,e,n)=>j(t)?It(t,e,0,n):null,regExp:rt,replace:vt("check"),triggerOnEnter:!0,type:"element"},Nt={dependencies:[B,_],export:(t,e,n)=>j(t)?It(t,e,0,n):null,regExp:nt,replace:vt("number"),triggerOnEnter:!0,type:"element"},Ft={format:["code"],tag:"`",type:"text-format"},Lt={format:["highlight"],tag:"==",type:"text-format"},Ot={format:["bold","italic"],tag:"***",type:"text-format"},Mt={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Rt={format:["bold"],tag:"**",type:"text-format"},Bt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},_t={format:["strikethrough"],tag:"~~",type:"text-format"},jt={format:["italic"],tag:"*",type:"text-format"},At={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Pt={dependencies:[L],export:(t,e,n)=>{if(!O(t)||R(t))return null;const o=e(t);let r=t.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${t.getURL()} "${r}")`:`[${o}](${t.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,e)=>{if(s(t,O))return;const[,n,o,i]=e,l=null!=o?et(o):void 0,c=null!=i?et(i):void 0,a=M(l,{title:c}),f=n.split("[").length-1,u=n.split("]").length-1;let d=n,g="";if(f<u)return;if(f>u){const t=n.split("[");g="["+t[0],d=t.slice(1).join("[")}const p=r(d);return p.setFormat(t.getFormat()),a.append(p),t.replace(a),g&&a.insertBefore(r(g)),p},trigger:")",type:"text-match"},zt=[yt,St,wt,Nt],Wt=[bt],Ut=[Ft,Ot,Mt,Rt,Bt,Lt,jt,At,_t],Dt=[Pt],Ht=[...zt,...Wt,...Ut,...Dt];function Kt(t,e,n,o,r,i){let s=t.isSelected(e);for(const l of n){if(!l.export)continue;const n=l.export(t,t=>qt(t,e,o,r,i).markdown,e);if(null!=n){if(!s&&f(t)){qt(t,e,o,r,i).shouldInclude&&(s=!0)}return{markdown:n,shouldInclude:s}}}if(f(t)){const n=qt(t,e,o,r,i);return{markdown:n.markdown,shouldInclude:s||n.shouldInclude}}return u(t)?{markdown:t.getTextContent(),shouldInclude:s}:{markdown:null,shouldInclude:s}}function qt(t,n,o,r,i,s,l){const a=[],d=t.getChildren();let g=!1;s||(s=[]),l||(l=[]);t:for(const t of d){let d=t.isSelected(n);for(const e of r){if(!e.export)continue;const c=e.export(t,t=>qt(t,n,o,r,i,s,[...l,...s]).markdown,(t,e)=>Vt(t,w(n,t,"clone").getTextContent(),o,s,l,i));if(null!=c){!d&&f(t)&&t.getChildren().some(t=>t.isSelected(n))&&t.extractWithChild(t,n,"html")&&(d=!0),d&&(a.push(c),g=!0);continue t}}if(c(t))d&&(a.push(Qt(t)),g=!0);else if(e(t)){if(d){const e=w(n,t,"clone");a.push(Vt(t,e.getTextContent(),o,s,l,i)),g=!0}}else if(f(t)){const e=qt(t,n,o,r,i,s,l);!d&&e.shouldInclude&&t.extractWithChild(t,n,"html")&&(d=!0),(d||e.shouldInclude)&&(a.push(e.markdown),g=!0)}else u(t)&&d&&(a.push(t.getTextContent()),g=!0)}return{markdown:a.join(""),shouldInclude:g}}function Gt(t,e,n,o,r){for(const i of e){if(!i.export)continue;const e=i.export(t,t=>Jt(t,n,o,void 0,void 0,r));if(null!=e)return e}return f(t)?Jt(t,n,o,void 0,void 0,r):u(t)?t.getTextContent():null}function Jt(t,n,o,r,i,s=!1){const l=[],a=t.getChildren();r||(r=[]),i||(i=[]);t:for(const t of a){for(const e of o){if(!e.export)continue;const c=e.export(t,t=>Jt(t,n,o,r,[...i,...r],s),(t,e)=>Vt(t,e,n,r,i,s));if(null!=c){l.push(c);continue t}}c(t)?l.push(Qt(t)):e(t)?l.push(Vt(t,t.getTextContent(),n,r,i,s)):f(t)?l.push(Jt(t,n,o,r,i,s)):u(t)&&l.push(t.getTextContent())}return l.join("")}function Qt(t){return i(t,mt)+"\n"}function Vt(t,e,n,o,r,i=!1){let s=e;t.hasFormat("code")||(s=i?s.replace(/([*_`~])/g,"\\$1"):s.replace(/([*_`~\\])/g,"\\$1"));const l=s.match(/^(\s*)(.*?)(\s*)$/s)||["","",s,""],c=l[1],a=l[2],f=l[3],u=""===a;let d="",g="",p="";const h=Xt(t,!0),x=Xt(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;Zt(t,n)&&!m.has(n)&&(m.add(n),Zt(h,n)&&o.find(t=>t.tag===r)||(o.push({format:n,tag:r}),d+=r))}for(let e=0;e<o.length;e++){const n=Yt(t,o[e].format),i=Yt(x,o[e].format);if(n&&i)continue;const s=[...o];for(;s.length>e;){const t=s.pop();r&&t&&r.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?i||(p+=t.tag):g+=t.tag),o.pop())}break}return u&&!t.hasFormat("code")?g+s:g+c+d+a+p+f}function Xt(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function Yt(t,n){return e(t)&&t.hasFormat(n)}function Zt(t,e){return!!Yt(t,e)&&("code"===e||(!t||!/^\s*$/.test(t.getTextContent())))}function te(t,e){const n=t.getTextContent(),o=e.fullMatchRegExpByTag["`"],r=e.transformersByTag["`"],i=[];let s=null;if(o&&r){const t=new RegExp(o.source,"g"),e=Array.from(n.matchAll(t));for(const t of e){const e=t.index+t[1].length,n=t.index+t[0].length;s||(s={content:t[3],endIndex:n,startIndex:e,tag:"`"}),i.push({end:n,start:e})}}const l=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),i=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},s=t=>n.some(e=>t>=e.start&&t<e.end);let l=0;for(;l<t.length;){const e=t[l];if(!r.has(e)||i(l)||s(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=ee(e,t,l,n,!0),a=ee(e,t,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,i),c=l.length>0?function(t,e,n){const o={};let r=0,i=null;for(;r<e.length;){const s=e[r];if(!s.active||!s.canClose||0===s.length){r++;continue}const l=`${s.char}${s.canOpen}`,c=o[l]??-1;let a=!1;for(let o=r-1;o>c;o--){const l=e[o];if(!l.active||!l.canOpen||0===l.length||l.char!==s.char)continue;if(l.canClose||s.canOpen){if((l.originalLength+s.originalLength)%3==0&&l.originalLength%3!=0&&s.originalLength%3!=0)continue}const c=Math.min(l.length,s.length),f=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!f)continue;a=!0;const u=f.length,d={content:t.slice(l.index+l.length,s.index),endIndex:s.index+u,startIndex:l.index+(l.length-u),tag:f};(!i||d.startIndex<i.startIndex||d.startIndex===i.startIndex&&d.endIndex>i.endIndex)&&(i=d);for(let t=o+1;t<r;t++)e[t].active=!1;l.length-=u,s.length-=u,l.active=l.length>0,s.length>0?s.index+=u:(s.active=!1,r++);break}a||(o[l]=r-1,s.canOpen||(s.active=!1),r++)}return i}(n,l,e):null;let a=null,f=null;if(s&&c?c.startIndex<=s.startIndex&&c.endIndex>=s.endIndex?(a=c,f=e.transformersByTag[c.tag]):(a=s,f=r):s?(a=s,f=r):c&&(a=c,f=e.transformersByTag[c.tag]),!a||!f)return null;const u=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return u.index=a.startIndex,u.input=n,{endIndex:a.endIndex,match:u,startIndex:a.startIndex,transformer:f}}function ee(t,e,n,o,r){if(!ne(e,n,o,r))return!1;if("*"===t)return!0;if("_"===t){if(!ne(e,n,o,!r))return!0;const t=r?e[n-1]:e[n+o];return void 0!==t&&Y.test(t)}return!0}function ne(t,e,n,o){const r=t[e-1],i=t[e+n],[s,l]=o?[i,r]:[r,i];return void 0!==s&&!X.test(s)&&(!Y.test(s)||(void 0===l||X.test(l)||Y.test(l)))}function oe(t){return e(t)&&!t.hasFormat("code")}function re(t,e,n){let o=te(t,e),r=function(t,e){const n=t;let o,r,i,s;for(const t of e){if(!t.replace||!t.importRegExp)continue;const e=n.getTextContent().match(t.importRegExp);if(!e)continue;const l=e.index||0,c=t.getEndIndex?t.getEndIndex(n,e):l+e[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&(c>r||c<=o))&&(o=l,r=c,i=t,s=e)}return void 0===o||void 0===r||void 0===i||void 0===s?null:{endIndex:r,match:s,startIndex:o,transformer:i}}(t,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(t,e,n,o,r){const i=t.getTextContent();let s,l,c;if(r[0]===i?s=t:0===e?[s,l]=t.splitText(n):[c,s,l]=t.splitText(e,n),s.setTextContent(r[2]),o)for(const t of o.format)s.hasFormat(t)||s.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:s}}(t,o.startIndex,o.endIndex,o.transformer,o.match);oe(r.nodeAfter)&&re(r.nodeAfter,e,n),oe(r.nodeBefore)&&re(r.nodeBefore,e,n),oe(r.transformedNode)&&re(r.transformedNode,e,n)}else if(r){const o=function(t,e,n,o,r){let i,s,l;return 0===e?[i,s]=t.splitText(n):[l,i,s]=t.splitText(e,n),o.replace?{nodeAfter:s,nodeBefore:l,transformedNode:o.replace(i,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;oe(o.nodeAfter)&&re(o.nodeAfter,e,n),oe(o.nodeBefore)&&re(o.nodeBefore,e,n),oe(o.transformedNode)&&re(o.transformedNode,e,n)}const i=et(t.getTextContent());t.setTextContent(i)}function ie(t,e=!1){const n=Q(t),o=function(t){const e={},n={},o=[];for(const r of t){const{tag:t}=r;e[t]=r;const i=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(i),1===t.length?n[t]="`"===t?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)(${i})(?![\\\\${i}])`):n[t]=new RegExp(`(^|[^\\\\])(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:e}}(n.textFormat);return(t,r)=>{const i=t.split("\n"),s=i.length,l=r||a();l.clear();for(let t=0;t<s;t++){const r=i[t],[s,c]=se(i,t,n.multilineElement,l);s?t=c:le(r,l,n.element,o,n.textMatch,e)}const c=l.getChildren();for(const t of c)if(!e&&tt(t)&&l.getChildrenSize()>1)t.remove();else if(f(t))for(const e of t.getAllTextNodes())ce(e);null!==d()&&l.selectStart()}}function se(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:i,regExpStart:s,replace:l}=r,c=t[e].match(s);if(!c)continue;if(n){const i=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===i)continue;if(i)return i}const a="object"==typeof i&&"regExp"in i?i.regExp:i,f=i&&"object"==typeof i&&"optional"in i?i.optional:!i;let u=e;const d=t.length;for(;u<d;){const n=a?t[u].match(a):null;if(!n&&(!f||f&&u<d-1)){u++;continue}if(n&&e===u&&n.index===c.index){u++;continue}const r=[];if(n&&e===u)r.push(t[e].slice(c[0].length,-n[0].length));else for(let o=e;o<=u;o++)if(o===e){const e=t[o].slice(c[0].length);r.push(e)}else if(o===u&&n){const e=t[o].slice(0,-n[0].length);r.push(e)}else r.push(t[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,u];break}}return[!1,e]}function le(e,n,o,i,s,l){const c=r(e),a=g();a.append(c),n.append(a);for(const{regExp:t,replace:n}of o){const o=e.match(t);if(o&&(c.setTextContent(e.slice(o[0].length)),!1!==n(a,[c],o,!0)))break}if(re(c,i,s),a.isAttached()&&e.length>0){const e=a.getPreviousSibling();if(!l&&(t(e)||H(e)||j(e))){let t=e;if(j(e)){const n=e.getLastDescendant();t=null==n?null:G(n,z)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[Et(t),...a.getChildren()]),a.remove())}}}function ce(t){const e=new Set,n=t.getTextContent();let o=n.indexOf("\t");for(;-1!==o;)e.add(o),e.add(o+1),o=n.indexOf("\t",o+1);t.splitText(...e).forEach(t=>{"\t"===t.getTextContent()&&t.replace(p())})}function ae(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function fe(t,e,n,o,r){const i=t.getParent();if(!y(i)||t.getFirstChild()!==e)return!1;const s=e.getTextContent();if(!r&&" "!==s[n-1])return!1;for(const{regExp:i,replace:l}of o){const o=s.match(i),c=r||o&&o[0].endsWith(" ")?n:n-1;if(o&&o[0].length===c){const r=e.getNextSiblings(),[i,s]=e.splitText(n);if(!1!==l(t,s?[s,...r]:r,o,!1))return i.remove(),!0}}return!1}function ue(t,e,n,o,r){const i=t.getParent();if(!y(i)||t.getFirstChild()!==e)return!1;const s=e.getTextContent();if(!r&&" "!==s[n-1])return!1;for(const{regExpStart:i,replace:l,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=s.match(i);if(o){const i=r||o[0].endsWith(" ")?n:n-1;if(o[0].length!==i)continue;const s=e.getNextSiblings(),[c,a]=e.splitText(n);if(!1!==l(t,a?[a,...s]:s,o,null,null,!1))return c.remove(),!0}}return!1}function de(t,e){let n=0;const o=t.getTextContent();for(let t=0;t<e;t++)"`"===o[t]&&n++;return n%2!=0}function ge(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(pe(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function pe(t,e,n,o,r){for(let i=0;i<r;i++)if(t[e+i]!==n[o+i])return!1;return!0}function he(t,n=Ht){const o=Q(n),r=o.element.filter(t=>t.triggerOnEnter),i=J(o.textFormat,({tag:t})=>t[t.length-1]),s=J(o.textMatch,({trigger:t})=>t),l=new Set([" "]);for(const t of o.textFormat)l.add(t.tag.slice(-1));for(const t of o.textMatch)void 0!==t.trigger&&l.add(t.trigger);for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||ae(173,e.getType())}}const a=(t,n,r)=>!!fe(t,n,r,o.element)||(!!ue(t,n,r,o.multilineElement)||(!!function(t,e,n){let o=t.getTextContent();const r=n[o[e-1]];if(null==r)return!1;e<o.length&&(o=o.slice(0,e));for(const e of r){if(!e.replace||!e.regExp)continue;const n=o.match(e.regExp);if(null===n)continue;const r=n.index||0,i=r+n[0].length;let s;return 0===r?[s]=t.splitText(i):[,s]=t.splitText(r,i),s.selectNext(0,0),e.replace(s,n),!0}return!1}(n,r,s)||!!function(t,n,o){const r=t.getTextContent(),i=n-1,s=r[i],l=o[s];if(!l)return!1;for(const n of l){const{tag:o}=n,l=o.length,a=i-l+1;if(l>1&&!pe(r,a,o,0,l))continue;if(" "===r[a-1])continue;const f=r[i+1];if(!1===n.intraword&&f&&!V.test(f))continue;const u=t;let g=u,p=ge(r,a,o),h=g;for(;p<0&&(h=h.getPreviousSibling())&&!c(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();g=h,p=ge(t,t.length,o)}if(p<0)continue;if(g===u&&p+l===a)continue;const x=g.getTextContent();if(p>0&&x[p-1]===s)continue;const m=x[p-1];if(!1===n.intraword&&m&&!V.test(m))continue;if(!n.format.includes("code")&&de(g,p))continue;const C=u.getTextContent(),E=C.slice(0,a)+C.slice(i+1);u.setTextContent(E);const $=g===u?E:x;g.setTextContent($.slice(0,p)+$.slice(p+l));const v=d(),I=S();b(I);const y=i-l*(g===u?2:1)+1;I.anchor.set(g.__key,p,"text"),I.focus.set(u.__key,y,"text");for(const t of n.format)I.hasFormat(t)||I.formatText(t);I.anchor.set(I.focus.key,I.focus.offset,I.focus.type);for(const t of n.format)I.hasFormat(t)&&I.toggleFormat(t);return T(v)&&(I.format=v.format),!0}return!1}(n,r,i)));return h(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:i})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const s=n.has(C),c=r.read(d),f=i.read(d);if(!T(f)||!T(c)||!c.isCollapsed()||c.is(f)&&!s)return;const u=c.anchor.key,g=c.anchor.offset,p=r._nodeMap.get(u);if(e(p)&&o.has(u)&&(s||1===g||!(g>f.anchor.offset+1))){if(s){const t=r.read(()=>p.getTextContent())[g-1];if(!l.has(t))return}t.update(()=>{if(!oe(p))return;const t=p.getParent();null===t||F(t)||a(t,p,c.anchor.offset)&&E($)})}}),t.registerCommand(v,t=>{if(null!==t&&t.shiftKey)return!1;const n=d();if(!T(n)||!n.isCollapsed())return!1;const i=n.anchor.offset,s=n.anchor.getNode();if(!e(s)||!oe(s))return!1;const l=s.getParent();if(null===l||F(l))return!1;return i===s.getTextContent().length&&(!(!ue(l,s,i,o.multilineElement,!0)&&!fe(l,s,i,r,!0))&&(null!==t&&t.preventDefault(),!0))},I))}function xe(t,e=Ht,n,o=!1,r=!1){const i=o?t:function(t,e=!1){const n=t.split("\n");let o=!1;const r=[];for(let t=0;t<n.length;t++){const i=n[t],s=i.trimEnd(),l=r[r.length-1],c=t<n.length-1?Ct(i):null,a=void 0!==l&&null!==Ct(l);at.test(s)?r.push(s):lt.test(s)||ct.test(s)?(o=!o,r.push(s)):o?r.push(i):""===s||""===l||!l||it.test(l)||it.test(s)||st.test(s)||nt.test(s)||ot.test(s)||rt.test(s)||ft.test(s)||ut.test(s)||a||!e||dt.test(s)||gt.test(s)||pt(gt).test(l)||pt(dt).test(l)||ct.test(l)?r.push(!e&&""!==s||null!==c?i:s):r[r.length-1]=l+" "+(null===c?s:i).trimStart()}return r.join("\n")}(t,r);return ie(e,o)(i,n)}function me(t=Ht,e,n=!1){const o=function(t,e=!1){const n=Q(t),o=[...n.multilineElement,...n.element],r=!e,i=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const s=[],l=(t||a()).getChildren();for(let t=0;t<l.length;t++){const c=l[t],a=Gt(c,o,i,n.textMatch,e);null!=a&&s.push(r&&t>0&&!tt(c)&&!tt(l[t-1])?"\n".concat(a):a)}return s.join("\n")}}(t,n);return o(e)}function Ce(t=Ht,e,n=!1){if(!e||T(e)&&e.isCollapsed())return"";const o=function(t,e=!1){const n=Q(t),o=[...n.multilineElement,...n.element],r=!e,i=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const s=[],l=a().getChildren();for(let c=0;c<l.length;c++){const a=l[c],{shouldInclude:f,markdown:u}=Kt(a,t,o,i,n.textMatch,e);f&&null!=u&&s.push(r&&c>0&&!tt(a)&&!tt(l[c-1])?"\n".concat(u):u)}return s.join("\n")}}(t,n);return o(e)}export{xe as $convertFromMarkdownString,Ce as $convertSelectionToMarkdownString,me as $convertToMarkdownString,Ot as BOLD_ITALIC_STAR,Mt as BOLD_ITALIC_UNDERSCORE,Rt as BOLD_STAR,Bt as BOLD_UNDERSCORE,kt as CHECK_LIST,bt as CODE,zt as ELEMENT_TRANSFORMERS,yt as HEADING,Lt as HIGHLIGHT,Ft as INLINE_CODE,jt as ITALIC_STAR,At as ITALIC_UNDERSCORE,Pt as LINK,Wt as MULTILINE_ELEMENT_TRANSFORMERS,Nt as ORDERED_LIST,St as QUOTE,_t as STRIKETHROUGH,Ut as TEXT_FORMAT_TRANSFORMERS,Dt as TEXT_MATCH_TRANSFORMERS,Ht as TRANSFORMERS,wt as UNORDERED_LIST,he as registerMarkdownShortcuts};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|