@lexical/markdown 0.46.0 → 0.46.1-nightly.20260629.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.
|
@@ -622,7 +622,7 @@ const TEXT_MATCH_TRANSFORMERS = [LINK];
|
|
|
622
622
|
const TRANSFORMERS = [...ELEMENT_TRANSFORMERS, ...MULTILINE_ELEMENT_TRANSFORMERS, ...TEXT_FORMAT_TRANSFORMERS, ...TEXT_MATCH_TRANSFORMERS];
|
|
623
623
|
function normalizeMarkdown(input, shouldMergeAdjacentLines = false) {
|
|
624
624
|
const lines = input.split('\n');
|
|
625
|
-
let
|
|
625
|
+
let codeBlockFenceLength = 0;
|
|
626
626
|
const sanitizedLines = [];
|
|
627
627
|
for (let i = 0; i < lines.length; i++) {
|
|
628
628
|
const rawLine = lines[i];
|
|
@@ -636,16 +636,24 @@ function normalizeMarkdown(input, shouldMergeAdjacentLines = false) {
|
|
|
636
636
|
sanitizedLines.push(line);
|
|
637
637
|
continue;
|
|
638
638
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
639
|
+
if (codeBlockFenceLength === 0) {
|
|
640
|
+
// An opening fence may carry an info string (e.g. ```ts)
|
|
641
|
+
const openMatch = line.match(CODE_START_REGEX);
|
|
642
|
+
if (openMatch) {
|
|
643
|
+
codeBlockFenceLength = openMatch[1].trim().length;
|
|
644
|
+
sanitizedLines.push(line);
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
} else {
|
|
648
|
+
// A code block is closed only by a bare fence (no info string) that is at
|
|
649
|
+
// least as long as the opening fence. Fence-like lines that carry an info
|
|
650
|
+
// string (e.g. a nested ```ts) are part of the code block's content.
|
|
651
|
+
if (CODE_END_REGEX.test(line) && line.trim().length >= codeBlockFenceLength) {
|
|
652
|
+
codeBlockFenceLength = 0;
|
|
653
|
+
sanitizedLines.push(line);
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
// Inside a code block, keep the line unchanged
|
|
649
657
|
sanitizedLines.push(rawLine);
|
|
650
658
|
continue;
|
|
651
659
|
}
|
|
@@ -620,7 +620,7 @@ const TEXT_MATCH_TRANSFORMERS = [LINK];
|
|
|
620
620
|
const TRANSFORMERS = [...ELEMENT_TRANSFORMERS, ...MULTILINE_ELEMENT_TRANSFORMERS, ...TEXT_FORMAT_TRANSFORMERS, ...TEXT_MATCH_TRANSFORMERS];
|
|
621
621
|
function normalizeMarkdown(input, shouldMergeAdjacentLines = false) {
|
|
622
622
|
const lines = input.split('\n');
|
|
623
|
-
let
|
|
623
|
+
let codeBlockFenceLength = 0;
|
|
624
624
|
const sanitizedLines = [];
|
|
625
625
|
for (let i = 0; i < lines.length; i++) {
|
|
626
626
|
const rawLine = lines[i];
|
|
@@ -634,16 +634,24 @@ function normalizeMarkdown(input, shouldMergeAdjacentLines = false) {
|
|
|
634
634
|
sanitizedLines.push(line);
|
|
635
635
|
continue;
|
|
636
636
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
637
|
+
if (codeBlockFenceLength === 0) {
|
|
638
|
+
// An opening fence may carry an info string (e.g. ```ts)
|
|
639
|
+
const openMatch = line.match(CODE_START_REGEX);
|
|
640
|
+
if (openMatch) {
|
|
641
|
+
codeBlockFenceLength = openMatch[1].trim().length;
|
|
642
|
+
sanitizedLines.push(line);
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
} else {
|
|
646
|
+
// A code block is closed only by a bare fence (no info string) that is at
|
|
647
|
+
// least as long as the opening fence. Fence-like lines that carry an info
|
|
648
|
+
// string (e.g. a nested ```ts) are part of the code block's content.
|
|
649
|
+
if (CODE_END_REGEX.test(line) && line.trim().length >= codeBlockFenceLength) {
|
|
650
|
+
codeBlockFenceLength = 0;
|
|
651
|
+
sanitizedLines.push(line);
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
// Inside a code block, keep the line unchanged
|
|
647
655
|
sanitizedLines.push(rawLine);
|
|
648
656
|
continue;
|
|
649
657
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/selection"),n=require("@lexical/code-core"),o=require("@lexical/link"),r=require("@lexical/list"),s=require("@lexical/rich-text");function i(e,t){const n={};for(const o of e){const e=t(o);e&&(n[e]?n[e].push(o):n[e]=[o])}return n}function l(e){const t=i(e,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}const c=/[!-/:-@[-`{-~\s]/,a=/\s/,d=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,f=/^\s{0,3}$/;function u(t){if(!e.$isParagraphNode(t))return!1;const n=t.getFirstChild();return null==n||1===t.getChildrenSize()&&e.$isTextNode(n)&&f.test(n.getTextContent())}function g(e){return e.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}const p=/^(\s*)(\d{1,})\.\s/,h=/^(\s*)[-*+]\s/,x=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,m=/^(#{1,6})\s/,$=/^>\s/,T=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,N=/^[ \t]*`{3,}$/,C=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,S=/^(?:\|)(.+)(?:\|)\s?$/;function E(e){if("|"!==e[0])return!1;const{length:t}=e;let n=1,o=0;for(;n<t;){let t=n;for(" "===e[t]&&t++,":"===e[t]&&t++;"-"===e[t];)t++;if(":"===e[t]&&t++," "===e[t]&&t++,"|"!==e[t])break;o++,n=t+1}return o>0&&(n===t||n===t-1&&/\s/.test(e[n]))}const I=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,L=/^<\/[a-z_][\w-]*\s*>/i,R=e=>new RegExp(`(?:${e.source})$`,e.flags),v=/* @__PURE__ */e.createState("mdListMarker",{parse:e=>"string"==typeof e&&/^[-*+]$/.test(e)?e:"-",resetOnCopyNode:!0}),O=/* @__PURE__ */e.createState("mdCodeFence",{parse:e=>"string"==typeof e&&/^`{3,}$/.test(e)?e:"```",resetOnCopyNode:!0}),_=/* @__PURE__ */e.createState("mdHardLineBreak",{parse:e=>"string"==typeof e&&/^(\\| {2,})$/.test(e)?e:"",resetOnCopyNode:!0});function y(e){if(e.endsWith("\\"))return[e.slice(0,-1),"\\"];const t=e.match(/^(.*?\S)( {2,})$/);return t?[t[1],t[2]]:null}function k(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e.$isTextNode(r))return null;const s=r.getTextContent(),i=y(s);if(null!==i){const[e,t]=i;return r.setTextContent(e),t}return/^ {2,}$/.test(s)&&function(t,n){for(let o=n-1;o>=0;o--){if(e.$isLineBreakNode(t[o]))return!1;if(/\S/.test(t[o].getTextContent()))return!0}return!1}(n,o)?(r.setTextContent(""),s):null}function b(t){const n=e.$createLineBreakNode(),o=k(t);return null!==o&&e.$setState(n,_,o),n}const w=e=>(t,n,o,r)=>{const s=e(o);s.append(...n),t.replace(s),r||s.select(0,0)};const M=t=>(n,o,s,i)=>{const l=n.getPreviousSibling(),c=n.getNextSibling(),a=r.$createListItemNode("check"===t?"x"===s[3]:void 0),d=s[0].trim()[0],f="bullet"!==t&&"check"!==t||d!==v.parse(d)?void 0:d;if(r.$isListNode(c)&&c.getListType()===t){f&&e.$setState(c,v,f);const o=c.getFirstChild();null!==o?o.insertBefore(a):c.append(a),"number"===t&&c.setStart(Number(s[2])),n.remove()}else if(r.$isListNode(l)&&l.getListType()===t)f&&e.$setState(l,v,f),l.append(a),n.remove();else{const o=r.$createListNode(t,"number"===t?Number(s[2]):void 0);f&&e.$setState(o,v,f),o.append(a),n.replace(o)}a.append(...o),i||a.select(0,0);const u=function(e){const t=e.match(/\t/g),n=e.match(/ /g);let o=0;return t&&(o+=t.length),n&&(o+=Math.floor(n.length/4)),o}(s[1]);u&&a.setIndent(u)},A=(t,n,o,s)=>{const i=[],l=t.getChildren();let c=0;for(const a of l)if(r.$isListItemNode(a)){if(1===a.getChildrenSize()){const e=a.getFirstChild();if(r.$isListNode(e)){const t=A(e,n,o+1,s);t&&i.push(t);continue}}if(s&&!a.getChildren().some(e=>e.isSelected(s)))continue;const l=" ".repeat(4*o),d=t.getListType(),f=e.$getState(t,v),u="number"===d?`${t.getStart()+c}. `:"check"===d?`${f} [${a.getChecked()?"x":" "}] `:f+" ";let g=n(a);"number"!==d&&(g=g.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),i.push(l+u+g),c++}return i.join("\n")},F={dependencies:[s.HeadingNode],export:(e,t)=>{if(!s.$isHeadingNode(e))return null;const n=Number(e.getTag().slice(1));return"#".repeat(n)+" "+t(e)},regExp:m,replace:w(e=>{const t="h"+e[1].length;return s.$createHeadingNode(t)}),triggerOnEnter:!0,type:"element"},B={dependencies:[s.QuoteNode],export:(e,t)=>{if(!s.$isQuoteNode(e))return null;const n=t(e).split("\n"),o=[];for(const e of n)o.push("> "+e);return o.join("\n")},regExp:$,replace:(e,t,n,o)=>{if(o){const n=e.getPreviousSibling();if(s.$isQuoteNode(n))return n.splice(n.getChildrenSize(),0,[b(n),...t]),void e.remove()}const r=s.$createQuoteNode();r.append(...t),e.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},D={dependencies:[n.CodeNode],export:t=>{if(!n.$isCodeNode(t))return null;const o=t.getTextContent();let r=e.$getState(t,O);if(o.indexOf(r)>-1){const e=o.match(/`{3,}/g);if(e){const t=Math.max(...e.map(e=>e.length));r="`".repeat(t+1)}}return r+(t.getLanguage()||"")+(o?"\n"+o:"")+"\n"+r},handleImportAfterStartMatch:({lines:e,rootNode:t,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=e[n],l=o.index+r.length,c=i.slice(l),a=new RegExp(`\`{${s},}$`);if(a.test(c)){const e=c.match(a),r=c.slice(0,c.lastIndexOf(e[0])),s=[...o];return s[2]="",D.replace(t,null,s,e,[r],!0),[!0,n]}const d=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<e.length;r++){const s=e[r];if(d.test(s)){const l=s.match(d),c=e.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&c.unshift(a),D.replace(t,null,o,l,c,!0),[!0,r]}}const f=e.slice(n+1),u=i.slice(o[0].length);return u.length>0&&f.unshift(u),D.replace(t,null,o,null,f,!0),[!0,e.length-1]},regExpEnd:{optional:!0,regExp:N},regExpStart:T,replace:(t,o,r,s,i,l)=>{let c,a;const d=r[1]?r[1].trim():"```",f=r[2]||void 0;if(!o&&i){if(1===i.length)s?(c=n.$createCodeNode(f),a=i[0]):(c=n.$createCodeNode(f),a=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=n.$createCodeNode(f),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();a=i.join("\n")}e.$setState(c,O,d);const o=e.$createTextNode(a);c.append(o),t.append(c)}else o&&w(e=>n.$createCodeNode(e?e[2]:void 0))(t,o,r,l)},type:"multiline-element"},P={dependencies:[r.ListNode,r.ListItemNode],export:(e,t,n)=>r.$isListNode(e)?A(e,t,0,n):null,regExp:h,replace:M("bullet"),triggerOnEnter:!0,type:"element"},H={dependencies:[r.ListNode,r.ListItemNode],export:(e,t,n)=>r.$isListNode(e)?A(e,t,0,n):null,regExp:x,replace:M("check"),triggerOnEnter:!0,type:"element"},j={dependencies:[r.ListNode,r.ListItemNode],export:(e,t,n)=>r.$isListNode(e)?A(e,t,0,n):null,regExp:p,replace:M("number"),triggerOnEnter:!0,type:"element"},U={format:["code"],tag:"`",type:"text-format"};const W={format:["highlight"],tag:"==",type:"text-format"},z={format:["bold","italic"],tag:"***",type:"text-format"},G={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},q={format:["bold"],tag:"**",type:"text-format"},Q={format:["bold"],intraword:!1,tag:"__",type:"text-format"},K={format:["strikethrough"],tag:"~~",type:"text-format"},Y={format:["italic"],tag:"*",type:"text-format"},X={format:["italic"],intraword:!1,tag:"_",type:"text-format"},J={dependencies:[o.LinkNode],export:(e,t,n)=>{if(!o.$isLinkNode(e)||o.$isAutoLinkNode(e))return null;const r=t(e);let s=e.getTitle();null!=s&&(s=s.replace(/([\\"])/g,"\\$1"));return s?`[${r}](${e.getURL()} "${s}")`:`[${r}](${e.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{if(e.$findMatchingParent(t,o.$isLinkNode))return;const[,r,s,i]=n,l=null!=s?g(s):void 0,c=null!=i?g(i):void 0,a=o.$createLinkNode(l,{title:c}),d=r.split("[").length-1,f=r.split("]").length-1;let u=r,p="";if(d<f)return;if(d>f){const e=r.split("[");p="["+e[0],u=e.slice(1).join("[")}const h=e.$createTextNode(u);return h.setFormat(t.getFormat()),a.append(h),t.replace(a),p&&a.insertBefore(e.$createTextNode(p)),h},trigger:")",type:"text-match"},V=[F,B,P,j],Z=[D],ee=[U,z,G,q,Q,W,Y,X,K],te=[J],ne=[...V,...Z,...ee,...te];function oe(t,n,o,r,s,i){let l=t.isSelected(n);for(const c of o){if(!c.export)continue;const o=c.export(t,e=>re(e,n,r,s,i).markdown,n);if(null!=o){if(!l&&e.$isElementNode(t)){re(t,n,r,s,i).shouldInclude&&(l=!0)}return{markdown:o,shouldInclude:l}}}if(e.$isElementNode(t)){const e=re(t,n,r,s,i);return{markdown:e.markdown,shouldInclude:l||e.shouldInclude}}return e.$isDecoratorNode(t)?{markdown:t.getTextContent(),shouldInclude:l}:{markdown:null,shouldInclude:l}}function re(n,o,r,s,i,l,c){const a=[],d=n.getChildren();let f=!1;l||(l=[]),c||(c=[]);e:for(const n of d){let d=n.isSelected(o);for(const u of s){if(!u.export)continue;const g=u.export(n,e=>re(e,o,r,s,i,l,[...c,...l]).markdown,(e,n)=>ce(e,t.$sliceSelectedTextNodeContent(o,e,"clone").getTextContent(),r,l,c,i));if(null!=g){!d&&e.$isElementNode(n)&&n.getChildren().some(e=>e.isSelected(o))&&n.extractWithChild(n,o,"html")&&(d=!0),d&&(a.push(g),f=!0);continue e}}if(e.$isLineBreakNode(n))d&&(a.push(le(n)),f=!0);else if(e.$isTextNode(n)){if(d){const e=t.$sliceSelectedTextNodeContent(o,n,"clone");a.push(ce(n,e.getTextContent(),r,l,c,i)),f=!0}}else if(e.$isElementNode(n)){const e=re(n,o,r,s,i,l,c);!d&&e.shouldInclude&&n.extractWithChild(n,o,"html")&&(d=!0),(d||e.shouldInclude)&&(a.push(e.markdown),f=!0)}else e.$isDecoratorNode(n)&&d&&(a.push(n.getTextContent()),f=!0)}return{markdown:a.join(""),shouldInclude:f}}function se(t,n,o,r,s){for(const e of n){if(!e.export)continue;const n=e.export(t,e=>ie(e,o,r,void 0,void 0,s));if(null!=n)return n}return e.$isElementNode(t)?ie(t,o,r,void 0,void 0,s):e.$isDecoratorNode(t)?t.getTextContent():null}function ie(t,n,o,r,s,i=!1){const l=[],c=t.getChildren();r||(r=[]),s||(s=[]);e:for(const t of c){for(const e of o){if(!e.export)continue;const c=e.export(t,e=>ie(e,n,o,r,[...s,...r],i),(e,t)=>ce(e,t,n,r,s,i));if(null!=c){l.push(c);continue e}}e.$isLineBreakNode(t)?l.push(le(t)):e.$isTextNode(t)?l.push(ce(t,t.getTextContent(),n,r,s,i)):e.$isElementNode(t)?l.push(ie(t,n,o,r,s,i)):e.$isDecoratorNode(t)&&l.push(t.getTextContent())}return l.join("")}function le(t){return e.$getState(t,_)+"\n"}function ce(e,t,n,o,r,s=!1){const i=e.hasFormat("code");let l,c,a,d,f=t;if(i||(f=s?f.replace(/([*_`~])/g,"\\$1"):f.replace(/([*_`~\\])/g,"\\$1")),i){const{fence:e,padded:n}=function(e){const t=e.match(/`+/g),n=t?Math.max(...t.map(e=>e.length)):0;return{fence:"`".repeat(n+1),padded:0===e.length||e.includes("`")||/^\s/.test(e)&&/\s$/.test(e)?` ${e} `:e}}(t);l="",a="",c=e+n+e,d=!1}else{const e=f.match(/^(\s*)(.*?)(\s*)$/s)||["","",f,""];l=e[1],c=e[2],a=e[3],d=""===c}let u="",g="",p="";const h=ae(e,!0),x=ae(e,!1),m=new Set;for(const t of n){const n=t.format[0],r=t.tag;"code"!==n&&(fe(e,n)&&!m.has(n)&&(m.add(n),fe(h,n)&&o.find(e=>e.tag===r)||(o.push({format:n,tag:r}),u+=r)))}for(let t=0;t<o.length;t++){const n=de(e,o[t].format),s=de(x,o[t].format);if(n&&s)continue;const i=[...o];for(;i.length>t;){const e=i.pop();r&&e&&r.find(t=>t.tag===e.tag)||(e&&"string"==typeof e.tag&&(n?s||(p+=e.tag):g+=e.tag),o.pop())}break}return d&&!e.hasFormat("code")?g+f:g+l+u+c+p+a}function ae(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e.$isTextNode(o)?o:null}function de(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function fe(e,t){return!!de(e,t)&&("code"===t||(!e||!/^\s*$/.test(e.getTextContent())))}function ue(e,t){const n=e.getTextContent(),o=t.transformersByTag["`"],r=[];let s=null;if(o){const e=function(e){const t=t=>{let n=0;for(let o=t-1;o>=0&&"\\"===e[o];o--)n++;return n%2==1},n=[];let o=0;for(;o<e.length;)if("`"===e[o]){let t=1;for(;o+t<e.length&&"`"===e[o+t];)t++;n.push({index:o,length:t}),o+=t}else o++;const r=[];let s=0;for(;s<n.length;){const o=n[s];if(t(o.index)){s++;continue}let i=-1;for(let e=s+1;e<n.length;e++)if(n[e].length===o.length){i=e;break}if(-1===i){s++;continue}const l=n[i];let c=e.slice(o.index+o.length,l.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),r.push({content:c,endIndex:l.index+l.length,startIndex:o.index}),s=i+1}return r}(n);for(const t of e)s||(s={content:t.content,endIndex:t.endIndex,startIndex:t.startIndex,tag:"`"}),r.push({end:t.endIndex,start:t.startIndex})}const i=function(e,t,n=[]){const o=[],r=new Set(Object.keys(t.transformersByTag).filter(e=>"`"!==e[0]).map(e=>e[0])),s=t=>{let n=0;for(let o=t-1;o>=0&&"\\"===e[o];o--)n++;return n%2==1},i=e=>n.some(t=>e>=t.start&&e<t.end);let l=0;for(;l<e.length;){const t=e[l];if(!r.has(t)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<e.length&&e[l+n]===t;)n++;const c=ge(t,e,l,n,!0),a=ge(t,e,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:t,index:l,length:n,originalLength:n}),l+=n}return o}(n,t,r),l=i.length>0?function(e,t,n){const o={};let r=0,s=null;for(;r<t.length;){const i=t[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const l=`${i.char}${i.canOpen}`,c=o[l]??-1;let a=!1;for(let o=r-1;o>c;o--){const l=t[o];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if(l.canClose||i.canOpen){if((l.originalLength+i.originalLength)%3==0&&l.originalLength%3!=0&&i.originalLength%3!=0)continue}const c=Math.min(l.length,i.length),d=Object.keys(n.transformersByTag).filter(e=>e[0]===l.char&&e.length<=c).sort((e,t)=>t.length-e.length)[0];if(!d)continue;a=!0;const f=d.length,u={content:e.slice(l.index+l.length,i.index),endIndex:i.index+f,startIndex:l.index+(l.length-f),tag:d};(!s||u.startIndex<s.startIndex||u.startIndex===s.startIndex&&u.endIndex>s.endIndex)&&(s=u);for(let e=o+1;e<r;e++)t[e].active=!1;l.length-=f,i.length-=f,l.active=l.length>0,i.length>0?i.index+=f:(i.active=!1,r++);break}a||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,i,t):null;let c=null,a=null;if(s&&l?l.startIndex<=s.startIndex&&l.endIndex>=s.endIndex?(c=l,a=t.transformersByTag[l.tag]):(c=s,a=o):s?(c=s,a=o):l&&(c=l,a=t.transformersByTag[l.tag]),!c||!a)return null;const d=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return d.index=c.startIndex,d.input=n,{endIndex:c.endIndex,isCodeSpan:a===o,match:d,startIndex:c.startIndex,transformer:a}}function ge(e,t,n,o,r){if(!pe(t,n,o,r))return!1;if("*"===e)return!0;if("_"===e){if(!pe(t,n,o,!r))return!0;const e=r?t[n-1]:t[n+o];return void 0!==e&&d.test(e)}return!0}function pe(e,t,n,o){const r=e[t-1],s=e[t+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!a.test(i)&&(!d.test(i)||(void 0===l||a.test(l)||d.test(l)))}function he(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function xe(e,t,n){let o=ue(e,t),r=function(e,t){const n=e;let o,r,s,i;for(const e of t){if(!e.replace||!e.importRegExp)continue;const t=n.getTextContent().match(e.importRegExp);if(!t)continue;const l=t.index||0,c=e.getEndIndex?e.getEndIndex(n,t):l+t[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&(c>r||c<=o))&&(o=l,r=c,s=e,i=t)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(e,n);if(o&&r&&(o.isCodeSpan?r.startIndex<=o.startIndex&&r.endIndex>=o.endIndex?o=null:r=null:o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(e,t,n,o,r){const s=e.getTextContent();let i,l,c;if(r[0]===s?i=e:0===t?[i,l]=e.splitText(n):[c,i,l]=e.splitText(t,n),i.setTextContent(r[2]),o)for(const e of o.format)i.hasFormat(e)||i.toggleFormat(e);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(e,o.startIndex,o.endIndex,o.transformer,o.match);he(r.nodeAfter)&&xe(r.nodeAfter,t,n),he(r.nodeBefore)&&xe(r.nodeBefore,t,n),he(r.transformedNode)&&xe(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let s,i,l;return 0===t?[s,i]=e.splitText(n):[l,s,i]=e.splitText(t,n),o.replace?{nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;he(o.nodeAfter)&&xe(o.nodeAfter,t,n),he(o.nodeBefore)&&xe(o.nodeBefore,t,n),he(o.transformedNode)&&xe(o.transformedNode,t,n)}const s=g(e.getTextContent());e.setTextContent(s)}function me(t,n=!1){const o=l(t),r=function(e){const t={},n={},o=[];for(const r of e){const{tag:e}=r;t[e]=r;const s=e.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===e.length?n[e]="`"===e?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[e]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:t}}(o.textFormat);return(t,s)=>{const i=t.split("\n"),l=i.length,c=s||e.$getRoot();c.clear();for(let e=0;e<l;e++){const t=i[e],[s,l]=$e(i,e,o.multilineElement,c);s?e=l:Te(t,c,o.element,r,o.textMatch,n)}const a=c.getChildren();for(const t of a)if(!n&&u(t)&&c.getChildrenSize()>1)t.remove();else if(e.$isElementNode(t))for(const e of t.getAllTextNodes())Ne(e);null!==e.$getSelection()&&c.selectStart()}}function $e(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=r,c=e[t].match(i);if(!c)continue;if(n){const s=n({lines:e,rootNode:o,startLineIndex:t,startMatch:c,transformer:r});if(null===s)continue;if(s)return s}const a="object"==typeof s&&"regExp"in s?s.regExp:s,d=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let f=t;const u=e.length;for(;f<u;){const n=a?e[f].match(a):null;if(!n&&(!d||d&&f<u-1)){f++;continue}if(n&&t===f&&n.index===c.index){f++;continue}const r=[];if(n&&t===f)r.push(e[t].slice(c[0].length,-n[0].length));else for(let o=t;o<=f;o++)if(o===t){const t=e[o].slice(c[0].length);r.push(t)}else if(o===f&&n){const t=e[o].slice(0,-n[0].length);r.push(t)}else r.push(e[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,f];break}}return[!1,t]}function Te(t,n,o,i,l,c){const a=e.$createTextNode(t),d=e.$createParagraphNode();d.append(a),n.append(d);for(const{regExp:e,replace:n}of o){const o=t.match(e);if(o&&(a.setTextContent(t.slice(o[0].length)),!1!==n(d,[a],o,!0)))break}if(xe(a,i,l),d.isAttached()&&t.length>0){const t=d.getPreviousSibling();if(!c&&(e.$isParagraphNode(t)||s.$isQuoteNode(t)||r.$isListNode(t))){let n=t;if(r.$isListNode(t)){const o=t.getLastDescendant();n=null==o?null:e.$findMatchingParent(o,r.$isListItemNode)}null!=n&&n.getTextContentSize()>0&&(n.splice(n.getChildrenSize(),0,[b(n),...d.getChildren()]),d.remove())}}}function Ne(t){const n=new Set,o=t.getTextContent();let r=o.indexOf("\t");for(;-1!==r;)n.add(r),n.add(r+1),r=o.indexOf("\t",r+1);t.splitText(...n).forEach(t=>{"\t"===t.getTextContent()&&t.replace(e.$createTabNode())})}function Ce(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Se(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const l=n.getTextContent();if(!s&&" "!==l[o-1])return!1;for(const{regExp:e,replace:i}of r){const r=l.match(e),c=s||r&&r[0].endsWith(" ")?o:o-1;if(r&&r[0].length===c){const e=n.getNextSiblings(),[s,l]=n.splitText(o);if(!1!==i(t,l?[l,...e]:e,r,!1))return s.remove(),!0}}return!1}function Ee(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const l=n.getTextContent();if(!s&&" "!==l[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:c}of r){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const r=l.match(e);if(r){const e=s||r[0].endsWith(" ")?o:o-1;if(r[0].length!==e)continue;const l=n.getNextSiblings(),[c,a]=n.splitText(o);if(!1!==i(t,a?[a,...l]:l,r,null,null,!1))return c.remove(),!0}}return!1}function Ie(e,t){let n=0;const o=e.getTextContent();for(let e=0;e<t;e++)"`"===o[e]&&n++;return n%2!=0}function Le(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(Re(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function Re(e,t,n,o,r){for(let s=0;s<r;s++)if(e[t+s]!==n[o+s])return!1;return!0}exports.$convertFromMarkdownString=function(e,t=ne,n,o=!1,r=!1){const s=o?e:function(e,t=!1){const n=e.split("\n");let o=!1;const r=[];for(let e=0;e<n.length;e++){const s=n[e],i=s.trimEnd(),l=r[r.length-1],c=e<n.length-1?y(s):null,a=void 0!==l&&null!==y(l);C.test(i)?r.push(i):T.test(i)||N.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===l||!l||m.test(l)||m.test(i)||$.test(i)||p.test(i)||h.test(i)||x.test(i)||S.test(i)||E(i)||a||!t||I.test(i)||L.test(i)||R(L).test(l)||R(I).test(l)||N.test(l)?r.push(!t&&""!==i||null!==c?s:i):r[r.length-1]=l+" "+(null===c?i:s).trimStart()}return r.join("\n")}(e,r);return me(t,o)(s,n)},exports.$convertSelectionToMarkdownString=function(t=ne,n,o=!1){if(!n||e.$isRangeSelection(n)&&n.isCollapsed())return"";const r=function(t,n=!1){const o=l(t),r=[...o.multilineElement,...o.element],s=!n,i=o.textFormat.filter(e=>1===e.format.length).sort((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code")));return t=>{const l=[],c=e.$getRoot().getChildren();for(let e=0;e<c.length;e++){const a=c[e],{shouldInclude:d,markdown:f}=oe(a,t,r,i,o.textMatch,n);d&&null!=f&&l.push(s&&e>0&&!u(a)&&!u(c[e-1])?"\n".concat(f):f)}return l.join("\n")}}(t,o);return r(n)},exports.$convertToMarkdownString=function(t=ne,n,o=!1){return function(t,n=!1){const o=l(t),r=[...o.multilineElement,...o.element],s=!n,i=o.textFormat.filter(e=>1===e.format.length).sort((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code")));return t=>{const l=[],c=(t||e.$getRoot()).getChildren();for(let e=0;e<c.length;e++){const t=c[e],a=se(t,r,i,o.textMatch,n);null!=a&&l.push(s&&e>0&&!u(t)&&!u(c[e-1])?"\n".concat(a):a)}return l.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=z,exports.BOLD_ITALIC_UNDERSCORE=G,exports.BOLD_STAR=q,exports.BOLD_UNDERSCORE=Q,exports.CHECK_LIST=H,exports.CODE=D,exports.ELEMENT_TRANSFORMERS=V,exports.HEADING=F,exports.HIGHLIGHT=W,exports.INLINE_CODE=U,exports.ITALIC_STAR=Y,exports.ITALIC_UNDERSCORE=X,exports.LINK=J,exports.MULTILINE_ELEMENT_TRANSFORMERS=Z,exports.ORDERED_LIST=j,exports.QUOTE=B,exports.STRIKETHROUGH=K,exports.TEXT_FORMAT_TRANSFORMERS=ee,exports.TEXT_MATCH_TRANSFORMERS=te,exports.TRANSFORMERS=ne,exports.UNORDERED_LIST=P,exports.isTableRowDivider=E,exports.registerMarkdownShortcuts=function(t,o=ne){const r=l(o),s=r.element.filter(e=>e.triggerOnEnter),a=i(r.textFormat,({tag:e})=>e[e.length-1]),d=i(r.textMatch,({trigger:e})=>e),f=new Set([" "]);for(const e of r.textFormat)f.add(e.tag.slice(-1));for(const e of r.textMatch)void 0!==e.trigger&&f.add(e.trigger);for(const e of o){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)||Ce(173,e.getType())}}const u=(t,n,o)=>!!Se(t,n,o,r.element)||(!!Ee(t,n,o,r.multilineElement)||(!!function(e,t,n){let o=e.getTextContent();const r=n[o[t-1]];if(null==r)return!1;t<o.length&&(o=o.slice(0,t));for(const t of r){if(!t.replace||!t.regExp)continue;const n=o.match(t.regExp);if(null===n)continue;const r=n.index||0,s=r+n[0].length;let i;return 0===r?[i]=e.splitText(s):[,i]=e.splitText(r,s),i.selectNext(0,0),t.replace(i,n),!0}return!1}(n,o,d)||!!function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],l=o[i];if(!l)return!1;for(const n of l){const{tag:o}=n,l=o.length,a=s-l+1;if(l>1&&!Re(r,a,o,0,l))continue;if(" "===r[a-1])continue;const d=r[s+1];if(!1===n.intraword&&d&&!c.test(d))continue;const f=t;let u=f,g=Le(r,a,o),p=u;for(;g<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();u=p,g=Le(e,e.length,o)}if(g<0)continue;if(u===f&&g+l===a)continue;const h=u.getTextContent();if(g>0&&h[g-1]===i)continue;const x=h[g-1];if(!1===n.intraword&&x&&!c.test(x))continue;if(!n.format.includes("code")&&Ie(u,g))continue;const m=f.getTextContent(),$=m.slice(0,a)+m.slice(s+1);f.setTextContent($);const T=u===f?$:h;u.setTextContent(T.slice(0,g)+T.slice(g+l));const N=e.$getSelection(),C=e.$createRangeSelection();e.$setSelection(C);const S=s-l*(u===f?2:1)+1;C.anchor.set(u.__key,g,"text"),C.focus.set(f.__key,S,"text");for(const t of n.format)C.formatText(t,e.TEXT_TYPE_TO_FORMAT[t]);C.anchor.set(C.focus.key,C.focus.offset,C.focus.type);for(const e of n.format)C.hasFormat(e)&&C.toggleFormat(e);return e.$isRangeSelection(N)&&(C.format=N.format),!0}return!1}(n,o,a)));return e.mergeRegister(t.registerUpdateListener(({tags:o,dirtyLeaves:r,editorState:s,prevEditorState:i})=>{if(o.has(e.COLLABORATION_TAG)||o.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const l=o.has(e.COMPOSITION_END_TAG),c=s.read(e.$getSelection),a=i.read(e.$getSelection);if(!e.$isRangeSelection(a)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(a)&&!l)return;const d=c.anchor.key,g=c.anchor.offset,p=s._nodeMap.get(d);if(e.$isTextNode(p)&&r.has(d)&&(l||1===g||!(g>a.anchor.offset+1))){if(l){const e=s.read(()=>p.getTextContent())[g-1];if(!f.has(e))return}t.update(()=>{if(!he(p))return;const t=p.getParent();null===t||n.$isCodeNode(t)||u(t,p,c.anchor.offset)&&e.$addUpdateTag(e.HISTORY_PUSH_TAG)})}}),t.registerCommand(e.KEY_ENTER_COMMAND,t=>{if(null!==t&&t.shiftKey)return!1;const o=e.$getSelection();if(!e.$isRangeSelection(o)||!o.isCollapsed())return!1;const i=o.anchor.offset,l=o.anchor.getNode();if(!e.$isTextNode(l)||!he(l))return!1;const c=l.getParent();if(null===c||n.$isCodeNode(c))return!1;return i===l.getTextContent().length&&(!(!Ee(c,l,i,r.multilineElement,!0)&&!Se(c,l,i,s,!0))&&(null!==t&&t.preventDefault(),!0))},e.COMMAND_PRIORITY_LOW))};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/selection"),n=require("@lexical/code-core"),o=require("@lexical/link"),r=require("@lexical/list"),s=require("@lexical/rich-text");function i(e,t){const n={};for(const o of e){const e=t(o);e&&(n[e]?n[e].push(o):n[e]=[o])}return n}function l(e){const t=i(e,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}const c=/[!-/:-@[-`{-~\s]/,a=/\s/,d=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,f=/^\s{0,3}$/;function u(t){if(!e.$isParagraphNode(t))return!1;const n=t.getFirstChild();return null==n||1===t.getChildrenSize()&&e.$isTextNode(n)&&f.test(n.getTextContent())}function g(e){return e.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}const p=/^(\s*)(\d{1,})\.\s/,h=/^(\s*)[-*+]\s/,x=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,m=/^(#{1,6})\s/,$=/^>\s/,T=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,N=/^[ \t]*`{3,}$/,C=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,S=/^(?:\|)(.+)(?:\|)\s?$/;function E(e){if("|"!==e[0])return!1;const{length:t}=e;let n=1,o=0;for(;n<t;){let t=n;for(" "===e[t]&&t++,":"===e[t]&&t++;"-"===e[t];)t++;if(":"===e[t]&&t++," "===e[t]&&t++,"|"!==e[t])break;o++,n=t+1}return o>0&&(n===t||n===t-1&&/\s/.test(e[n]))}const I=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,L=/^<\/[a-z_][\w-]*\s*>/i,R=e=>new RegExp(`(?:${e.source})$`,e.flags),v=/* @__PURE__ */e.createState("mdListMarker",{parse:e=>"string"==typeof e&&/^[-*+]$/.test(e)?e:"-",resetOnCopyNode:!0}),O=/* @__PURE__ */e.createState("mdCodeFence",{parse:e=>"string"==typeof e&&/^`{3,}$/.test(e)?e:"```",resetOnCopyNode:!0}),_=/* @__PURE__ */e.createState("mdHardLineBreak",{parse:e=>"string"==typeof e&&/^(\\| {2,})$/.test(e)?e:"",resetOnCopyNode:!0});function y(e){if(e.endsWith("\\"))return[e.slice(0,-1),"\\"];const t=e.match(/^(.*?\S)( {2,})$/);return t?[t[1],t[2]]:null}function k(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e.$isTextNode(r))return null;const s=r.getTextContent(),i=y(s);if(null!==i){const[e,t]=i;return r.setTextContent(e),t}return/^ {2,}$/.test(s)&&function(t,n){for(let o=n-1;o>=0;o--){if(e.$isLineBreakNode(t[o]))return!1;if(/\S/.test(t[o].getTextContent()))return!0}return!1}(n,o)?(r.setTextContent(""),s):null}function b(t){const n=e.$createLineBreakNode(),o=k(t);return null!==o&&e.$setState(n,_,o),n}const w=e=>(t,n,o,r)=>{const s=e(o);s.append(...n),t.replace(s),r||s.select(0,0)};const M=t=>(n,o,s,i)=>{const l=n.getPreviousSibling(),c=n.getNextSibling(),a=r.$createListItemNode("check"===t?"x"===s[3]:void 0),d=s[0].trim()[0],f="bullet"!==t&&"check"!==t||d!==v.parse(d)?void 0:d;if(r.$isListNode(c)&&c.getListType()===t){f&&e.$setState(c,v,f);const o=c.getFirstChild();null!==o?o.insertBefore(a):c.append(a),"number"===t&&c.setStart(Number(s[2])),n.remove()}else if(r.$isListNode(l)&&l.getListType()===t)f&&e.$setState(l,v,f),l.append(a),n.remove();else{const o=r.$createListNode(t,"number"===t?Number(s[2]):void 0);f&&e.$setState(o,v,f),o.append(a),n.replace(o)}a.append(...o),i||a.select(0,0);const u=function(e){const t=e.match(/\t/g),n=e.match(/ /g);let o=0;return t&&(o+=t.length),n&&(o+=Math.floor(n.length/4)),o}(s[1]);u&&a.setIndent(u)},A=(t,n,o,s)=>{const i=[],l=t.getChildren();let c=0;for(const a of l)if(r.$isListItemNode(a)){if(1===a.getChildrenSize()){const e=a.getFirstChild();if(r.$isListNode(e)){const t=A(e,n,o+1,s);t&&i.push(t);continue}}if(s&&!a.getChildren().some(e=>e.isSelected(s)))continue;const l=" ".repeat(4*o),d=t.getListType(),f=e.$getState(t,v),u="number"===d?`${t.getStart()+c}. `:"check"===d?`${f} [${a.getChecked()?"x":" "}] `:f+" ";let g=n(a);"number"!==d&&(g=g.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),i.push(l+u+g),c++}return i.join("\n")},F={dependencies:[s.HeadingNode],export:(e,t)=>{if(!s.$isHeadingNode(e))return null;const n=Number(e.getTag().slice(1));return"#".repeat(n)+" "+t(e)},regExp:m,replace:w(e=>{const t="h"+e[1].length;return s.$createHeadingNode(t)}),triggerOnEnter:!0,type:"element"},B={dependencies:[s.QuoteNode],export:(e,t)=>{if(!s.$isQuoteNode(e))return null;const n=t(e).split("\n"),o=[];for(const e of n)o.push("> "+e);return o.join("\n")},regExp:$,replace:(e,t,n,o)=>{if(o){const n=e.getPreviousSibling();if(s.$isQuoteNode(n))return n.splice(n.getChildrenSize(),0,[b(n),...t]),void e.remove()}const r=s.$createQuoteNode();r.append(...t),e.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},D={dependencies:[n.CodeNode],export:t=>{if(!n.$isCodeNode(t))return null;const o=t.getTextContent();let r=e.$getState(t,O);if(o.indexOf(r)>-1){const e=o.match(/`{3,}/g);if(e){const t=Math.max(...e.map(e=>e.length));r="`".repeat(t+1)}}return r+(t.getLanguage()||"")+(o?"\n"+o:"")+"\n"+r},handleImportAfterStartMatch:({lines:e,rootNode:t,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=e[n],l=o.index+r.length,c=i.slice(l),a=new RegExp(`\`{${s},}$`);if(a.test(c)){const e=c.match(a),r=c.slice(0,c.lastIndexOf(e[0])),s=[...o];return s[2]="",D.replace(t,null,s,e,[r],!0),[!0,n]}const d=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<e.length;r++){const s=e[r];if(d.test(s)){const l=s.match(d),c=e.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&c.unshift(a),D.replace(t,null,o,l,c,!0),[!0,r]}}const f=e.slice(n+1),u=i.slice(o[0].length);return u.length>0&&f.unshift(u),D.replace(t,null,o,null,f,!0),[!0,e.length-1]},regExpEnd:{optional:!0,regExp:N},regExpStart:T,replace:(t,o,r,s,i,l)=>{let c,a;const d=r[1]?r[1].trim():"```",f=r[2]||void 0;if(!o&&i){if(1===i.length)s?(c=n.$createCodeNode(f),a=i[0]):(c=n.$createCodeNode(f),a=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=n.$createCodeNode(f),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();a=i.join("\n")}e.$setState(c,O,d);const o=e.$createTextNode(a);c.append(o),t.append(c)}else o&&w(e=>n.$createCodeNode(e?e[2]:void 0))(t,o,r,l)},type:"multiline-element"},P={dependencies:[r.ListNode,r.ListItemNode],export:(e,t,n)=>r.$isListNode(e)?A(e,t,0,n):null,regExp:h,replace:M("bullet"),triggerOnEnter:!0,type:"element"},H={dependencies:[r.ListNode,r.ListItemNode],export:(e,t,n)=>r.$isListNode(e)?A(e,t,0,n):null,regExp:x,replace:M("check"),triggerOnEnter:!0,type:"element"},j={dependencies:[r.ListNode,r.ListItemNode],export:(e,t,n)=>r.$isListNode(e)?A(e,t,0,n):null,regExp:p,replace:M("number"),triggerOnEnter:!0,type:"element"},U={format:["code"],tag:"`",type:"text-format"};const W={format:["highlight"],tag:"==",type:"text-format"},z={format:["bold","italic"],tag:"***",type:"text-format"},G={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},q={format:["bold"],tag:"**",type:"text-format"},Q={format:["bold"],intraword:!1,tag:"__",type:"text-format"},K={format:["strikethrough"],tag:"~~",type:"text-format"},Y={format:["italic"],tag:"*",type:"text-format"},X={format:["italic"],intraword:!1,tag:"_",type:"text-format"},J={dependencies:[o.LinkNode],export:(e,t,n)=>{if(!o.$isLinkNode(e)||o.$isAutoLinkNode(e))return null;const r=t(e);let s=e.getTitle();null!=s&&(s=s.replace(/([\\"])/g,"\\$1"));return s?`[${r}](${e.getURL()} "${s}")`:`[${r}](${e.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{if(e.$findMatchingParent(t,o.$isLinkNode))return;const[,r,s,i]=n,l=null!=s?g(s):void 0,c=null!=i?g(i):void 0,a=o.$createLinkNode(l,{title:c}),d=r.split("[").length-1,f=r.split("]").length-1;let u=r,p="";if(d<f)return;if(d>f){const e=r.split("[");p="["+e[0],u=e.slice(1).join("[")}const h=e.$createTextNode(u);return h.setFormat(t.getFormat()),a.append(h),t.replace(a),p&&a.insertBefore(e.$createTextNode(p)),h},trigger:")",type:"text-match"},V=[F,B,P,j],Z=[D],ee=[U,z,G,q,Q,W,Y,X,K],te=[J],ne=[...V,...Z,...ee,...te];function oe(t,n,o,r,s,i){let l=t.isSelected(n);for(const c of o){if(!c.export)continue;const o=c.export(t,e=>re(e,n,r,s,i).markdown,n);if(null!=o){if(!l&&e.$isElementNode(t)){re(t,n,r,s,i).shouldInclude&&(l=!0)}return{markdown:o,shouldInclude:l}}}if(e.$isElementNode(t)){const e=re(t,n,r,s,i);return{markdown:e.markdown,shouldInclude:l||e.shouldInclude}}return e.$isDecoratorNode(t)?{markdown:t.getTextContent(),shouldInclude:l}:{markdown:null,shouldInclude:l}}function re(n,o,r,s,i,l,c){const a=[],d=n.getChildren();let f=!1;l||(l=[]),c||(c=[]);e:for(const n of d){let d=n.isSelected(o);for(const u of s){if(!u.export)continue;const g=u.export(n,e=>re(e,o,r,s,i,l,[...c,...l]).markdown,(e,n)=>ce(e,t.$sliceSelectedTextNodeContent(o,e,"clone").getTextContent(),r,l,c,i));if(null!=g){!d&&e.$isElementNode(n)&&n.getChildren().some(e=>e.isSelected(o))&&n.extractWithChild(n,o,"html")&&(d=!0),d&&(a.push(g),f=!0);continue e}}if(e.$isLineBreakNode(n))d&&(a.push(le(n)),f=!0);else if(e.$isTextNode(n)){if(d){const e=t.$sliceSelectedTextNodeContent(o,n,"clone");a.push(ce(n,e.getTextContent(),r,l,c,i)),f=!0}}else if(e.$isElementNode(n)){const e=re(n,o,r,s,i,l,c);!d&&e.shouldInclude&&n.extractWithChild(n,o,"html")&&(d=!0),(d||e.shouldInclude)&&(a.push(e.markdown),f=!0)}else e.$isDecoratorNode(n)&&d&&(a.push(n.getTextContent()),f=!0)}return{markdown:a.join(""),shouldInclude:f}}function se(t,n,o,r,s){for(const e of n){if(!e.export)continue;const n=e.export(t,e=>ie(e,o,r,void 0,void 0,s));if(null!=n)return n}return e.$isElementNode(t)?ie(t,o,r,void 0,void 0,s):e.$isDecoratorNode(t)?t.getTextContent():null}function ie(t,n,o,r,s,i=!1){const l=[],c=t.getChildren();r||(r=[]),s||(s=[]);e:for(const t of c){for(const e of o){if(!e.export)continue;const c=e.export(t,e=>ie(e,n,o,r,[...s,...r],i),(e,t)=>ce(e,t,n,r,s,i));if(null!=c){l.push(c);continue e}}e.$isLineBreakNode(t)?l.push(le(t)):e.$isTextNode(t)?l.push(ce(t,t.getTextContent(),n,r,s,i)):e.$isElementNode(t)?l.push(ie(t,n,o,r,s,i)):e.$isDecoratorNode(t)&&l.push(t.getTextContent())}return l.join("")}function le(t){return e.$getState(t,_)+"\n"}function ce(e,t,n,o,r,s=!1){const i=e.hasFormat("code");let l,c,a,d,f=t;if(i||(f=s?f.replace(/([*_`~])/g,"\\$1"):f.replace(/([*_`~\\])/g,"\\$1")),i){const{fence:e,padded:n}=function(e){const t=e.match(/`+/g),n=t?Math.max(...t.map(e=>e.length)):0;return{fence:"`".repeat(n+1),padded:0===e.length||e.includes("`")||/^\s/.test(e)&&/\s$/.test(e)?` ${e} `:e}}(t);l="",a="",c=e+n+e,d=!1}else{const e=f.match(/^(\s*)(.*?)(\s*)$/s)||["","",f,""];l=e[1],c=e[2],a=e[3],d=""===c}let u="",g="",p="";const h=ae(e,!0),x=ae(e,!1),m=new Set;for(const t of n){const n=t.format[0],r=t.tag;"code"!==n&&(fe(e,n)&&!m.has(n)&&(m.add(n),fe(h,n)&&o.find(e=>e.tag===r)||(o.push({format:n,tag:r}),u+=r)))}for(let t=0;t<o.length;t++){const n=de(e,o[t].format),s=de(x,o[t].format);if(n&&s)continue;const i=[...o];for(;i.length>t;){const e=i.pop();r&&e&&r.find(t=>t.tag===e.tag)||(e&&"string"==typeof e.tag&&(n?s||(p+=e.tag):g+=e.tag),o.pop())}break}return d&&!e.hasFormat("code")?g+f:g+l+u+c+p+a}function ae(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e.$isTextNode(o)?o:null}function de(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function fe(e,t){return!!de(e,t)&&("code"===t||(!e||!/^\s*$/.test(e.getTextContent())))}function ue(e,t){const n=e.getTextContent(),o=t.transformersByTag["`"],r=[];let s=null;if(o){const e=function(e){const t=t=>{let n=0;for(let o=t-1;o>=0&&"\\"===e[o];o--)n++;return n%2==1},n=[];let o=0;for(;o<e.length;)if("`"===e[o]){let t=1;for(;o+t<e.length&&"`"===e[o+t];)t++;n.push({index:o,length:t}),o+=t}else o++;const r=[];let s=0;for(;s<n.length;){const o=n[s];if(t(o.index)){s++;continue}let i=-1;for(let e=s+1;e<n.length;e++)if(n[e].length===o.length){i=e;break}if(-1===i){s++;continue}const l=n[i];let c=e.slice(o.index+o.length,l.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),r.push({content:c,endIndex:l.index+l.length,startIndex:o.index}),s=i+1}return r}(n);for(const t of e)s||(s={content:t.content,endIndex:t.endIndex,startIndex:t.startIndex,tag:"`"}),r.push({end:t.endIndex,start:t.startIndex})}const i=function(e,t,n=[]){const o=[],r=new Set(Object.keys(t.transformersByTag).filter(e=>"`"!==e[0]).map(e=>e[0])),s=t=>{let n=0;for(let o=t-1;o>=0&&"\\"===e[o];o--)n++;return n%2==1},i=e=>n.some(t=>e>=t.start&&e<t.end);let l=0;for(;l<e.length;){const t=e[l];if(!r.has(t)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<e.length&&e[l+n]===t;)n++;const c=ge(t,e,l,n,!0),a=ge(t,e,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:t,index:l,length:n,originalLength:n}),l+=n}return o}(n,t,r),l=i.length>0?function(e,t,n){const o={};let r=0,s=null;for(;r<t.length;){const i=t[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const l=`${i.char}${i.canOpen}`,c=o[l]??-1;let a=!1;for(let o=r-1;o>c;o--){const l=t[o];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if(l.canClose||i.canOpen){if((l.originalLength+i.originalLength)%3==0&&l.originalLength%3!=0&&i.originalLength%3!=0)continue}const c=Math.min(l.length,i.length),d=Object.keys(n.transformersByTag).filter(e=>e[0]===l.char&&e.length<=c).sort((e,t)=>t.length-e.length)[0];if(!d)continue;a=!0;const f=d.length,u={content:e.slice(l.index+l.length,i.index),endIndex:i.index+f,startIndex:l.index+(l.length-f),tag:d};(!s||u.startIndex<s.startIndex||u.startIndex===s.startIndex&&u.endIndex>s.endIndex)&&(s=u);for(let e=o+1;e<r;e++)t[e].active=!1;l.length-=f,i.length-=f,l.active=l.length>0,i.length>0?i.index+=f:(i.active=!1,r++);break}a||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,i,t):null;let c=null,a=null;if(s&&l?l.startIndex<=s.startIndex&&l.endIndex>=s.endIndex?(c=l,a=t.transformersByTag[l.tag]):(c=s,a=o):s?(c=s,a=o):l&&(c=l,a=t.transformersByTag[l.tag]),!c||!a)return null;const d=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return d.index=c.startIndex,d.input=n,{endIndex:c.endIndex,isCodeSpan:a===o,match:d,startIndex:c.startIndex,transformer:a}}function ge(e,t,n,o,r){if(!pe(t,n,o,r))return!1;if("*"===e)return!0;if("_"===e){if(!pe(t,n,o,!r))return!0;const e=r?t[n-1]:t[n+o];return void 0!==e&&d.test(e)}return!0}function pe(e,t,n,o){const r=e[t-1],s=e[t+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!a.test(i)&&(!d.test(i)||(void 0===l||a.test(l)||d.test(l)))}function he(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function xe(e,t,n){let o=ue(e,t),r=function(e,t){const n=e;let o,r,s,i;for(const e of t){if(!e.replace||!e.importRegExp)continue;const t=n.getTextContent().match(e.importRegExp);if(!t)continue;const l=t.index||0,c=e.getEndIndex?e.getEndIndex(n,t):l+t[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&(c>r||c<=o))&&(o=l,r=c,s=e,i=t)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(e,n);if(o&&r&&(o.isCodeSpan?r.startIndex<=o.startIndex&&r.endIndex>=o.endIndex?o=null:r=null:o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(e,t,n,o,r){const s=e.getTextContent();let i,l,c;if(r[0]===s?i=e:0===t?[i,l]=e.splitText(n):[c,i,l]=e.splitText(t,n),i.setTextContent(r[2]),o)for(const e of o.format)i.hasFormat(e)||i.toggleFormat(e);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(e,o.startIndex,o.endIndex,o.transformer,o.match);he(r.nodeAfter)&&xe(r.nodeAfter,t,n),he(r.nodeBefore)&&xe(r.nodeBefore,t,n),he(r.transformedNode)&&xe(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let s,i,l;return 0===t?[s,i]=e.splitText(n):[l,s,i]=e.splitText(t,n),o.replace?{nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;he(o.nodeAfter)&&xe(o.nodeAfter,t,n),he(o.nodeBefore)&&xe(o.nodeBefore,t,n),he(o.transformedNode)&&xe(o.transformedNode,t,n)}const s=g(e.getTextContent());e.setTextContent(s)}function me(t,n=!1){const o=l(t),r=function(e){const t={},n={},o=[];for(const r of e){const{tag:e}=r;t[e]=r;const s=e.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===e.length?n[e]="`"===e?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[e]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:t}}(o.textFormat);return(t,s)=>{const i=t.split("\n"),l=i.length,c=s||e.$getRoot();c.clear();for(let e=0;e<l;e++){const t=i[e],[s,l]=$e(i,e,o.multilineElement,c);s?e=l:Te(t,c,o.element,r,o.textMatch,n)}const a=c.getChildren();for(const t of a)if(!n&&u(t)&&c.getChildrenSize()>1)t.remove();else if(e.$isElementNode(t))for(const e of t.getAllTextNodes())Ne(e);null!==e.$getSelection()&&c.selectStart()}}function $e(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=r,c=e[t].match(i);if(!c)continue;if(n){const s=n({lines:e,rootNode:o,startLineIndex:t,startMatch:c,transformer:r});if(null===s)continue;if(s)return s}const a="object"==typeof s&&"regExp"in s?s.regExp:s,d=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let f=t;const u=e.length;for(;f<u;){const n=a?e[f].match(a):null;if(!n&&(!d||d&&f<u-1)){f++;continue}if(n&&t===f&&n.index===c.index){f++;continue}const r=[];if(n&&t===f)r.push(e[t].slice(c[0].length,-n[0].length));else for(let o=t;o<=f;o++)if(o===t){const t=e[o].slice(c[0].length);r.push(t)}else if(o===f&&n){const t=e[o].slice(0,-n[0].length);r.push(t)}else r.push(e[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,f];break}}return[!1,t]}function Te(t,n,o,i,l,c){const a=e.$createTextNode(t),d=e.$createParagraphNode();d.append(a),n.append(d);for(const{regExp:e,replace:n}of o){const o=t.match(e);if(o&&(a.setTextContent(t.slice(o[0].length)),!1!==n(d,[a],o,!0)))break}if(xe(a,i,l),d.isAttached()&&t.length>0){const t=d.getPreviousSibling();if(!c&&(e.$isParagraphNode(t)||s.$isQuoteNode(t)||r.$isListNode(t))){let n=t;if(r.$isListNode(t)){const o=t.getLastDescendant();n=null==o?null:e.$findMatchingParent(o,r.$isListItemNode)}null!=n&&n.getTextContentSize()>0&&(n.splice(n.getChildrenSize(),0,[b(n),...d.getChildren()]),d.remove())}}}function Ne(t){const n=new Set,o=t.getTextContent();let r=o.indexOf("\t");for(;-1!==r;)n.add(r),n.add(r+1),r=o.indexOf("\t",r+1);t.splitText(...n).forEach(t=>{"\t"===t.getTextContent()&&t.replace(e.$createTabNode())})}function Ce(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Se(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const l=n.getTextContent();if(!s&&" "!==l[o-1])return!1;for(const{regExp:e,replace:i}of r){const r=l.match(e),c=s||r&&r[0].endsWith(" ")?o:o-1;if(r&&r[0].length===c){const e=n.getNextSiblings(),[s,l]=n.splitText(o);if(!1!==i(t,l?[l,...e]:e,r,!1))return s.remove(),!0}}return!1}function Ee(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const l=n.getTextContent();if(!s&&" "!==l[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:c}of r){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const r=l.match(e);if(r){const e=s||r[0].endsWith(" ")?o:o-1;if(r[0].length!==e)continue;const l=n.getNextSiblings(),[c,a]=n.splitText(o);if(!1!==i(t,a?[a,...l]:l,r,null,null,!1))return c.remove(),!0}}return!1}function Ie(e,t){let n=0;const o=e.getTextContent();for(let e=0;e<t;e++)"`"===o[e]&&n++;return n%2!=0}function Le(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(Re(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function Re(e,t,n,o,r){for(let s=0;s<r;s++)if(e[t+s]!==n[o+s])return!1;return!0}exports.$convertFromMarkdownString=function(e,t=ne,n,o=!1,r=!1){const s=o?e:function(e,t=!1){const n=e.split("\n");let o=0;const r=[];for(let e=0;e<n.length;e++){const s=n[e],i=s.trimEnd(),l=r[r.length-1],c=e<n.length-1?y(s):null,a=void 0!==l&&null!==y(l);if(C.test(i))r.push(i);else if(0===o){{const e=i.match(T);if(e){o=e[1].trim().length,r.push(i);continue}}""===i||""===l||!l||m.test(l)||m.test(i)||$.test(i)||p.test(i)||h.test(i)||x.test(i)||S.test(i)||E(i)||a||!t||I.test(i)||L.test(i)||R(L).test(l)||R(I).test(l)||N.test(l)?r.push(!t&&""!==i||null!==c?s:i):r[r.length-1]=l+" "+(null===c?i:s).trimStart()}else{if(N.test(i)&&i.trim().length>=o){o=0,r.push(i);continue}r.push(s)}}return r.join("\n")}(e,r);return me(t,o)(s,n)},exports.$convertSelectionToMarkdownString=function(t=ne,n,o=!1){if(!n||e.$isRangeSelection(n)&&n.isCollapsed())return"";const r=function(t,n=!1){const o=l(t),r=[...o.multilineElement,...o.element],s=!n,i=o.textFormat.filter(e=>1===e.format.length).sort((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code")));return t=>{const l=[],c=e.$getRoot().getChildren();for(let e=0;e<c.length;e++){const a=c[e],{shouldInclude:d,markdown:f}=oe(a,t,r,i,o.textMatch,n);d&&null!=f&&l.push(s&&e>0&&!u(a)&&!u(c[e-1])?"\n".concat(f):f)}return l.join("\n")}}(t,o);return r(n)},exports.$convertToMarkdownString=function(t=ne,n,o=!1){return function(t,n=!1){const o=l(t),r=[...o.multilineElement,...o.element],s=!n,i=o.textFormat.filter(e=>1===e.format.length).sort((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code")));return t=>{const l=[],c=(t||e.$getRoot()).getChildren();for(let e=0;e<c.length;e++){const t=c[e],a=se(t,r,i,o.textMatch,n);null!=a&&l.push(s&&e>0&&!u(t)&&!u(c[e-1])?"\n".concat(a):a)}return l.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=z,exports.BOLD_ITALIC_UNDERSCORE=G,exports.BOLD_STAR=q,exports.BOLD_UNDERSCORE=Q,exports.CHECK_LIST=H,exports.CODE=D,exports.ELEMENT_TRANSFORMERS=V,exports.HEADING=F,exports.HIGHLIGHT=W,exports.INLINE_CODE=U,exports.ITALIC_STAR=Y,exports.ITALIC_UNDERSCORE=X,exports.LINK=J,exports.MULTILINE_ELEMENT_TRANSFORMERS=Z,exports.ORDERED_LIST=j,exports.QUOTE=B,exports.STRIKETHROUGH=K,exports.TEXT_FORMAT_TRANSFORMERS=ee,exports.TEXT_MATCH_TRANSFORMERS=te,exports.TRANSFORMERS=ne,exports.UNORDERED_LIST=P,exports.isTableRowDivider=E,exports.registerMarkdownShortcuts=function(t,o=ne){const r=l(o),s=r.element.filter(e=>e.triggerOnEnter),a=i(r.textFormat,({tag:e})=>e[e.length-1]),d=i(r.textMatch,({trigger:e})=>e),f=new Set([" "]);for(const e of r.textFormat)f.add(e.tag.slice(-1));for(const e of r.textMatch)void 0!==e.trigger&&f.add(e.trigger);for(const e of o){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)||Ce(173,e.getType())}}const u=(t,n,o)=>!!Se(t,n,o,r.element)||(!!Ee(t,n,o,r.multilineElement)||(!!function(e,t,n){let o=e.getTextContent();const r=n[o[t-1]];if(null==r)return!1;t<o.length&&(o=o.slice(0,t));for(const t of r){if(!t.replace||!t.regExp)continue;const n=o.match(t.regExp);if(null===n)continue;const r=n.index||0,s=r+n[0].length;let i;return 0===r?[i]=e.splitText(s):[,i]=e.splitText(r,s),i.selectNext(0,0),t.replace(i,n),!0}return!1}(n,o,d)||!!function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],l=o[i];if(!l)return!1;for(const n of l){const{tag:o}=n,l=o.length,a=s-l+1;if(l>1&&!Re(r,a,o,0,l))continue;if(" "===r[a-1])continue;const d=r[s+1];if(!1===n.intraword&&d&&!c.test(d))continue;const f=t;let u=f,g=Le(r,a,o),p=u;for(;g<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();u=p,g=Le(e,e.length,o)}if(g<0)continue;if(u===f&&g+l===a)continue;const h=u.getTextContent();if(g>0&&h[g-1]===i)continue;const x=h[g-1];if(!1===n.intraword&&x&&!c.test(x))continue;if(!n.format.includes("code")&&Ie(u,g))continue;const m=f.getTextContent(),$=m.slice(0,a)+m.slice(s+1);f.setTextContent($);const T=u===f?$:h;u.setTextContent(T.slice(0,g)+T.slice(g+l));const N=e.$getSelection(),C=e.$createRangeSelection();e.$setSelection(C);const S=s-l*(u===f?2:1)+1;C.anchor.set(u.__key,g,"text"),C.focus.set(f.__key,S,"text");for(const t of n.format)C.formatText(t,e.TEXT_TYPE_TO_FORMAT[t]);C.anchor.set(C.focus.key,C.focus.offset,C.focus.type);for(const e of n.format)C.hasFormat(e)&&C.toggleFormat(e);return e.$isRangeSelection(N)&&(C.format=N.format),!0}return!1}(n,o,a)));return e.mergeRegister(t.registerUpdateListener(({tags:o,dirtyLeaves:r,editorState:s,prevEditorState:i})=>{if(o.has(e.COLLABORATION_TAG)||o.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const l=o.has(e.COMPOSITION_END_TAG),c=s.read(e.$getSelection),a=i.read(e.$getSelection);if(!e.$isRangeSelection(a)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(a)&&!l)return;const d=c.anchor.key,g=c.anchor.offset,p=s._nodeMap.get(d);if(e.$isTextNode(p)&&r.has(d)&&(l||1===g||!(g>a.anchor.offset+1))){if(l){const e=s.read(()=>p.getTextContent())[g-1];if(!f.has(e))return}t.update(()=>{if(!he(p))return;const t=p.getParent();null===t||n.$isCodeNode(t)||u(t,p,c.anchor.offset)&&e.$addUpdateTag(e.HISTORY_PUSH_TAG)})}}),t.registerCommand(e.KEY_ENTER_COMMAND,t=>{if(null!==t&&t.shiftKey)return!1;const o=e.$getSelection();if(!e.$isRangeSelection(o)||!o.isCollapsed())return!1;const i=o.anchor.offset,l=o.anchor.getNode();if(!e.$isTextNode(l)||!he(l))return!1;const c=l.getParent();if(null===c||n.$isCodeNode(c))return!1;return i===l.getTextContent().length&&(!(!Ee(c,l,i,r.multilineElement,!0)&&!Se(c,l,i,s,!0))&&(null!==t&&t.preventDefault(),!0))},e.COMMAND_PRIORITY_LOW))};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isParagraphNode as t,$isTextNode as e,$setState as n,$createTextNode as o,$getState as r,$findMatchingParent as s,$createLineBreakNode as i,createState as l,$isLineBreakNode as c,$getRoot as f,$isElementNode as a,$isDecoratorNode as u,$getSelection as d,$createParagraphNode as g,$createTabNode as h,mergeRegister as p,COLLABORATION_TAG as x,HISTORIC_TAG as m,COMPOSITION_END_TAG as C,$isRangeSelection as I,$addUpdateTag as T,HISTORY_PUSH_TAG as E,KEY_ENTER_COMMAND as $,COMMAND_PRIORITY_LOW as v,$isRootOrShadowRoot as y,$createRangeSelection as S,$setSelection as b,TEXT_TYPE_TO_FORMAT as w}from"lexical";import{$sliceSelectedTextNodeContent as k}from"@lexical/selection";import{CodeNode as N,$createCodeNode as F,$isCodeNode as L}from"@lexical/code-core";import{LinkNode as O,$isLinkNode as M,$createLinkNode as _,$isAutoLinkNode as B}from"@lexical/link";import{ListNode as R,ListItemNode as j,$isListNode as P,$createListItemNode as A,$createListNode as W,$isListItemNode as z}from"@lexical/list";import{HeadingNode as U,QuoteNode as D,$isHeadingNode as H,$isQuoteNode as K,$createQuoteNode as q,$createHeadingNode as G}from"@lexical/rich-text";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=/\s/,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,st=/^(#{1,6})\s/,it=/^>\s/,lt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,ct=/^[ \t]*`{3,}$/,ft=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,at=/^(?:\|)(.+)(?:\|)\s?$/;function ut(t){if("|"!==t[0])return!1;const{length:e}=t;let n=1,o=0;for(;n<e;){let e=n;for(" "===t[e]&&e++,":"===t[e]&&e++;"-"===t[e];)e++;if(":"===t[e]&&e++," "===t[e]&&e++,"|"!==t[e])break;o++,n=e+1}return o>0&&(n===e||n===e-1&&/\s/.test(t[n]))}const dt=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,gt=/^<\/[a-z_][\w-]*\s*>/i,ht=t=>new RegExp(`(?:${t.source})$`,t.flags),pt=/* @__PURE__ */l("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),xt=/* @__PURE__ */l("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),mt=/* @__PURE__ */l("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 It(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e(r))return null;const s=r.getTextContent(),i=Ct(s);if(null!==i){const[t,e]=i;return r.setTextContent(t),e}return/^ {2,}$/.test(s)&&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(""),s):null}function Tt(t){const e=i(),o=It(t);return null!==o&&n(e,mt,o),e}const Et=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};const $t=t=>(e,o,r,s)=>{const i=e.getPreviousSibling(),l=e.getNextSibling(),c=A("check"===t?"x"===r[3]:void 0),f=r[0].trim()[0],a="bullet"!==t&&"check"!==t||f!==pt.parse(f)?void 0:f;if(P(l)&&l.getListType()===t){a&&n(l,pt,a);const o=l.getFirstChild();null!==o?o.insertBefore(c):l.append(c),"number"===t&&l.setStart(Number(r[2])),e.remove()}else if(P(i)&&i.getListType()===t)a&&n(i,pt,a),i.append(c),e.remove();else{const o=W(t,"number"===t?Number(r[2]):void 0);a&&n(o,pt,a),o.append(c),e.replace(o)}c.append(...o),s||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)},vt=(t,e,n,o)=>{const s=[],i=t.getChildren();let l=0;for(const c of i)if(z(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(P(t)){const r=vt(t,e,n+1,o);r&&s.push(r);continue}}if(o&&!c.getChildren().some(t=>t.isSelected(o)))continue;const i=" ".repeat(4*n),f=t.getListType(),a=r(t,pt),u="number"===f?`${t.getStart()+l}. `:"check"===f?`${a} [${c.getChecked()?"x":" "}] `:a+" ";let d=e(c);"number"!==f&&(d=d.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),s.push(i+u+d),l++}return s.join("\n")},yt={dependencies:[U],export:(t,e)=>{if(!H(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:st,replace:Et(t=>{const e="h"+t[1].length;return G(e)}),triggerOnEnter:!0,type:"element"},St={dependencies:[D],export:(t,e)=>{if(!K(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:it,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(K(n))return n.splice(n.getChildrenSize(),0,[Tt(n),...e]),void t.remove()}const r=q();r.append(...e),t.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},bt={dependencies:[N],export:t=>{if(!L(t))return null;const e=t.getTextContent();let n=r(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],s=r.trim().length,i=t[n],l=o.index+r.length,c=i.slice(l),f=new RegExp(`\`{${s},}$`);if(f.test(c)){const t=c.match(f),r=c.slice(0,c.lastIndexOf(t[0])),s=[...o];return s[2]="",bt.replace(e,null,s,t,[r],!0),[!0,n]}const a=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(a.test(s)){const l=s.match(a),c=t.slice(n+1,r),f=i.slice(o[0].length);return f.length>0&&c.unshift(f),bt.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),d=i.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,r,s,i,l)=>{let c,f;const a=r[1]?r[1].trim():"```",u=r[2]||void 0;if(!e&&i){if(1===i.length)s?(c=F(u),f=i[0]):(c=F(u),f=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=F(u),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();f=i.join("\n")}n(c,xt,a);const e=o(f);c.append(e),t.append(c)}else e&&Et(t=>F(t?t[2]:void 0))(t,e,r,l)},type:"multiline-element"},wt={dependencies:[R,j],export:(t,e,n)=>P(t)?vt(t,e,0,n):null,regExp:ot,replace:$t("bullet"),triggerOnEnter:!0,type:"element"},kt={dependencies:[R,j],export:(t,e,n)=>P(t)?vt(t,e,0,n):null,regExp:rt,replace:$t("check"),triggerOnEnter:!0,type:"element"},Nt={dependencies:[R,j],export:(t,e,n)=>P(t)?vt(t,e,0,n):null,regExp:nt,replace:$t("number"),triggerOnEnter:!0,type:"element"},Ft={format:["code"],tag:"`",type:"text-format"};const 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"},_t={format:["bold"],tag:"**",type:"text-format"},Bt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Rt={format:["strikethrough"],tag:"~~",type:"text-format"},jt={format:["italic"],tag:"*",type:"text-format"},Pt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},At={dependencies:[O],export:(t,e,n)=>{if(!M(t)||B(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,M))return;const[,n,r,i]=e,l=null!=r?et(r):void 0,c=null!=i?et(i):void 0,f=_(l,{title:c}),a=n.split("[").length-1,u=n.split("]").length-1;let d=n,g="";if(a<u)return;if(a>u){const t=n.split("[");g="["+t[0],d=t.slice(1).join("[")}const h=o(d);return h.setFormat(t.getFormat()),f.append(h),t.replace(f),g&&f.insertBefore(o(g)),h},trigger:")",type:"text-match"},Wt=[yt,St,wt,Nt],zt=[bt],Ut=[Ft,Ot,Mt,_t,Bt,Lt,jt,Pt,Rt],Dt=[At],Ht=[...Wt,...zt,...Ut,...Dt];function Kt(t,e,n,o,r,s){let i=t.isSelected(e);for(const l of n){if(!l.export)continue;const n=l.export(t,t=>qt(t,e,o,r,s).markdown,e);if(null!=n){if(!i&&a(t)){qt(t,e,o,r,s).shouldInclude&&(i=!0)}return{markdown:n,shouldInclude:i}}}if(a(t)){const n=qt(t,e,o,r,s);return{markdown:n.markdown,shouldInclude:i||n.shouldInclude}}return u(t)?{markdown:t.getTextContent(),shouldInclude:i}:{markdown:null,shouldInclude:i}}function qt(t,n,o,r,s,i,l){const f=[],d=t.getChildren();let g=!1;i||(i=[]),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,s,i,[...l,...i]).markdown,(t,e)=>Vt(t,k(n,t,"clone").getTextContent(),o,i,l,s));if(null!=c){!d&&a(t)&&t.getChildren().some(t=>t.isSelected(n))&&t.extractWithChild(t,n,"html")&&(d=!0),d&&(f.push(c),g=!0);continue t}}if(c(t))d&&(f.push(Qt(t)),g=!0);else if(e(t)){if(d){const e=k(n,t,"clone");f.push(Vt(t,e.getTextContent(),o,i,l,s)),g=!0}}else if(a(t)){const e=qt(t,n,o,r,s,i,l);!d&&e.shouldInclude&&t.extractWithChild(t,n,"html")&&(d=!0),(d||e.shouldInclude)&&(f.push(e.markdown),g=!0)}else u(t)&&d&&(f.push(t.getTextContent()),g=!0)}return{markdown:f.join(""),shouldInclude:g}}function Gt(t,e,n,o,r){for(const s of e){if(!s.export)continue;const e=s.export(t,t=>Jt(t,n,o,void 0,void 0,r));if(null!=e)return e}return a(t)?Jt(t,n,o,void 0,void 0,r):u(t)?t.getTextContent():null}function Jt(t,n,o,r,s,i=!1){const l=[],f=t.getChildren();r||(r=[]),s||(s=[]);t:for(const t of f){for(const e of o){if(!e.export)continue;const c=e.export(t,t=>Jt(t,n,o,r,[...s,...r],i),(t,e)=>Vt(t,e,n,r,s,i));if(null!=c){l.push(c);continue t}}c(t)?l.push(Qt(t)):e(t)?l.push(Vt(t,t.getTextContent(),n,r,s,i)):a(t)?l.push(Jt(t,n,o,r,s,i)):u(t)&&l.push(t.getTextContent())}return l.join("")}function Qt(t){return r(t,mt)+"\n"}function Vt(t,e,n,o,r,s=!1){const i=t.hasFormat("code");let l,c,f,a,u=e;if(i||(u=s?u.replace(/([*_`~])/g,"\\$1"):u.replace(/([*_`~\\])/g,"\\$1")),i){const{fence:t,padded:n}=function(t){const e=t.match(/`+/g),n=e?Math.max(...e.map(t=>t.length)):0;return{fence:"`".repeat(n+1),padded:0===t.length||t.includes("`")||/^\s/.test(t)&&/\s$/.test(t)?` ${t} `:t}}(e);l="",f="",c=t+n+t,a=!1}else{const t=u.match(/^(\s*)(.*?)(\s*)$/s)||["","",u,""];l=t[1],c=t[2],f=t[3],a=""===c}let d="",g="",h="";const p=Xt(t,!0),x=Xt(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;"code"!==n&&(Zt(t,n)&&!m.has(n)&&(m.add(n),Zt(p,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),s=Yt(x,o[e].format);if(n&&s)continue;const i=[...o];for(;i.length>e;){const t=i.pop();r&&t&&r.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?s||(h+=t.tag):g+=t.tag),o.pop())}break}return a&&!t.hasFormat("code")?g+u:g+l+d+c+h+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.transformersByTag["`"],r=[];let s=null;if(o){const t=function(t){const e=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},n=[];let o=0;for(;o<t.length;)if("`"===t[o]){let e=1;for(;o+e<t.length&&"`"===t[o+e];)e++;n.push({index:o,length:e}),o+=e}else o++;const r=[];let s=0;for(;s<n.length;){const o=n[s];if(e(o.index)){s++;continue}let i=-1;for(let t=s+1;t<n.length;t++)if(n[t].length===o.length){i=t;break}if(-1===i){s++;continue}const l=n[i];let c=t.slice(o.index+o.length,l.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),r.push({content:c,endIndex:l.index+l.length,startIndex:o.index}),s=i+1}return r}(n);for(const e of t)s||(s={content:e.content,endIndex:e.endIndex,startIndex:e.startIndex,tag:"`"}),r.push({end:e.endIndex,start:e.startIndex})}const i=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),s=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},i=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)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=ee(e,t,l,n,!0),f=ee(e,t,l,n,!1);(c||f)&&o.push({active:!0,canClose:f,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,r),l=i.length>0?function(t,e,n){const o={};let r=0,s=null;for(;r<e.length;){const i=e[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const l=`${i.char}${i.canOpen}`,c=o[l]??-1;let f=!1;for(let o=r-1;o>c;o--){const l=e[o];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if(l.canClose||i.canOpen){if((l.originalLength+i.originalLength)%3==0&&l.originalLength%3!=0&&i.originalLength%3!=0)continue}const c=Math.min(l.length,i.length),a=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!a)continue;f=!0;const u=a.length,d={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:a};(!s||d.startIndex<s.startIndex||d.startIndex===s.startIndex&&d.endIndex>s.endIndex)&&(s=d);for(let t=o+1;t<r;t++)e[t].active=!1;l.length-=u,i.length-=u,l.active=l.length>0,i.length>0?i.index+=u:(i.active=!1,r++);break}f||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,i,e):null;let c=null,f=null;if(s&&l?l.startIndex<=s.startIndex&&l.endIndex>=s.endIndex?(c=l,f=e.transformersByTag[l.tag]):(c=s,f=o):s?(c=s,f=o):l&&(c=l,f=e.transformersByTag[l.tag]),!c||!f)return null;const a=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return a.index=c.startIndex,a.input=n,{endIndex:c.endIndex,isCodeSpan:f===o,match:a,startIndex:c.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],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!X.test(i)&&(!Y.test(i)||(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,s,i;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,s=t,i=e)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(t,n);if(o&&r&&(o.isCodeSpan?r.startIndex<=o.startIndex&&r.endIndex>=o.endIndex?o=null:r=null: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 s=t.getTextContent();let i,l,c;if(r[0]===s?i=t:0===e?[i,l]=t.splitText(n):[c,i,l]=t.splitText(e,n),i.setTextContent(r[2]),o)for(const t of o.format)i.hasFormat(t)||i.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(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 s,i,l;return 0===e?[s,i]=t.splitText(n):[l,s,i]=t.splitText(e,n),o.replace?{nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,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 s=et(t.getTextContent());t.setTextContent(s)}function se(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 s=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===t.length?n[t]="`"===t?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[t]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:e}}(n.textFormat);return(t,r)=>{const s=t.split("\n"),i=s.length,l=r||f();l.clear();for(let t=0;t<i;t++){const r=s[t],[i,c]=ie(s,t,n.multilineElement,l);i?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(a(t))for(const e of t.getAllTextNodes())ce(e);null!==d()&&l.selectStart()}}function ie(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=r,c=t[e].match(i);if(!c)continue;if(n){const s=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===s)continue;if(s)return s}const f="object"==typeof s&&"regExp"in s?s.regExp:s,a=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const d=t.length;for(;u<d;){const n=f?t[u].match(f):null;if(!n&&(!a||a&&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,r,i,l,c){const f=o(e),a=g();a.append(f),n.append(a);for(const{regExp:t,replace:n}of r){const o=e.match(t);if(o&&(f.setTextContent(e.slice(o[0].length)),!1!==n(a,[f],o,!0)))break}if(re(f,i,l),a.isAttached()&&e.length>0){const e=a.getPreviousSibling();if(!c&&(t(e)||K(e)||P(e))){let t=e;if(P(e)){const n=e.getLastDescendant();t=null==n?null:s(n,z)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[Tt(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(h())})}function fe(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 ae(t,e,n,o,r){const s=t.getParent();if(!y(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!r&&" "!==i[n-1])return!1;for(const{regExp:s,replace:l}of o){const o=i.match(s),c=r||o&&o[0].endsWith(" ")?n:n-1;if(o&&o[0].length===c){const r=e.getNextSiblings(),[s,i]=e.splitText(n);if(!1!==l(t,i?[i,...r]:r,o,!1))return s.remove(),!0}}return!1}function ue(t,e,n,o,r){const s=t.getParent();if(!y(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!r&&" "!==i[n-1])return!1;for(const{regExpStart:s,replace:l,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=i.match(s);if(o){const s=r||o[0].endsWith(" ")?n:n-1;if(o[0].length!==s)continue;const i=e.getNextSiblings(),[c,f]=e.splitText(n);if(!1!==l(t,f?[f,...i]:i,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(he(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function he(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function pe(t,n=Ht){const o=Q(n),r=o.element.filter(t=>t.triggerOnEnter),s=J(o.textFormat,({tag:t})=>t[t.length-1]),i=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)||fe(173,e.getType())}}const f=(t,n,r)=>!!ae(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,s=r+n[0].length;let i;return 0===r?[i]=t.splitText(s):[,i]=t.splitText(r,s),i.selectNext(0,0),e.replace(i,n),!0}return!1}(n,r,i)||!!function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],l=o[i];if(!l)return!1;for(const n of l){const{tag:o}=n,l=o.length,f=s-l+1;if(l>1&&!he(r,f,o,0,l))continue;if(" "===r[f-1])continue;const a=r[s+1];if(!1===n.intraword&&a&&!V.test(a))continue;const u=t;let g=u,h=ge(r,f,o),p=g;for(;h<0&&(p=p.getPreviousSibling())&&!c(p);)if(e(p)){if(p.hasFormat("code"))continue;const t=p.getTextContent();g=p,h=ge(t,t.length,o)}if(h<0)continue;if(g===u&&h+l===f)continue;const x=g.getTextContent();if(h>0&&x[h-1]===i)continue;const m=x[h-1];if(!1===n.intraword&&m&&!V.test(m))continue;if(!n.format.includes("code")&&de(g,h))continue;const C=u.getTextContent(),T=C.slice(0,f)+C.slice(s+1);u.setTextContent(T);const E=g===u?T:x;g.setTextContent(E.slice(0,h)+E.slice(h+l));const $=d(),v=S();b(v);const y=s-l*(g===u?2:1)+1;v.anchor.set(g.__key,h,"text"),v.focus.set(u.__key,y,"text");for(const t of n.format)v.formatText(t,w[t]);v.anchor.set(v.focus.key,v.focus.offset,v.focus.type);for(const t of n.format)v.hasFormat(t)&&v.toggleFormat(t);return I($)&&(v.format=$.format),!0}return!1}(n,r,s)));return p(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:s})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const i=n.has(C),c=r.read(d),a=s.read(d);if(!I(a)||!I(c)||!c.isCollapsed()||c.is(a)&&!i)return;const u=c.anchor.key,g=c.anchor.offset,h=r._nodeMap.get(u);if(e(h)&&o.has(u)&&(i||1===g||!(g>a.anchor.offset+1))){if(i){const t=r.read(()=>h.getTextContent())[g-1];if(!l.has(t))return}t.update(()=>{if(!oe(h))return;const t=h.getParent();null===t||L(t)||f(t,h,c.anchor.offset)&&T(E)})}}),t.registerCommand($,t=>{if(null!==t&&t.shiftKey)return!1;const n=d();if(!I(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e(i)||!oe(i))return!1;const l=i.getParent();if(null===l||L(l))return!1;return s===i.getTextContent().length&&(!(!ue(l,i,s,o.multilineElement,!0)&&!ae(l,i,s,r,!0))&&(null!==t&&t.preventDefault(),!0))},v))}function xe(t,e=Ht,n,o=!1,r=!1){const s=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 s=n[t],i=s.trimEnd(),l=r[r.length-1],c=t<n.length-1?Ct(s):null,f=void 0!==l&&null!==Ct(l);ft.test(i)?r.push(i):lt.test(i)||ct.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===l||!l||st.test(l)||st.test(i)||it.test(i)||nt.test(i)||ot.test(i)||rt.test(i)||at.test(i)||ut(i)||f||!e||dt.test(i)||gt.test(i)||ht(gt).test(l)||ht(dt).test(l)||ct.test(l)?r.push(!e&&""!==i||null!==c?s:i):r[r.length-1]=l+" "+(null===c?i:s).trimStart()}return r.join("\n")}(t,r);return se(e,o)(s,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,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[],l=(t||f()).getChildren();for(let t=0;t<l.length;t++){const c=l[t],f=Gt(c,o,s,n.textMatch,e);null!=f&&i.push(r&&t>0&&!tt(c)&&!tt(l[t-1])?"\n".concat(f):f)}return i.join("\n")}}(t,n);return o(e)}function Ce(t=Ht,e,n=!1){if(!e||I(e)&&e.isCollapsed())return"";const o=function(t,e=!1){const n=Q(t),o=[...n.multilineElement,...n.element],r=!e,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[],l=f().getChildren();for(let c=0;c<l.length;c++){const f=l[c],{shouldInclude:a,markdown:u}=Kt(f,t,o,s,n.textMatch,e);a&&null!=u&&i.push(r&&c>0&&!tt(f)&&!tt(l[c-1])?"\n".concat(u):u)}return i.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,_t as BOLD_STAR,Bt as BOLD_UNDERSCORE,kt as CHECK_LIST,bt as CODE,Wt as ELEMENT_TRANSFORMERS,yt as HEADING,Lt as HIGHLIGHT,Ft as INLINE_CODE,jt as ITALIC_STAR,Pt as ITALIC_UNDERSCORE,At as LINK,zt as MULTILINE_ELEMENT_TRANSFORMERS,Nt as ORDERED_LIST,St as QUOTE,Rt as STRIKETHROUGH,Ut as TEXT_FORMAT_TRANSFORMERS,Dt as TEXT_MATCH_TRANSFORMERS,Ht as TRANSFORMERS,wt as UNORDERED_LIST,ut as isTableRowDivider,pe as registerMarkdownShortcuts};
|
|
9
|
+
import{$isParagraphNode as t,$isTextNode as e,$setState as n,$createTextNode as o,$getState as r,$findMatchingParent as s,$createLineBreakNode as i,createState as l,$isLineBreakNode as c,$getRoot as f,$isElementNode as a,$isDecoratorNode as u,$getSelection as d,$createParagraphNode as g,$createTabNode as h,mergeRegister as p,COLLABORATION_TAG as x,HISTORIC_TAG as m,COMPOSITION_END_TAG as C,$isRangeSelection as I,$addUpdateTag as T,HISTORY_PUSH_TAG as E,KEY_ENTER_COMMAND as $,COMMAND_PRIORITY_LOW as v,$isRootOrShadowRoot as y,$createRangeSelection as S,$setSelection as b,TEXT_TYPE_TO_FORMAT as w}from"lexical";import{$sliceSelectedTextNodeContent as k}from"@lexical/selection";import{CodeNode as N,$createCodeNode as F,$isCodeNode as L}from"@lexical/code-core";import{LinkNode as O,$isLinkNode as M,$createLinkNode as _,$isAutoLinkNode as B}from"@lexical/link";import{ListNode as R,ListItemNode as j,$isListNode as P,$createListItemNode as A,$createListNode as W,$isListItemNode as z}from"@lexical/list";import{HeadingNode as U,QuoteNode as D,$isHeadingNode as H,$isQuoteNode as K,$createQuoteNode as q,$createHeadingNode as G}from"@lexical/rich-text";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=/\s/,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,st=/^(#{1,6})\s/,it=/^>\s/,lt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,ct=/^[ \t]*`{3,}$/,ft=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,at=/^(?:\|)(.+)(?:\|)\s?$/;function ut(t){if("|"!==t[0])return!1;const{length:e}=t;let n=1,o=0;for(;n<e;){let e=n;for(" "===t[e]&&e++,":"===t[e]&&e++;"-"===t[e];)e++;if(":"===t[e]&&e++," "===t[e]&&e++,"|"!==t[e])break;o++,n=e+1}return o>0&&(n===e||n===e-1&&/\s/.test(t[n]))}const dt=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,gt=/^<\/[a-z_][\w-]*\s*>/i,ht=t=>new RegExp(`(?:${t.source})$`,t.flags),pt=/* @__PURE__ */l("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),xt=/* @__PURE__ */l("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),mt=/* @__PURE__ */l("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 It(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e(r))return null;const s=r.getTextContent(),i=Ct(s);if(null!==i){const[t,e]=i;return r.setTextContent(t),e}return/^ {2,}$/.test(s)&&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(""),s):null}function Tt(t){const e=i(),o=It(t);return null!==o&&n(e,mt,o),e}const Et=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};const $t=t=>(e,o,r,s)=>{const i=e.getPreviousSibling(),l=e.getNextSibling(),c=A("check"===t?"x"===r[3]:void 0),f=r[0].trim()[0],a="bullet"!==t&&"check"!==t||f!==pt.parse(f)?void 0:f;if(P(l)&&l.getListType()===t){a&&n(l,pt,a);const o=l.getFirstChild();null!==o?o.insertBefore(c):l.append(c),"number"===t&&l.setStart(Number(r[2])),e.remove()}else if(P(i)&&i.getListType()===t)a&&n(i,pt,a),i.append(c),e.remove();else{const o=W(t,"number"===t?Number(r[2]):void 0);a&&n(o,pt,a),o.append(c),e.replace(o)}c.append(...o),s||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)},vt=(t,e,n,o)=>{const s=[],i=t.getChildren();let l=0;for(const c of i)if(z(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(P(t)){const r=vt(t,e,n+1,o);r&&s.push(r);continue}}if(o&&!c.getChildren().some(t=>t.isSelected(o)))continue;const i=" ".repeat(4*n),f=t.getListType(),a=r(t,pt),u="number"===f?`${t.getStart()+l}. `:"check"===f?`${a} [${c.getChecked()?"x":" "}] `:a+" ";let d=e(c);"number"!==f&&(d=d.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),s.push(i+u+d),l++}return s.join("\n")},yt={dependencies:[U],export:(t,e)=>{if(!H(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:st,replace:Et(t=>{const e="h"+t[1].length;return G(e)}),triggerOnEnter:!0,type:"element"},St={dependencies:[D],export:(t,e)=>{if(!K(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:it,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(K(n))return n.splice(n.getChildrenSize(),0,[Tt(n),...e]),void t.remove()}const r=q();r.append(...e),t.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},bt={dependencies:[N],export:t=>{if(!L(t))return null;const e=t.getTextContent();let n=r(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],s=r.trim().length,i=t[n],l=o.index+r.length,c=i.slice(l),f=new RegExp(`\`{${s},}$`);if(f.test(c)){const t=c.match(f),r=c.slice(0,c.lastIndexOf(t[0])),s=[...o];return s[2]="",bt.replace(e,null,s,t,[r],!0),[!0,n]}const a=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(a.test(s)){const l=s.match(a),c=t.slice(n+1,r),f=i.slice(o[0].length);return f.length>0&&c.unshift(f),bt.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),d=i.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,r,s,i,l)=>{let c,f;const a=r[1]?r[1].trim():"```",u=r[2]||void 0;if(!e&&i){if(1===i.length)s?(c=F(u),f=i[0]):(c=F(u),f=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=F(u),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();f=i.join("\n")}n(c,xt,a);const e=o(f);c.append(e),t.append(c)}else e&&Et(t=>F(t?t[2]:void 0))(t,e,r,l)},type:"multiline-element"},wt={dependencies:[R,j],export:(t,e,n)=>P(t)?vt(t,e,0,n):null,regExp:ot,replace:$t("bullet"),triggerOnEnter:!0,type:"element"},kt={dependencies:[R,j],export:(t,e,n)=>P(t)?vt(t,e,0,n):null,regExp:rt,replace:$t("check"),triggerOnEnter:!0,type:"element"},Nt={dependencies:[R,j],export:(t,e,n)=>P(t)?vt(t,e,0,n):null,regExp:nt,replace:$t("number"),triggerOnEnter:!0,type:"element"},Ft={format:["code"],tag:"`",type:"text-format"};const 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"},_t={format:["bold"],tag:"**",type:"text-format"},Bt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Rt={format:["strikethrough"],tag:"~~",type:"text-format"},jt={format:["italic"],tag:"*",type:"text-format"},Pt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},At={dependencies:[O],export:(t,e,n)=>{if(!M(t)||B(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,M))return;const[,n,r,i]=e,l=null!=r?et(r):void 0,c=null!=i?et(i):void 0,f=_(l,{title:c}),a=n.split("[").length-1,u=n.split("]").length-1;let d=n,g="";if(a<u)return;if(a>u){const t=n.split("[");g="["+t[0],d=t.slice(1).join("[")}const h=o(d);return h.setFormat(t.getFormat()),f.append(h),t.replace(f),g&&f.insertBefore(o(g)),h},trigger:")",type:"text-match"},Wt=[yt,St,wt,Nt],zt=[bt],Ut=[Ft,Ot,Mt,_t,Bt,Lt,jt,Pt,Rt],Dt=[At],Ht=[...Wt,...zt,...Ut,...Dt];function Kt(t,e,n,o,r,s){let i=t.isSelected(e);for(const l of n){if(!l.export)continue;const n=l.export(t,t=>qt(t,e,o,r,s).markdown,e);if(null!=n){if(!i&&a(t)){qt(t,e,o,r,s).shouldInclude&&(i=!0)}return{markdown:n,shouldInclude:i}}}if(a(t)){const n=qt(t,e,o,r,s);return{markdown:n.markdown,shouldInclude:i||n.shouldInclude}}return u(t)?{markdown:t.getTextContent(),shouldInclude:i}:{markdown:null,shouldInclude:i}}function qt(t,n,o,r,s,i,l){const f=[],d=t.getChildren();let g=!1;i||(i=[]),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,s,i,[...l,...i]).markdown,(t,e)=>Vt(t,k(n,t,"clone").getTextContent(),o,i,l,s));if(null!=c){!d&&a(t)&&t.getChildren().some(t=>t.isSelected(n))&&t.extractWithChild(t,n,"html")&&(d=!0),d&&(f.push(c),g=!0);continue t}}if(c(t))d&&(f.push(Qt(t)),g=!0);else if(e(t)){if(d){const e=k(n,t,"clone");f.push(Vt(t,e.getTextContent(),o,i,l,s)),g=!0}}else if(a(t)){const e=qt(t,n,o,r,s,i,l);!d&&e.shouldInclude&&t.extractWithChild(t,n,"html")&&(d=!0),(d||e.shouldInclude)&&(f.push(e.markdown),g=!0)}else u(t)&&d&&(f.push(t.getTextContent()),g=!0)}return{markdown:f.join(""),shouldInclude:g}}function Gt(t,e,n,o,r){for(const s of e){if(!s.export)continue;const e=s.export(t,t=>Jt(t,n,o,void 0,void 0,r));if(null!=e)return e}return a(t)?Jt(t,n,o,void 0,void 0,r):u(t)?t.getTextContent():null}function Jt(t,n,o,r,s,i=!1){const l=[],f=t.getChildren();r||(r=[]),s||(s=[]);t:for(const t of f){for(const e of o){if(!e.export)continue;const c=e.export(t,t=>Jt(t,n,o,r,[...s,...r],i),(t,e)=>Vt(t,e,n,r,s,i));if(null!=c){l.push(c);continue t}}c(t)?l.push(Qt(t)):e(t)?l.push(Vt(t,t.getTextContent(),n,r,s,i)):a(t)?l.push(Jt(t,n,o,r,s,i)):u(t)&&l.push(t.getTextContent())}return l.join("")}function Qt(t){return r(t,mt)+"\n"}function Vt(t,e,n,o,r,s=!1){const i=t.hasFormat("code");let l,c,f,a,u=e;if(i||(u=s?u.replace(/([*_`~])/g,"\\$1"):u.replace(/([*_`~\\])/g,"\\$1")),i){const{fence:t,padded:n}=function(t){const e=t.match(/`+/g),n=e?Math.max(...e.map(t=>t.length)):0;return{fence:"`".repeat(n+1),padded:0===t.length||t.includes("`")||/^\s/.test(t)&&/\s$/.test(t)?` ${t} `:t}}(e);l="",f="",c=t+n+t,a=!1}else{const t=u.match(/^(\s*)(.*?)(\s*)$/s)||["","",u,""];l=t[1],c=t[2],f=t[3],a=""===c}let d="",g="",h="";const p=Xt(t,!0),x=Xt(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;"code"!==n&&(Zt(t,n)&&!m.has(n)&&(m.add(n),Zt(p,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),s=Yt(x,o[e].format);if(n&&s)continue;const i=[...o];for(;i.length>e;){const t=i.pop();r&&t&&r.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?s||(h+=t.tag):g+=t.tag),o.pop())}break}return a&&!t.hasFormat("code")?g+u:g+l+d+c+h+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.transformersByTag["`"],r=[];let s=null;if(o){const t=function(t){const e=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},n=[];let o=0;for(;o<t.length;)if("`"===t[o]){let e=1;for(;o+e<t.length&&"`"===t[o+e];)e++;n.push({index:o,length:e}),o+=e}else o++;const r=[];let s=0;for(;s<n.length;){const o=n[s];if(e(o.index)){s++;continue}let i=-1;for(let t=s+1;t<n.length;t++)if(n[t].length===o.length){i=t;break}if(-1===i){s++;continue}const l=n[i];let c=t.slice(o.index+o.length,l.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),r.push({content:c,endIndex:l.index+l.length,startIndex:o.index}),s=i+1}return r}(n);for(const e of t)s||(s={content:e.content,endIndex:e.endIndex,startIndex:e.startIndex,tag:"`"}),r.push({end:e.endIndex,start:e.startIndex})}const i=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),s=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},i=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)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=ee(e,t,l,n,!0),f=ee(e,t,l,n,!1);(c||f)&&o.push({active:!0,canClose:f,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,r),l=i.length>0?function(t,e,n){const o={};let r=0,s=null;for(;r<e.length;){const i=e[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const l=`${i.char}${i.canOpen}`,c=o[l]??-1;let f=!1;for(let o=r-1;o>c;o--){const l=e[o];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if(l.canClose||i.canOpen){if((l.originalLength+i.originalLength)%3==0&&l.originalLength%3!=0&&i.originalLength%3!=0)continue}const c=Math.min(l.length,i.length),a=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!a)continue;f=!0;const u=a.length,d={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:a};(!s||d.startIndex<s.startIndex||d.startIndex===s.startIndex&&d.endIndex>s.endIndex)&&(s=d);for(let t=o+1;t<r;t++)e[t].active=!1;l.length-=u,i.length-=u,l.active=l.length>0,i.length>0?i.index+=u:(i.active=!1,r++);break}f||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,i,e):null;let c=null,f=null;if(s&&l?l.startIndex<=s.startIndex&&l.endIndex>=s.endIndex?(c=l,f=e.transformersByTag[l.tag]):(c=s,f=o):s?(c=s,f=o):l&&(c=l,f=e.transformersByTag[l.tag]),!c||!f)return null;const a=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return a.index=c.startIndex,a.input=n,{endIndex:c.endIndex,isCodeSpan:f===o,match:a,startIndex:c.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],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!X.test(i)&&(!Y.test(i)||(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,s,i;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,s=t,i=e)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(t,n);if(o&&r&&(o.isCodeSpan?r.startIndex<=o.startIndex&&r.endIndex>=o.endIndex?o=null:r=null: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 s=t.getTextContent();let i,l,c;if(r[0]===s?i=t:0===e?[i,l]=t.splitText(n):[c,i,l]=t.splitText(e,n),i.setTextContent(r[2]),o)for(const t of o.format)i.hasFormat(t)||i.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(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 s,i,l;return 0===e?[s,i]=t.splitText(n):[l,s,i]=t.splitText(e,n),o.replace?{nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,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 s=et(t.getTextContent());t.setTextContent(s)}function se(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 s=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===t.length?n[t]="`"===t?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[t]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:e}}(n.textFormat);return(t,r)=>{const s=t.split("\n"),i=s.length,l=r||f();l.clear();for(let t=0;t<i;t++){const r=s[t],[i,c]=ie(s,t,n.multilineElement,l);i?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(a(t))for(const e of t.getAllTextNodes())ce(e);null!==d()&&l.selectStart()}}function ie(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=r,c=t[e].match(i);if(!c)continue;if(n){const s=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===s)continue;if(s)return s}const f="object"==typeof s&&"regExp"in s?s.regExp:s,a=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const d=t.length;for(;u<d;){const n=f?t[u].match(f):null;if(!n&&(!a||a&&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,r,i,l,c){const f=o(e),a=g();a.append(f),n.append(a);for(const{regExp:t,replace:n}of r){const o=e.match(t);if(o&&(f.setTextContent(e.slice(o[0].length)),!1!==n(a,[f],o,!0)))break}if(re(f,i,l),a.isAttached()&&e.length>0){const e=a.getPreviousSibling();if(!c&&(t(e)||K(e)||P(e))){let t=e;if(P(e)){const n=e.getLastDescendant();t=null==n?null:s(n,z)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[Tt(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(h())})}function fe(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 ae(t,e,n,o,r){const s=t.getParent();if(!y(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!r&&" "!==i[n-1])return!1;for(const{regExp:s,replace:l}of o){const o=i.match(s),c=r||o&&o[0].endsWith(" ")?n:n-1;if(o&&o[0].length===c){const r=e.getNextSiblings(),[s,i]=e.splitText(n);if(!1!==l(t,i?[i,...r]:r,o,!1))return s.remove(),!0}}return!1}function ue(t,e,n,o,r){const s=t.getParent();if(!y(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!r&&" "!==i[n-1])return!1;for(const{regExpStart:s,replace:l,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=i.match(s);if(o){const s=r||o[0].endsWith(" ")?n:n-1;if(o[0].length!==s)continue;const i=e.getNextSiblings(),[c,f]=e.splitText(n);if(!1!==l(t,f?[f,...i]:i,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(he(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function he(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function pe(t,n=Ht){const o=Q(n),r=o.element.filter(t=>t.triggerOnEnter),s=J(o.textFormat,({tag:t})=>t[t.length-1]),i=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)||fe(173,e.getType())}}const f=(t,n,r)=>!!ae(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,s=r+n[0].length;let i;return 0===r?[i]=t.splitText(s):[,i]=t.splitText(r,s),i.selectNext(0,0),e.replace(i,n),!0}return!1}(n,r,i)||!!function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],l=o[i];if(!l)return!1;for(const n of l){const{tag:o}=n,l=o.length,f=s-l+1;if(l>1&&!he(r,f,o,0,l))continue;if(" "===r[f-1])continue;const a=r[s+1];if(!1===n.intraword&&a&&!V.test(a))continue;const u=t;let g=u,h=ge(r,f,o),p=g;for(;h<0&&(p=p.getPreviousSibling())&&!c(p);)if(e(p)){if(p.hasFormat("code"))continue;const t=p.getTextContent();g=p,h=ge(t,t.length,o)}if(h<0)continue;if(g===u&&h+l===f)continue;const x=g.getTextContent();if(h>0&&x[h-1]===i)continue;const m=x[h-1];if(!1===n.intraword&&m&&!V.test(m))continue;if(!n.format.includes("code")&&de(g,h))continue;const C=u.getTextContent(),T=C.slice(0,f)+C.slice(s+1);u.setTextContent(T);const E=g===u?T:x;g.setTextContent(E.slice(0,h)+E.slice(h+l));const $=d(),v=S();b(v);const y=s-l*(g===u?2:1)+1;v.anchor.set(g.__key,h,"text"),v.focus.set(u.__key,y,"text");for(const t of n.format)v.formatText(t,w[t]);v.anchor.set(v.focus.key,v.focus.offset,v.focus.type);for(const t of n.format)v.hasFormat(t)&&v.toggleFormat(t);return I($)&&(v.format=$.format),!0}return!1}(n,r,s)));return p(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:s})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const i=n.has(C),c=r.read(d),a=s.read(d);if(!I(a)||!I(c)||!c.isCollapsed()||c.is(a)&&!i)return;const u=c.anchor.key,g=c.anchor.offset,h=r._nodeMap.get(u);if(e(h)&&o.has(u)&&(i||1===g||!(g>a.anchor.offset+1))){if(i){const t=r.read(()=>h.getTextContent())[g-1];if(!l.has(t))return}t.update(()=>{if(!oe(h))return;const t=h.getParent();null===t||L(t)||f(t,h,c.anchor.offset)&&T(E)})}}),t.registerCommand($,t=>{if(null!==t&&t.shiftKey)return!1;const n=d();if(!I(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e(i)||!oe(i))return!1;const l=i.getParent();if(null===l||L(l))return!1;return s===i.getTextContent().length&&(!(!ue(l,i,s,o.multilineElement,!0)&&!ae(l,i,s,r,!0))&&(null!==t&&t.preventDefault(),!0))},v))}function xe(t,e=Ht,n,o=!1,r=!1){const s=o?t:function(t,e=!1){const n=t.split("\n");let o=0;const r=[];for(let t=0;t<n.length;t++){const s=n[t],i=s.trimEnd(),l=r[r.length-1],c=t<n.length-1?Ct(s):null,f=void 0!==l&&null!==Ct(l);if(ft.test(i))r.push(i);else if(0===o){{const t=i.match(lt);if(t){o=t[1].trim().length,r.push(i);continue}}""===i||""===l||!l||st.test(l)||st.test(i)||it.test(i)||nt.test(i)||ot.test(i)||rt.test(i)||at.test(i)||ut(i)||f||!e||dt.test(i)||gt.test(i)||ht(gt).test(l)||ht(dt).test(l)||ct.test(l)?r.push(!e&&""!==i||null!==c?s:i):r[r.length-1]=l+" "+(null===c?i:s).trimStart()}else{if(ct.test(i)&&i.trim().length>=o){o=0,r.push(i);continue}r.push(s)}}return r.join("\n")}(t,r);return se(e,o)(s,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,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[],l=(t||f()).getChildren();for(let t=0;t<l.length;t++){const c=l[t],f=Gt(c,o,s,n.textMatch,e);null!=f&&i.push(r&&t>0&&!tt(c)&&!tt(l[t-1])?"\n".concat(f):f)}return i.join("\n")}}(t,n);return o(e)}function Ce(t=Ht,e,n=!1){if(!e||I(e)&&e.isCollapsed())return"";const o=function(t,e=!1){const n=Q(t),o=[...n.multilineElement,...n.element],r=!e,s=n.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const i=[],l=f().getChildren();for(let c=0;c<l.length;c++){const f=l[c],{shouldInclude:a,markdown:u}=Kt(f,t,o,s,n.textMatch,e);a&&null!=u&&i.push(r&&c>0&&!tt(f)&&!tt(l[c-1])?"\n".concat(u):u)}return i.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,_t as BOLD_STAR,Bt as BOLD_UNDERSCORE,kt as CHECK_LIST,bt as CODE,Wt as ELEMENT_TRANSFORMERS,yt as HEADING,Lt as HIGHLIGHT,Ft as INLINE_CODE,jt as ITALIC_STAR,Pt as ITALIC_UNDERSCORE,At as LINK,zt as MULTILINE_ELEMENT_TRANSFORMERS,Nt as ORDERED_LIST,St as QUOTE,Rt as STRIKETHROUGH,Ut as TEXT_FORMAT_TRANSFORMERS,Dt as TEXT_MATCH_TRANSFORMERS,Ht as TRANSFORMERS,wt as UNORDERED_LIST,ut as isTableRowDivider,pe as registerMarkdownShortcuts};
|
package/package.json
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.46.0",
|
|
11
|
+
"version": "0.46.1-nightly.20260629.0",
|
|
12
12
|
"main": "./dist/LexicalMarkdown.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/code-core": "0.46.0",
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/
|
|
19
|
-
"@lexical/
|
|
20
|
-
"@lexical/selection": "0.46.0",
|
|
21
|
-
"@lexical/text": "0.46.0",
|
|
22
|
-
"@lexical/utils": "0.46.0",
|
|
23
|
-
"lexical": "0.46.0"
|
|
15
|
+
"@lexical/code-core": "0.46.1-nightly.20260629.0",
|
|
16
|
+
"@lexical/list": "0.46.1-nightly.20260629.0",
|
|
17
|
+
"@lexical/internal": "0.46.1-nightly.20260629.0",
|
|
18
|
+
"@lexical/link": "0.46.1-nightly.20260629.0",
|
|
19
|
+
"@lexical/rich-text": "0.46.1-nightly.20260629.0",
|
|
20
|
+
"@lexical/selection": "0.46.1-nightly.20260629.0",
|
|
21
|
+
"@lexical/text": "0.46.1-nightly.20260629.0",
|
|
22
|
+
"@lexical/utils": "0.46.1-nightly.20260629.0",
|
|
23
|
+
"lexical": "0.46.1-nightly.20260629.0"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
@@ -968,7 +968,7 @@ export function normalizeMarkdown(
|
|
|
968
968
|
shouldMergeAdjacentLines = false,
|
|
969
969
|
): string {
|
|
970
970
|
const lines = input.split('\n');
|
|
971
|
-
let
|
|
971
|
+
let codeBlockFenceLength = 0;
|
|
972
972
|
const sanitizedLines: string[] = [];
|
|
973
973
|
|
|
974
974
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -986,15 +986,27 @@ export function normalizeMarkdown(
|
|
|
986
986
|
continue;
|
|
987
987
|
}
|
|
988
988
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
989
|
+
if (codeBlockFenceLength === 0) {
|
|
990
|
+
// An opening fence may carry an info string (e.g. ```ts)
|
|
991
|
+
const openMatch = line.match(CODE_START_REGEX);
|
|
992
|
+
if (openMatch) {
|
|
993
|
+
codeBlockFenceLength = openMatch[1].trim().length;
|
|
994
|
+
sanitizedLines.push(line);
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
} else {
|
|
998
|
+
// A code block is closed only by a bare fence (no info string) that is at
|
|
999
|
+
// least as long as the opening fence. Fence-like lines that carry an info
|
|
1000
|
+
// string (e.g. a nested ```ts) are part of the code block's content.
|
|
1001
|
+
if (
|
|
1002
|
+
CODE_END_REGEX.test(line) &&
|
|
1003
|
+
line.trim().length >= codeBlockFenceLength
|
|
1004
|
+
) {
|
|
1005
|
+
codeBlockFenceLength = 0;
|
|
1006
|
+
sanitizedLines.push(line);
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
// Inside a code block, keep the line unchanged
|
|
998
1010
|
sanitizedLines.push(rawLine);
|
|
999
1011
|
continue;
|
|
1000
1012
|
}
|