@lexical/markdown 0.52.1-nightly.20261027.0 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/LexicalMarkdown.dev.js +484 -426
- package/dist/LexicalMarkdown.prod.js +1 -1
- package/dist/importTextFormatTransformer.d.ts +5 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +10 -10
- package/src/MarkdownExport.ts +8 -1
- package/src/MarkdownTransformers.ts +59 -10
- package/src/importTextFormatTransformer.ts +1 -1
- package/src/importTextMatchTransformer.ts +23 -1
- package/src/utils.ts +25 -6
|
@@ -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,$isTabNode as d,$createTabNode as g,$createParagraphNode as h,mergeRegister as p,COLLABORATION_TAG as m,HISTORIC_TAG as x,COMPOSITION_END_TAG as C,$getSelection as T,$isRangeSelection as I,$addUpdateTag as v,HISTORY_PUSH_TAG as $,KEY_ENTER_COMMAND as y,COMMAND_PRIORITY_LOW as S,$isRootOrShadowRoot as E,$createRangeSelection as b,$setSelection as N,TEXT_TYPE_TO_FORMAT as w,ArtificialNode__DO_NOT_USE as k}from"lexical";import{$sliceSelectedTextNodeContent as F}from"@lexical/selection";import{CodeNode as O,$createCodeNode as P,$isCodeNode as M}from"@lexical/code-core";import{LinkNode as B,$isLinkNode as L,$createLinkNode as _,$isAutoLinkNode as R}from"@lexical/link";import{ListNode as j,ListItemNode as z,$isListNode as A,$createListItemNode as W,$createListNode as U,$isListItemNode as D}from"@lexical/list";import{HeadingNode as Z,QuoteNode as H,$isHeadingNode as K,$isQuoteNode as X,$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]/,Y=/\s/,tt=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,et=/^\s{0,3}$/;function nt(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&et.test(o.getTextContent())}function ot(t,e){const n=Number(e);return 0===n||n>=55296&&n<=57343||n>1114111?"\ufffd":String.fromCodePoint(n)}function rt(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d{1,7});/g,ot)}const st=/^(\s*)(\d{1,})\.\s/,it=/^(\s*)[-*+]\s/,lt=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,ct=/^(#{1,6})\s/,ft=/^>\s/,at=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,ut=/^[ \t]*`{3,}$/,dt=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,gt=/^(?:\|)(.+)(?:\|)\s?$/;function ht(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 pt=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,mt=/^<\/[a-z_][\w-]*\s*>/i,xt=t=>new RegExp(`(?:${t.source})$`,t.flags),Ct=/* @__PURE__ */l("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Tt=/* @__PURE__ */l("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),It=/* @__PURE__ */l("mdCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),vt=/* @__PURE__ */l("mdHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0});function $t(t){if(t.endsWith("\\")){let e=0;for(let n=t.length-1;n>=0&&"\\"===t[n];n--)e++;return e%2==1?[t.slice(0,-1),"\\"]:null}const e=t.match(/^(.*?\S)( {2,})$/);return e?[e[1],e[2]]:null}function yt(t){const o=i(),r=function(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e(r))return null;const s=r.getTextContent(),i=$t(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}(t);return null!==r&&n(o,vt,r),o}function St(t){return X(t)}function Et(t,e){let n=0;for(;n<e&&(" "===t[n]||"\t"===t[n]);)n++;return t.slice(n)}function bt(t,e){const o=t.getLastChild();e&&M(o)&&n(o,It,e)}const Nt=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};function wt(t){let e=0;for(const n of t)e+="\t"===n?4-e%4:1;return e}let kt=null,Ft=!1;const Ot=t=>(e,o,r,s)=>{if(K(e)||!s&&St(e))return!1;const i=e.getPreviousSibling(),l=e.getNextSibling(),c=W("check"===t?/^x$/i.test(r[3]||""):void 0),f=r[0].trim()[0],a="bullet"!==t&&"check"!==t||f!==Ct.parse(f)?void 0:f,u=kt;let d=i;if(null!==u){if(Ft)for(;null!==d&&nt(d);)d=d.getPreviousSibling();A(d)||(u.length=0)}const g=null===u||0===u.length?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]):function(t,e){const n=wt(e);for(let e=t.length-1;e>=0;e--)if(n>=t[e])return e+1;return 0}(u,r[1]);if(A(l)&&l.getListType()===t){const n=l.getFirstChild();null!==n?n.insertBefore(c):l.append(c),"number"===t&&0===g&&l.setStart(Number(r[2])),e.remove()}else if(A(d)&&(d.getListType()===t||g>0))d.append(c),e.remove();else{const n=U(t,"number"===t?Number(r[2]):void 0);n.append(c),e.replace(n)}c.append(...o),s||c.select(0,0),g&&(c.setIndent(g),function(t,e,n){const o=t.getParent();if(!A(o)||o.getListType()===e)return;const r=o.getParent();if(!D(r))return;const s=U(e,"number"===e?Number(n[2]):void 0),i=null===t.getPreviousSibling();s.append(t);const l=W();l.append(s),i?r.insertBefore(l):r.insertAfter(l),0===o.getChildrenSize()&&r.remove()}(c,t,r));const h=c.getParent();a&&A(h)&&n(h,Ct,a),null!==u&&function(t,e,n,o){for(let n=t.length;n<e;n++)t[n]=4*(n+1);t.length=e,t[e]=function(t,e){let n=t[0];if("check"===e){const e=n.slice(t[1].length).match(/^[-*+]\s/);e&&(n=t[1]+e[0])}return Math.min(wt(n),wt(t[1])+4)}(n,o)}(u,g,r,t)},Pt=(t,e,n,o)=>{const s=[],i=t.getChildren();let l=0;for(const c of i)if(D(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(A(t)){const r=Pt(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,Ct),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")},Mt=/* @__PURE__ */Nt(t=>{const e="h"+t[1].length;return G(e)}),Bt={dependencies:[Z],export:(t,e)=>{if(!K(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:ct,replace:(t,e,n,o)=>!(!o&&St(t))&&Mt(t,e,n,o),triggerOnEnter:!0,type:"element"},Lt={dependencies:[H],export:(t,e)=>{if(!X(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:ft,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(X(n))return n.splice(n.getChildrenSize(),0,[yt(n),...e]),void t.remove()}const r=q();r.append(...e),t.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},_t={dependencies:[O],export:t=>{if(!M(t))return null;const e=t.getTextContent();let n=r(t,Tt);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)}}const o=t.getLanguage()||"",s=o?r(t,It):"";return n+o+(s?" "+s:"")+(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]="",_t.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=o[2]?i.slice(o[0].length).trim():"";return c.unshift(f?"":i.slice(o[0].length)),_t.replace(e,null,o,l,c,!0),bt(e,f),[!0,r]}}const u=t.slice(n+1);return u.unshift(i.slice(o[0].length)),_t.replace(e,null,o,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:ut},regExpStart:at,replace:(t,e,r,s,i,l)=>{let c,f;const a=r[1]?r[1].trim():"```",u=r[2]||void 0,d=r[1]?r[1].length-r[1].trimStart().length:0;if(!e&&i){if(1===i.length)s?(c=P(u),f=Et(i[0],d)):(c=P(u),f=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(c=P(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.map(t=>Et(t,d)).join("\n")}n(c,Tt,a);const e=o(f);c.append(e),t.append(c)}else if(e){if(!l&&St(t))return!1;Nt(t=>P(t?t[2]:void 0))(t,e,r,l)}},type:"multiline-element"},Rt={dependencies:[j,z],export:(t,e,n)=>A(t)?Pt(t,e,0,n):null,regExp:it,replace:/* @__PURE__ */Ot("bullet"),triggerOnEnter:!0,type:"element"},jt={dependencies:[j,z],export:(t,e,n)=>A(t)?Pt(t,e,0,n):null,regExp:lt,replace:/* @__PURE__ */Ot("check"),triggerOnEnter:!0,type:"element"},zt={dependencies:[j,z],export:(t,e,n)=>A(t)?Pt(t,e,0,n):null,regExp:st,replace:/* @__PURE__ */Ot("number"),triggerOnEnter:!0,type:"element"},At={format:["code"],tag:"`",type:"text-format"},Wt={format:["highlight"],tag:"==",type:"text-format"},Ut={format:["bold","italic"],tag:"***",type:"text-format"},Dt={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Zt={format:["bold"],tag:"**",type:"text-format"},Ht={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Kt={format:["strikethrough"],tag:"~~",type:"text-format"},Xt={format:["italic"],tag:"*",type:"text-format"},qt={format:["italic"],intraword:!1,tag:"_",type:"text-format"};function Gt(t){return t.replace(/&(?=#\d+;|#[Xx][\dA-Fa-f]+;|[A-Za-z][\dA-Za-z]*;)/g,"&")}const Jt={dependencies:[B],export:(t,e,n)=>{if(!L(t)||R(t))return null;const o=e(t);let r=t.getTitle();null!=r&&(r=Gt(r).replace(/([\\"])/g,"\\$1"));const s=t.getURL(),i=Gt(s),l=""===s||/\s/.test(s)?`<${i.replace(/([\\<>])/g,"\\$1").replace(/\r/g," ").replace(/\n/g," ")}>`:i.replace(/([\\()])/g,"\\$1").replace(/^</,"\\<");return r?`[${o}](${l} "${r}")`:`[${o}](${l})`},importRegExp:/(?:\[(.+?)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))$/,replace:(t,e)=>{if(s(t,L))return;const[,n,r,i,l,c,f]=e,a=rt(r??i??""),u=l??c??f,d=null!=u?rt(u):void 0,g=_(a,{title:d}),h=n.split("[").length-1,p=n.split("]").length-1;let m=n,x="";if(h<p)return;if(h>p){const t=n.split("[");x="["+t[0],m=t.slice(1).join("[")}const C=t.getFormat(),T=o(m);return T.setFormat(C),g.append(T),t.replace(g),x&&g.insertBefore(o(x).setFormat(C)),T},trigger:")",type:"text-match"},Qt=[Bt,Lt,Rt,zt],Vt=[_t],Yt=[At,Ut,Dt,Zt,Ht,Wt,Xt,qt,Kt],te=[Jt];function ee(...t){return t.flat()}const ne=/* @__PURE__ */ee(Qt,Vt,Yt,te);function oe(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?$t(s):null,f=void 0!==l&&null!==$t(l);if(dt.test(i))r.push(i);else if(0===o){{const t=i.match(at);if(t){o=t[1].trim().length,r.push(i);continue}}""===i||""===l||!l||ct.test(l)||ct.test(i)||ft.test(i)||st.test(i)||it.test(i)||lt.test(i)||gt.test(i)||ht(i)||f||!e||pt.test(i)||mt.test(i)||xt(mt).test(l)||xt(pt).test(l)||ut.test(l)?r.push(!e&&""!==i||null!==c?s:i):r[r.length-1]=l+" "+(null===c?i:s).trimStart()}else{if(ut.test(i)&&i.trim().length>=o){o=0,r.push(i);continue}r.push(s)}}return r.join("\n")}function re(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=>se(t,e,o,r,s).markdown,e);if(null!=n)return!i&&a(t)&&se(t,e,o,r,s).shouldInclude&&(i=!0),{markdown:n,shouldInclude:i}}if(a(t)){const n=se(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 se(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=>se(t,n,o,r,s,i,[...l,...i]).markdown,(t,e)=>fe(t,F(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(ce(t)),g=!0);else if(e(t)){if(d){const e=F(n,t,"clone");f.push(fe(t,e.getTextContent(),o,i,l,s)),g=!0}}else if(a(t)){const e=se(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 ie(t,e,n,o,r){for(const s of e){if(!s.export)continue;const e=s.export(t,t=>le(t,n,o,void 0,void 0,r));if(null!=e)return e}return a(t)?le(t,n,o,void 0,void 0,r):u(t)?t.getTextContent():null}function le(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=>le(t,n,o,r,[...s,...r],i),(t,e)=>fe(t,e,n,r,s,i));if(null!=c){l.push(c);continue t}}c(t)?l.push(ce(t)):e(t)?l.push(fe(t,t.getTextContent(),n,r,s,i)):a(t)?l.push(le(t,n,o,r,s,i)):u(t)&&l.push(t.getTextContent())}return l.join("")}function ce(t){return r(t,vt)+"\n"}function fe(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=ae(t,!0),m=ae(t,!1),x=new Set;for(const e of n){const n=e.format[0],r=e.tag;"code"!==n&&(a||!de(t,n)||x.has(n)||(x.add(n),de(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=ue(t,o[e].format),s=ue(m,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 ae(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function ue(t,n){return e(t)&&t.hasFormat(n)}function de(t,e){return!(!ue(t,e)||"code"!==e&&t&&/^\s*$/.test(t.getTextContent()))}function ge(t,e,n,o,r){if(!he(e,n,o,r))return!1;if("*"===t)return!0;if("_"===t){if(!he(e,n,o,!r))return!0;const t=r?e[n-1]:e[n+o];return void 0!==t&&tt.test(t)}return!0}function he(t,e,n,o){const r=t[e-1],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!Y.test(i)&&(!tt.test(i)||void 0===l||Y.test(l)||tt.test(l))}function pe(t){return e(t)&&!t.hasFormat("code")}function me(t,e,n){let o=function(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=ge(e,t,l,n,!0),f=ge(e,t,l,n,!1);(c||f)&&o.push({active:!0,canClose:f,canOpen:c,char:e,index:l,length: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}${i.length%3}`,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)&&(l.length+i.length)%3==0&&l.length%3!=0&&i.length%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}}(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);pe(r.nodeAfter)&&me(r.nodeAfter,e,n),pe(r.nodeBefore)&&me(r.nodeBefore,e,n),pe(r.transformedNode)&&me(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?{matchedNode:s,nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;pe(o.nodeAfter)&&me(o.nodeAfter,e,n),pe(o.nodeBefore)&&me(o.nodeBefore,e,n),pe(o.transformedNode)?me(o.transformedNode,e,n):void 0===o.transformedNode&&pe(o.matchedNode)&&null!==o.matchedNode.getParent()&&o.matchedNode.setTextContent(rt(o.matchedNode.getTextContent()))}if(!o&&!r){const e=rt(t.getTextContent());t.setTextContent(e)}}function xe(t,e,n,o=!1){const r=Q(n),s=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}}(r.textFormat),i=t.split("\n"),l=i.length;!function(t){const n=kt,c=Ft;kt=[],Ft=t;try{return(()=>{for(let t=0;t<l;t++){const n=i[t],[l,c]=Ce(i,t,r.multilineElement,e);l?t=c:Te(n,e,r.element,s,r.textMatch,o)}})()}finally{kt=n,Ft=c}}(!o);const c=e.getChildren();for(const t of c)if(!o&&nt(t)&&e.getChildrenSize()>1)t.remove();else if(a(t))for(const e of t.getAllTextNodes())Ie(e)}function Ce(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 Te(e,n,r,i,l,c){const f=o(e),a=h();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(me(f,i,l),null!==a.getParent()&&e.length>0){const e=a.getPreviousSibling();if(!c&&(t(e)||X(e)||A(e))){let t=e;if(A(e)){const n=e.getLastDescendant();t=null==n?null:s(n,D)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[yt(t),...a.getChildren()]),a.remove())}}}function Ie(t){if(d(t))return;const e=t.getTextContent();if(!e.includes("\t"))return;const n=t.getFormat(),r=t.getStyle(),s=[];let i=0;for(let t=e.indexOf("\t");-1!==t;t=e.indexOf("\t",t+1))t>i&&s.push(o(e.slice(i,t)).setFormat(n).setStyle(r)),s.push(g()),i=t+1;i<e.length&&s.push(o(e.slice(i)).setFormat(n).setStyle(r)),t.getParentOrThrow().splice(t.getIndexWithinParent(),1,s)}function ve(t,...e){throw function(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);return n.search=o.toString(),new 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.`)}(t,...e)}function $e(t,e,n,o,r){const s=t.getParent();if(!E(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 ye(t,e,n,o,r){const s=t.getParent();if(!E(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 Se(t,e){let n=0;const o=t.getTextContent();for(let t=0;t<e;t++)"`"===o[t]&&n++;return n%2!=0}function Ee(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(Ne(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function be(t){const n=t.getNode();let o=0;if(e(n))o=t.offset;else if(a(n))for(const e of n.getChildren().slice(0,t.offset))o+=e.getTextContentSize();for(let t=n.getPreviousSibling();null!==t;t=t.getPreviousSibling())o+=t.getTextContentSize();return o}function Ne(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function we(t,n=ne){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)||ve(173,e.getType())}}return p(t.registerUpdateListener(({tags:n,dirtyLeaves:r,editorState:f,prevEditorState:a})=>{if(n.has(m)||n.has(x))return;if(t.isComposing())return;const u=n.has(C),d=f.read(T),g=a.read(T);if(!I(g)||!I(d)||!d.isCollapsed()||d.is(g)&&!u)return;const h=d.anchor.key,p=d.anchor.offset,y=f._nodeMap.get(h);if(e(y)&&r.has(h)&&(u||1===p||!(f.read(()=>be(d.anchor))>a.read(()=>be(g.anchor))+1))){if(u){const t=f.read(()=>y.getTextContent())[p-1];if(!l.has(t))return}t.update(()=>{if(!pe(y))return;const t=y.getParent();null===t||M(t)||((t,n,r)=>!!($e(t,n,r,o.element)||ye(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&&!Ne(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 d=u,g=Ee(r,f,o),h=d;for(;g<0&&(h=h.getPreviousSibling())&&!c(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,g=Ee(t,t.length,o)}if(g<0)continue;if(d===u&&g+l===f)continue;const p=d.getTextContent();if(g>0&&p[g-1]===i)continue;const m=p[g-1];if(!1===n.intraword&&m&&!V.test(m))continue;if(!n.format.includes("code")&&Se(d,g))continue;const x=u.getTextContent(),C=x.slice(0,f)+x.slice(s+1);u.setTextContent(C);const v=d===u?C:p;d.setTextContent(v.slice(0,g)+v.slice(g+l));const $=T(),y=b();N(y);const S=s-l*(d===u?2:1)+1;y.anchor.set(d.__key,g,"text"),y.focus.set(u.__key,S,"text");for(const t of n.format)y.formatText(t,w[t]);y.anchor.set(y.focus.key,y.focus.offset,y.focus.type);for(const t of n.format)y.hasFormat(t)&&y.toggleFormat(t);return I($)&&(y.format=$.format),!0}return!1}(n,r,s)))(t,y,d.anchor.offset)&&v($)})}}),t.registerCommand(y,t=>{if(null!==t&&t.shiftKey)return!1;const n=T();if(!I(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e(i)||!pe(i))return!1;const l=i.getParent();return null!==l&&!M(l)&&!(s!==i.getTextContent().length||!ye(l,i,s,o.multilineElement,!0)&&!$e(l,i,s,r,!0)||(null!==t&&t.preventDefault(),0))},S))}function ke(t,e=ne,n,o=!1,r=!1){const s=o?t:oe(t,r),i=n||f();i.clear(),xe(s,i,e,o),null!==T()&&i.selectStart()}function Fe(t,e=ne,n=!1,o=!1){const r=n?t:oe(t,o),s=new k;return xe(r,s,e,n),s.getChildren()}function Oe(t=ne,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=ie(c,o,s,n.textMatch,e);null!=f&&i.push(r&&t>0&&!nt(c)&&!nt(l[t-1])?"\n".concat(f):f)}return i.join("\n")}}(t,n);return o(e)}function Pe(t=ne,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=[];let l=null;for(const c of f().getChildren()){const{shouldInclude:f,markdown:a}=re(c,t,o,s,n.textMatch,e);f&&null!=a&&(i.push(!r||null===l||nt(c)||nt(l)?a:"\n".concat(a)),l=c)}return i.join("\n")}}(t,n);return o(e)}export{ke as $convertFromMarkdownString,Pe as $convertSelectionToMarkdownString,Oe as $convertToMarkdownString,Fe as $generateNodesFromMarkdownString,Ut as BOLD_ITALIC_STAR,Dt as BOLD_ITALIC_UNDERSCORE,Zt as BOLD_STAR,Ht as BOLD_UNDERSCORE,jt as CHECK_LIST,_t as CODE,Qt as ELEMENT_TRANSFORMERS,Bt as HEADING,Wt as HIGHLIGHT,At as INLINE_CODE,Xt as ITALIC_STAR,qt as ITALIC_UNDERSCORE,Jt as LINK,Vt as MULTILINE_ELEMENT_TRANSFORMERS,zt as ORDERED_LIST,Lt as QUOTE,Kt as STRIKETHROUGH,Yt as TEXT_FORMAT_TRANSFORMERS,te as TEXT_MATCH_TRANSFORMERS,ne as TRANSFORMERS,Rt as UNORDERED_LIST,ht as isTableRowDivider,we as registerMarkdownShortcuts};
|
|
9
|
+
import{$isParagraphNode as t,$isTextNode as e,$setState as n,$createTextNode as o,$getState as r,$findMatchingParent as s,$createLineBreakNode as l,createState as i,$isLineBreakNode as c,$getRoot as f,$isElementNode as u,$isDecoratorNode as a,$isTabNode as d,$createTabNode as g,$createParagraphNode as h,mergeRegister as p,COLLABORATION_TAG as x,HISTORIC_TAG as m,COMPOSITION_END_TAG as C,$getSelection as I,$isRangeSelection as T,$addUpdateTag as v,HISTORY_PUSH_TAG as $,KEY_ENTER_COMMAND as y,COMMAND_PRIORITY_LOW as E,$isRootOrShadowRoot as S,$createRangeSelection as b,$setSelection as w,TEXT_TYPE_TO_FORMAT as N,ArtificialNode__DO_NOT_USE as k}from"lexical";import{$sliceSelectedTextNodeContent as F}from"@lexical/selection";import{CodeNode as O,$createCodeNode as P,$isCodeNode as M}from"@lexical/code-core";import{LinkNode as R,$isLinkNode as _,$createLinkNode as B,$isAutoLinkNode as L}from"@lexical/link";import{ListNode as A,ListItemNode as j,$isListNode as z,$createListItemNode as W,$createListNode as U,$isListItemNode as D}from"@lexical/list";import{HeadingNode as X,QuoteNode as Z,$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]/,Y=/\s/,tt=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,et=/^\s{0,3}$/;function nt(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&et.test(o.getTextContent())}function ot(t){return t.replace(/\\([!-/:-@[-`{-~])|&#(?:(\d{1,7})|[xX]([\da-fA-F]{1,6}));/g,(t,e,n,o)=>e??function(t,e){const n=void 0!==t?Number(t):parseInt(e,16);return 0===n||n>=55296&&n<=57343||n>1114111?"\ufffd":String.fromCodePoint(n)}(n,o))}function rt(t,e){let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1}function st(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 l=-1;for(let t=s+1;t<n.length;t++)if(n[t].length===o.length){l=t;break}if(-1===l){s++;continue}const i=n[l];let c=t.slice(o.index+o.length,i.index);c.length>=2&&c.startsWith(" ")&&c.endsWith(" ")&&/[^ ]/.test(c)&&(c=c.slice(1,-1)),r.push({content:c,endIndex:i.index+i.length,startIndex:o.index}),s=l+1}return r}function lt(t,e,n,o,r){if(!it(e,n,o,r))return!1;if("*"===t)return!0;if("_"===t){if(!it(e,n,o,!r))return!0;const t=r?e[n-1]:e[n+o];return void 0!==t&&tt.test(t)}return!0}function it(t,e,n,o){const r=t[e-1],s=t[e+n],[l,i]=o?[s,r]:[r,s];return void 0!==l&&!Y.test(l)&&(!tt.test(l)||void 0===i||Y.test(i)||tt.test(i))}const ct=/^(\s*)(\d{1,})\.\s/,ft=/^(\s*)[-*+]\s/,ut=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,at=/^(#{1,6})\s/,dt=/^>\s/,gt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,ht=/^[ \t]*`{3,}$/,pt=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,xt=/^(?:\|)(.+)(?:\|)\s?$/;function mt(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 Ct=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,It=/^<\/[a-z_][\w-]*\s*>/i,Tt=t=>new RegExp(`(?:${t.source})$`,t.flags),vt=/* @__PURE__ */i("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),$t=/* @__PURE__ */i("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),yt=/* @__PURE__ */i("mdCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),Et=/* @__PURE__ */i("mdHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0});function St(t){if(t.endsWith("\\")){let e=0;for(let n=t.length-1;n>=0&&"\\"===t[n];n--)e++;return e%2==1?[t.slice(0,-1),"\\"]:null}const e=t.match(/^(.*?\S)( {2,})$/);return e?[e[1],e[2]]:null}function bt(t){const o=l(),r=function(t){const n=t.getChildren(),o=n.length-1,r=n[o];if(!e(r))return null;const s=r.getTextContent(),l=St(s);if(null!==l){const[t,e]=l;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}(t);return null!==r&&n(o,Et,r),o}function wt(t){return K(t)}function Nt(t,e){let n=0;for(;n<e&&(" "===t[n]||"\t"===t[n]);)n++;return t.slice(n)}function kt(t,e){const o=t.getLastChild();e&&M(o)&&n(o,yt,e)}const Ft=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};function Ot(t){let e=0;for(const n of t)e+="\t"===n?4-e%4:1;return e}let Pt=null,Mt=!1;const Rt=t=>(e,o,r,s)=>{if(H(e)||!s&&wt(e))return!1;const l=e.getPreviousSibling(),i=e.getNextSibling(),c=W("check"===t?/^x$/i.test(r[3]||""):void 0),f=r[0].trim()[0],u="bullet"!==t&&"check"!==t||f!==vt.parse(f)?void 0:f,a=Pt;let d=l;if(null!==a){if(Mt)for(;null!==d&&nt(d);)d=d.getPreviousSibling();z(d)||(a.length=0)}const g=null===a||0===a.length?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]):function(t,e){const n=Ot(e);for(let e=t.length-1;e>=0;e--)if(n>=t[e])return e+1;return 0}(a,r[1]);if(z(i)&&i.getListType()===t){const n=i.getFirstChild();null!==n?n.insertBefore(c):i.append(c),"number"===t&&0===g&&i.setStart(Number(r[2])),e.remove()}else if(z(d)&&(d.getListType()===t||g>0))d.append(c),e.remove();else{const n=U(t,"number"===t?Number(r[2]):void 0);n.append(c),e.replace(n)}c.append(...o),s||c.select(0,0),g&&(c.setIndent(g),function(t,e,n){const o=t.getParent();if(!z(o)||o.getListType()===e)return;const r=o.getParent();if(!D(r))return;const s=U(e,"number"===e?Number(n[2]):void 0),l=null===t.getPreviousSibling();s.append(t);const i=W();i.append(s),l?r.insertBefore(i):r.insertAfter(i),0===o.getChildrenSize()&&r.remove()}(c,t,r));const h=c.getParent();u&&z(h)&&n(h,vt,u),null!==a&&function(t,e,n,o){for(let n=t.length;n<e;n++)t[n]=4*(n+1);t.length=e,t[e]=function(t,e){let n=t[0];if("check"===e){const e=n.slice(t[1].length).match(/^[-*+]\s/);e&&(n=t[1]+e[0])}return Math.min(Ot(n),Ot(t[1])+4)}(n,o)}(a,g,r,t)},_t=(t,e,n,o)=>{const s=[],l=t.getChildren();let i=0;for(const c of l)if(D(c)){if(1===c.getChildrenSize()){const t=c.getFirstChild();if(z(t)){const r=_t(t,e,n+1,o);r&&s.push(r);continue}}if(o&&!c.getChildren().some(t=>t.isSelected(o)))continue;const l=" ".repeat(4*n),f=t.getListType(),u=r(t,vt),a="number"===f?`${t.getStart()+i}. `:"check"===f?`${u} [${c.getChecked()?"x":" "}] `:u+" ";let d=e(c);"number"!==f&&(d=d.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),s.push(l+a+d),i++}return s.join("\n")},Bt=/* @__PURE__ */Ft(t=>{const e="h"+t[1].length;return G(e)}),Lt={dependencies:[X],export:(t,e)=>{if(!H(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:at,replace:(t,e,n,o)=>!(!o&&wt(t))&&Bt(t,e,n,o),triggerOnEnter:!0,type:"element"},At={dependencies:[Z],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:dt,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(K(n))return n.splice(n.getChildrenSize(),0,[bt(n),...e]),void t.remove()}const r=q();r.append(...e),t.replace(r),o||r.select(0,0)},triggerOnEnter:!0,type:"element"},jt={dependencies:[O],export:t=>{if(!M(t))return null;const e=t.getTextContent();let n=r(t,$t);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)}}const o=t.getLanguage()||"",s=o?r(t,yt):"";return n+o+(s?" "+s:"")+(e?"\n"+e:"")+"\n"+n},handleImportAfterStartMatch:({lines:t,rootNode:e,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,l=t[n],i=o.index+r.length,c=l.slice(i),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]="",jt.replace(e,null,s,t,[r],!0),[!0,n]}const u=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(u.test(s)){const i=s.match(u),c=t.slice(n+1,r),f=o[2]?l.slice(o[0].length).trim():"";return c.unshift(f?"":l.slice(o[0].length)),jt.replace(e,null,o,i,c,!0),kt(e,f),[!0,r]}}const a=t.slice(n+1);return a.unshift(l.slice(o[0].length)),jt.replace(e,null,o,null,a,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:ht},regExpStart:gt,replace:(t,e,r,s,l,i)=>{let c,f;const u=r[1]?r[1].trim():"```",a=r[2]||void 0,d=r[1]?r[1].length-r[1].trimStart().length:0;if(!e&&l){if(1===l.length)s?(c=P(a),f=Nt(l[0],d)):(c=P(a),f=l[0].startsWith(" ")?l[0].slice(1):l[0]);else{for(c=P(a),l.length>0&&(0===l[0].trim().length?l.shift():l[0].startsWith(" ")&&(l[0]=l[0].slice(1)));l.length>0&&!l[l.length-1].length;)l.pop();f=l.map(t=>Nt(t,d)).join("\n")}n(c,$t,u);const e=o(f);c.append(e),t.append(c)}else if(e){if(!i&&wt(t))return!1;Ft(t=>P(t?t[2]:void 0))(t,e,r,i)}},type:"multiline-element"},zt={dependencies:[A,j],export:(t,e,n)=>z(t)?_t(t,e,0,n):null,regExp:ft,replace:/* @__PURE__ */Rt("bullet"),triggerOnEnter:!0,type:"element"},Wt={dependencies:[A,j],export:(t,e,n)=>z(t)?_t(t,e,0,n):null,regExp:ut,replace:/* @__PURE__ */Rt("check"),triggerOnEnter:!0,type:"element"},Ut={dependencies:[A,j],export:(t,e,n)=>z(t)?_t(t,e,0,n):null,regExp:ct,replace:/* @__PURE__ */Rt("number"),triggerOnEnter:!0,type:"element"},Dt={format:["code"],tag:"`",type:"text-format"},Xt={format:["highlight"],tag:"==",type:"text-format"},Zt={format:["bold","italic"],tag:"***",type:"text-format"},Ht={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Kt={format:["bold"],tag:"**",type:"text-format"},qt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Gt={format:["strikethrough"],tag:"~~",type:"text-format"},Jt={format:["italic"],tag:"*",type:"text-format"},Qt={format:["italic"],intraword:!1,tag:"_",type:"text-format"};function Vt(t){return t.replace(/&(?=#\d+;|#[Xx][\dA-Fa-f]+;|[A-Za-z][\dA-Za-z]*;)/g,"&")}const Yt={dependencies:[R],export:(t,e,n)=>{if(!_(t)||L(t))return null;const o=e(t);let r=t.getTitle();null!=r&&(r=Vt(r).replace(/([\\"])/g,"\\$1"));const s=t.getURL(),l=Vt(s),i=""===s||/\s/.test(s)?`<${l.replace(/([\\<>])/g,"\\$1").replace(/\r/g," ").replace(/\n/g," ")}>`:l.replace(/([\\()])/g,"\\$1").replace(/^</,"\\<");return r?`[${o}](${i} "${r}")`:`[${o}](${i})`},importRegExp:/(?:\[(.+?)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))$/,replace:(t,e)=>{const n=e.input||"",r=e.index||0;if(s(t,_)||rt(n,r)||rt(n,r+e[1].length+1))return;const[,l,i,c,f,u,a]=e,d=ot(i??c??""),g=f??u??a,h=null!=g?ot(g):void 0,p=B(d,{title:h}),x=function(t){const e=st(t);let n=0;const o=t.replace(/\\.|[[\]]/g,(t,o)=>{for(;n<e.length&&o>=e[n].endIndex;)n++;return n<e.length&&o>=e[n].startIndex||"\\"===t[0]?" ".repeat(t.length):t}),r=[];let s=!1;for(let t=0;t<o.length;t++){const e=o[t];"["===e?r.push(t):"]"===e&&void 0===r.pop()&&(s=!0)}return r.pop()??(s?null:-1)}(l);if(null===x)return;let m=l,C="";-1!==x&&(C="["+function(t){let e="",n=0;for(const{startIndex:o,endIndex:r}of st(t))e+=ot(t.slice(n,o))+t.slice(o,r),n=r;return e+ot(t.slice(n))}(l.slice(0,x)),m=l.slice(x+1));const I=t.getFormat(),T=o(m);return T.setFormat(I),p.append(T),t.replace(p),C&&p.insertBefore(o(C).setFormat(I)),T},trigger:")",type:"text-match"},te=[Lt,At,zt,Ut],ee=[jt],ne=[Dt,Zt,Ht,Kt,qt,Xt,Jt,Qt,Gt],oe=[Yt];function re(...t){return t.flat()}const se=/* @__PURE__ */re(te,ee,ne,oe);function le(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],l=s.trimEnd(),i=r[r.length-1],c=t<n.length-1?St(s):null,f=void 0!==i&&null!==St(i);if(pt.test(l))r.push(l);else if(0===o){{const t=l.match(gt);if(t){o=t[1].trim().length,r.push(l);continue}}""===l||""===i||!i||at.test(i)||at.test(l)||dt.test(l)||ct.test(l)||ft.test(l)||ut.test(l)||xt.test(l)||mt(l)||f||!e||Ct.test(l)||It.test(l)||Tt(It).test(i)||Tt(Ct).test(i)||ht.test(i)?r.push(!e&&""!==l||null!==c?s:l):r[r.length-1]=i+" "+(null===c?l:s).trimStart()}else{if(ht.test(l)&&l.trim().length>=o){o=0,r.push(l);continue}r.push(s)}}return r.join("\n")}function ie(t,e,n,o,r,s){let l=t.isSelected(e);for(const i of n){if(!i.export)continue;const n=i.export(t,t=>ce(t,e,o,r,s).markdown,e);if(null!=n)return!l&&u(t)&&ce(t,e,o,r,s).shouldInclude&&(l=!0),{markdown:n,shouldInclude:l}}if(u(t)){const n=ce(t,e,o,r,s);return{markdown:n.markdown,shouldInclude:l||n.shouldInclude}}return a(t)?{markdown:t.getTextContent(),shouldInclude:l}:{markdown:null,shouldInclude:l}}function ce(t,n,o,r,s,l,i){const f=[],d=t.getChildren();let g=!1;l||(l=[]),i||(i=[]);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=>ce(t,n,o,r,s,l,[...i,...l]).markdown,(t,e)=>de(t,F(n,t,"clone").getTextContent(),o,l,i,s));if(null!=c){!d&&u(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(ae(t)),g=!0);else if(e(t)){if(d){const e=F(n,t,"clone");f.push(de(t,e.getTextContent(),o,l,i,s)),g=!0}}else if(u(t)){const e=ce(t,n,o,r,s,l,i);!d&&e.shouldInclude&&t.extractWithChild(t,n,"html")&&(d=!0),(d||e.shouldInclude)&&(f.push(e.markdown),g=!0)}else a(t)&&d&&(f.push(t.getTextContent()),g=!0)}return{markdown:f.join(""),shouldInclude:g}}function fe(t,e,n,o,r){for(const s of e){if(!s.export)continue;const e=s.export(t,t=>ue(t,n,o,void 0,void 0,r));if(null!=e)return e}return u(t)?ue(t,n,o,void 0,void 0,r):a(t)?t.getTextContent():null}function ue(t,n,o,r,s,l=!1){const i=[],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=>ue(t,n,o,r,[...s,...r],l),(t,e)=>de(t,e,n,r,s,l));if(null!=c){i.push(c);continue t}}c(t)?i.push(ae(t)):e(t)?i.push(de(t,t.getTextContent(),n,r,s,l)):u(t)?i.push(ue(t,n,o,r,s,l)):a(t)&&i.push(t.getTextContent())}return i.join("")}function ae(t){return r(t,Et)+"\n"}function de(t,e,n,o,r,s=!1){const l=t.hasFormat("code");let i,c,f,u,a=e;if(l||(a=s?a.replace(/([*_`~])/g,"\\$1"):a.replace(/([[\]*_`~\\]|<(?=\S|$)|&(?=#|$))/g,t=>/[*_`~\\]/.test(t)?`\\${t}`:`&#${t.charCodeAt(0)};`)),l){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);i="",f="",c=t+n+t,u=!1}else{const t=a.match(/^(\s*)(.*?)(\s*)$/s)||["","",a,""];i=t[1],c=t[2],f=t[3],u=""===c}let d="",g="",h="";const p=ge(t,!0),x=ge(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;"code"!==n&&(u||!pe(t,n)||m.has(n)||(m.add(n),pe(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=he(t,o[e].format),s=he(x,o[e].format);if(n&&s)continue;const l=[...o];for(;l.length>e;){const t=l.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 u&&!t.hasFormat("code")?g+a:g+i+d+c+h+f}function ge(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function he(t,n){return e(t)&&t.hasFormat(n)}function pe(t,e){return!(!he(t,e)||"code"!==e&&t&&/^\s*$/.test(t.getTextContent()))}function xe(t,e){const n=new RegExp(e.source,e.flags.replace(/[gy]/g,"")+"g");let o;for(;null!==(o=n.exec(t));){if(!rt(t,o.index))return o;n.lastIndex=o.index+1}return null}function me(t){return e(t)&&!t.hasFormat("code")}function Ce(t,e,n){let o=function(t,e){const n=t.getTextContent(),o=e.transformersByTag["`"],r=[];let s=null;if(o){const t=st(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 l=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},l=t=>n.some(e=>t>=e.start&&t<e.end);let i=0;for(;i<t.length;){const e=t[i];if(!r.has(e)||s(i)||l(i)){i++;continue}let n=1;for(;i+n<t.length&&t[i+n]===e;)n++;const c=lt(e,t,i,n,!0),f=lt(e,t,i,n,!1);(c||f)&&o.push({active:!0,canClose:f,canOpen:c,char:e,index:i,length:n}),i+=n}return o}(n,e,r),i=l.length>0?function(t,e,n){const o={};let r=0,s=null;for(;r<e.length;){const l=e[r];if(!l.active||!l.canClose||0===l.length){r++;continue}const i=`${l.char}${l.canOpen}${l.length%3}`,c=o[i]??-1;let f=!1;for(let o=r-1;o>c;o--){const i=e[o];if(!i.active||!i.canOpen||0===i.length||i.char!==l.char)continue;if((i.canClose||l.canOpen)&&(i.length+l.length)%3==0&&i.length%3!=0&&l.length%3!=0)continue;const c=Math.min(i.length,l.length),u=Object.keys(n.transformersByTag).filter(t=>t[0]===i.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!u)continue;f=!0;const a=u.length,d={content:t.slice(i.index+i.length,l.index),endIndex:l.index+a,startIndex:i.index+(i.length-a),tag:u};(!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;i.length-=a,l.length-=a,i.active=i.length>0,l.length>0?l.index+=a:(l.active=!1,r++);break}f||(o[i]=r-1,l.canOpen||(l.active=!1),r++)}return s}(n,l,e):null;let c=null,f=null;if(s&&i?i.startIndex<=s.startIndex&&i.endIndex>=s.endIndex?(c=i,f=e.transformersByTag[i.tag]):(c=s,f=o):s?(c=s,f=o):i&&(c=i,f=e.transformersByTag[i.tag]),!c||!f)return null;const u=[n.slice(c.startIndex,c.endIndex),c.tag,c.content];return u.index=c.startIndex,u.input=n,{endIndex:c.endIndex,isCodeSpan:f===o,match:u,startIndex:c.startIndex,transformer:f}}(t,e),r=function(t,e){const n=t;let o,r,s,l;for(const t of e){if(!t.replace||!t.importRegExp)continue;const e=n.getTextContent(),i=void 0!==Yt.importRegExp&&t.importRegExp.source===Yt.importRegExp.source?xe(e,t.importRegExp):e.match(t.importRegExp);if(!i)continue;const c=i.index||0,f=t.getEndIndex?t.getEndIndex(n,i):c+i[0].length;!1!==f&&(void 0===o||void 0===r||c<o&&(f>r||f<=o))&&(o=c,r=f,s=t,l=i)}return void 0===o||void 0===r||void 0===s||void 0===l?null:{endIndex:r,match:l,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 l,i,c;if(r[0]===s?l=t:0===e?[l,i]=t.splitText(n):[c,l,i]=t.splitText(e,n),l.setTextContent(r[2]),o)for(const t of o.format)l.hasFormat(t)||l.toggleFormat(t);return{nodeAfter:i,nodeBefore:c,transformedNode:l}}(t,o.startIndex,o.endIndex,o.transformer,o.match);me(r.nodeAfter)&&Ce(r.nodeAfter,e,n),me(r.nodeBefore)&&Ce(r.nodeBefore,e,n),me(r.transformedNode)&&Ce(r.transformedNode,e,n)}else if(r){const o=function(t,e,n,o,r){let s,l,i;return 0===e?[s,l]=t.splitText(n):[i,s,l]=t.splitText(e,n),o.replace?{matchedNode:s,nodeAfter:l,nodeBefore:i,transformedNode:o.replace(s,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;me(o.nodeAfter)&&Ce(o.nodeAfter,e,n),me(o.nodeBefore)&&Ce(o.nodeBefore,e,n),me(o.transformedNode)?Ce(o.transformedNode,e,n):void 0===o.transformedNode&&me(o.matchedNode)&&null!==o.matchedNode.getParent()&&o.matchedNode.setTextContent(ot(o.matchedNode.getTextContent()))}if(!o&&!r){const e=ot(t.getTextContent());t.setTextContent(e)}}function Ie(t,e,n,o=!1){const r=Q(n),s=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}}(r.textFormat),l=t.split("\n"),i=l.length;!function(t){const n=Pt,c=Mt;Pt=[],Mt=t;try{return(()=>{for(let t=0;t<i;t++){const n=l[t],[i,c]=Te(l,t,r.multilineElement,e);i?t=c:ve(n,e,r.element,s,r.textMatch,o)}})()}finally{Pt=n,Mt=c}}(!o);const c=e.getChildren();for(const t of c)if(!o&&nt(t)&&e.getChildrenSize()>1)t.remove();else if(u(t))for(const e of t.getAllTextNodes())$e(e)}function Te(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:l,replace:i}=r,c=t[e].match(l);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,u=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let a=e;const d=t.length;for(;a<d;){const n=f?t[a].match(f):null;if(!n&&(!u||u&&a<d-1)){a++;continue}if(n&&e===a&&n.index===c.index){a++;continue}const r=[];if(n&&e===a)r.push(t[e].slice(c[0].length,-n[0].length));else for(let o=e;o<=a;o++)if(o===e){const e=t[o].slice(c[0].length);r.push(e)}else if(o===a&&n){const e=t[o].slice(0,-n[0].length);r.push(e)}else r.push(t[o]);if(!1!==i(o,null,c,n,r,!0))return[!0,a];break}}return[!1,e]}function ve(e,n,r,l,i,c){const f=o(e),u=h();u.append(f),n.append(u);for(const{regExp:t,replace:n}of r){const o=e.match(t);if(o&&(f.setTextContent(e.slice(o[0].length)),!1!==n(u,[f],o,!0)))break}if(Ce(f,l,i),null!==u.getParent()&&e.length>0){const e=u.getPreviousSibling();if(!c&&(t(e)||K(e)||z(e))){let t=e;if(z(e)){const n=e.getLastDescendant();t=null==n?null:s(n,D)}null!=t&&t.getTextContentSize()>0&&(t.splice(t.getChildrenSize(),0,[bt(t),...u.getChildren()]),u.remove())}}}function $e(t){if(d(t))return;const e=t.getTextContent();if(!e.includes("\t"))return;const n=t.getFormat(),r=t.getStyle(),s=[];let l=0;for(let t=e.indexOf("\t");-1!==t;t=e.indexOf("\t",t+1))t>l&&s.push(o(e.slice(l,t)).setFormat(n).setStyle(r)),s.push(g()),l=t+1;l<e.length&&s.push(o(e.slice(l)).setFormat(n).setStyle(r)),t.getParentOrThrow().splice(t.getIndexWithinParent(),1,s)}function ye(t,...e){throw function(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);return n.search=o.toString(),new 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.`)}(t,...e)}function Ee(t,e,n,o,r){const s=t.getParent();if(!S(s)||t.getFirstChild()!==e)return!1;const l=e.getTextContent();if(!r&&" "!==l[n-1])return!1;for(const{regExp:s,replace:i}of o){const o=l.match(s),c=r||o&&o[0].endsWith(" ")?n:n-1;if(o&&o[0].length===c){const r=e.getNextSiblings(),[s,l]=e.splitText(n);if(!1!==i(t,l?[l,...r]:r,o,!1))return s.remove(),!0}}return!1}function Se(t,e,n,o,r){const s=t.getParent();if(!S(s)||t.getFirstChild()!==e)return!1;const l=e.getTextContent();if(!r&&" "!==l[n-1])return!1;for(const{regExpStart:s,replace:i,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=l.match(s);if(o){const s=r||o[0].endsWith(" ")?n:n-1;if(o[0].length!==s)continue;const l=e.getNextSiblings(),[c,f]=e.splitText(n);if(!1!==i(t,f?[f,...l]:l,o,null,null,!1))return c.remove(),!0}}return!1}function be(t,e){let n=0;const o=t.getTextContent();for(let t=0;t<e;t++)"`"===o[t]&&n++;return n%2!=0}function we(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(ke(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function Ne(t){const n=t.getNode();let o=0;if(e(n))o=t.offset;else if(u(n))for(const e of n.getChildren().slice(0,t.offset))o+=e.getTextContentSize();for(let t=n.getPreviousSibling();null!==t;t=t.getPreviousSibling())o+=t.getTextContentSize();return o}function ke(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function Fe(t,n=se){const o=Q(n),r=o.element.filter(t=>t.triggerOnEnter),s=J(o.textFormat,({tag:t})=>t[t.length-1]),l=J(o.textMatch,({trigger:t})=>t),i=new Set([" "]);for(const t of o.textFormat)i.add(t.tag.slice(-1));for(const t of o.textMatch)void 0!==t.trigger&&i.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)||ye(173,e.getType())}}return p(t.registerUpdateListener(({tags:n,dirtyLeaves:r,editorState:f,prevEditorState:u})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const a=n.has(C),d=f.read(I),g=u.read(I);if(!T(g)||!T(d)||!d.isCollapsed()||d.is(g)&&!a)return;const h=d.anchor.key,p=d.anchor.offset,y=f._nodeMap.get(h);if(e(y)&&r.has(h)&&(a||1===p||!(f.read(()=>Ne(d.anchor))>u.read(()=>Ne(g.anchor))+1))){if(a){const t=f.read(()=>y.getTextContent())[p-1];if(!i.has(t))return}t.update(()=>{if(!me(y))return;const t=y.getParent();null===t||M(t)||((t,n,r)=>!!(Ee(t,n,r,o.element)||Se(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 l;return 0===r?[l]=t.splitText(s):[,l]=t.splitText(r,s),l.selectNext(0,0),e.replace(l,n),!0}return!1}(n,r,l)||function(t,n,o){const r=t.getTextContent(),s=n-1,l=r[s],i=o[l];if(!i)return!1;for(const n of i){const{tag:o}=n,i=o.length,f=s-i+1;if(i>1&&!ke(r,f,o,0,i))continue;if(" "===r[f-1])continue;const u=r[s+1];if(!1===n.intraword&&u&&!V.test(u))continue;const a=t;let d=a,g=we(r,f,o),h=d;for(;g<0&&(h=h.getPreviousSibling())&&!c(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,g=we(t,t.length,o)}if(g<0)continue;if(d===a&&g+i===f)continue;const p=d.getTextContent();if(g>0&&p[g-1]===l)continue;const x=p[g-1];if(!1===n.intraword&&x&&!V.test(x))continue;if(!n.format.includes("code")&&be(d,g))continue;const m=a.getTextContent(),C=m.slice(0,f)+m.slice(s+1);a.setTextContent(C);const v=d===a?C:p;d.setTextContent(v.slice(0,g)+v.slice(g+i));const $=I(),y=b();w(y);const E=s-i*(d===a?2:1)+1;y.anchor.set(d.__key,g,"text"),y.focus.set(a.__key,E,"text");for(const t of n.format)y.formatText(t,N[t]);y.anchor.set(y.focus.key,y.focus.offset,y.focus.type);for(const t of n.format)y.hasFormat(t)&&y.toggleFormat(t);return T($)&&(y.format=$.format),!0}return!1}(n,r,s)))(t,y,d.anchor.offset)&&v($)})}}),t.registerCommand(y,t=>{if(null!==t&&t.shiftKey)return!1;const n=I();if(!T(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,l=n.anchor.getNode();if(!e(l)||!me(l))return!1;const i=l.getParent();return null!==i&&!M(i)&&!(s!==l.getTextContent().length||!Se(i,l,s,o.multilineElement,!0)&&!Ee(i,l,s,r,!0)||(null!==t&&t.preventDefault(),0))},E))}function Oe(t,e=se,n,o=!1,r=!1){const s=o?t:le(t,r),l=n||f();l.clear(),Ie(s,l,e,o),null!==I()&&l.selectStart()}function Pe(t,e=se,n=!1,o=!1){const r=n?t:le(t,o),s=new k;return Ie(r,s,e,n),s.getChildren()}function Me(t=se,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 l=[],i=(t||f()).getChildren();for(let t=0;t<i.length;t++){const c=i[t],f=fe(c,o,s,n.textMatch,e);null!=f&&l.push(r&&t>0&&!nt(c)&&!nt(i[t-1])?"\n".concat(f):f)}return l.join("\n")}}(t,n);return o(e)}function Re(t=se,e,n=!1){if(!e||T(e)&&e.isCollapsed())return"";const o=function(t,e=!1){const n=Q(t),o=[...n.multilineElement,...n.element],r=!e,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 l=[];let i=null;for(const c of f().getChildren()){const{shouldInclude:f,markdown:u}=ie(c,t,o,s,n.textMatch,e);f&&null!=u&&(l.push(!r||null===i||nt(c)||nt(i)?u:"\n".concat(u)),i=c)}return l.join("\n")}}(t,n);return o(e)}export{Oe as $convertFromMarkdownString,Re as $convertSelectionToMarkdownString,Me as $convertToMarkdownString,Pe as $generateNodesFromMarkdownString,Zt as BOLD_ITALIC_STAR,Ht as BOLD_ITALIC_UNDERSCORE,Kt as BOLD_STAR,qt as BOLD_UNDERSCORE,Wt as CHECK_LIST,jt as CODE,te as ELEMENT_TRANSFORMERS,Lt as HEADING,Xt as HIGHLIGHT,Dt as INLINE_CODE,Jt as ITALIC_STAR,Qt as ITALIC_UNDERSCORE,Yt as LINK,ee as MULTILINE_ELEMENT_TRANSFORMERS,Ut as ORDERED_LIST,At as QUOTE,Gt as STRIKETHROUGH,ne as TEXT_FORMAT_TRANSFORMERS,oe as TEXT_MATCH_TRANSFORMERS,se as TRANSFORMERS,zt as UNORDERED_LIST,mt as isTableRowDivider,Fe as registerMarkdownShortcuts};
|
|
@@ -15,6 +15,11 @@ export declare function findOutermostTextFormatTransformer(textNode: TextNode, t
|
|
|
15
15
|
match: RegExpMatchArray;
|
|
16
16
|
isCodeSpan: boolean;
|
|
17
17
|
} | null;
|
|
18
|
+
export declare function scanCodeSpans(text: string): {
|
|
19
|
+
startIndex: number;
|
|
20
|
+
endIndex: number;
|
|
21
|
+
content: string;
|
|
22
|
+
}[];
|
|
18
23
|
export declare function importTextFormatTransformer(textNode: TextNode, startIndex: number, endIndex: number, transformer: TextFormatTransformer, match: RegExpMatchArray): {
|
|
19
24
|
transformedNode: TextNode;
|
|
20
25
|
nodeBefore: TextNode | undefined;
|
package/dist/utils.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare const WHITESPACE: RegExp;
|
|
|
19
19
|
export declare const PUNCTUATION: RegExp;
|
|
20
20
|
export declare function isEmptyParagraph(node: LexicalNode): boolean;
|
|
21
21
|
export declare function unescapeText(value: string): string;
|
|
22
|
+
export declare function isEscaped(text: string, index: number): boolean;
|
package/package.json
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.53.0",
|
|
12
12
|
"main": "./dist/LexicalMarkdown.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/code-core": "0.
|
|
16
|
-
"@lexical/internal": "0.
|
|
17
|
-
"@lexical/link": "0.
|
|
18
|
-
"@lexical/list": "0.
|
|
19
|
-
"@lexical/rich-text": "0.
|
|
20
|
-
"@lexical/selection": "0.
|
|
21
|
-
"@lexical/text": "0.
|
|
22
|
-
"@lexical/utils": "0.
|
|
23
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/code-core": "0.53.0",
|
|
16
|
+
"@lexical/internal": "0.53.0",
|
|
17
|
+
"@lexical/link": "0.53.0",
|
|
18
|
+
"@lexical/list": "0.53.0",
|
|
19
|
+
"@lexical/rich-text": "0.53.0",
|
|
20
|
+
"@lexical/selection": "0.53.0",
|
|
21
|
+
"@lexical/text": "0.53.0",
|
|
22
|
+
"@lexical/utils": "0.53.0",
|
|
23
|
+
"lexical": "0.53.0"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
package/src/MarkdownExport.ts
CHANGED
|
@@ -500,9 +500,16 @@ function exportTextFormat(
|
|
|
500
500
|
let output = textContent;
|
|
501
501
|
if (!isCode) {
|
|
502
502
|
// Preserve literal backslashes when preserving source newlines.
|
|
503
|
+
// Default mode guards numeric references; named references keep legacy output.
|
|
504
|
+
// Numeric escapes avoid changing emphasis flanking beside formatting.
|
|
505
|
+
// Guard ambiguous '<' and '&' at node ends for constructs split across nodes.
|
|
503
506
|
output = shouldPreserveNewLines
|
|
504
507
|
? output.replace(/([*_`~])/g, '\\$1')
|
|
505
|
-
: output.replace(/([*_`~\\])/g,
|
|
508
|
+
: output.replace(/([[\]*_`~\\]|<(?=\S|$)|&(?=#|$))/g, character =>
|
|
509
|
+
/[*_`~\\]/.test(character)
|
|
510
|
+
? `\\${character}`
|
|
511
|
+
: `&#${character.charCodeAt(0)};`,
|
|
512
|
+
);
|
|
506
513
|
}
|
|
507
514
|
|
|
508
515
|
let leadingSpace: string;
|
|
@@ -49,7 +49,8 @@ import {
|
|
|
49
49
|
type TextNode,
|
|
50
50
|
} from 'lexical';
|
|
51
51
|
|
|
52
|
-
import {
|
|
52
|
+
import {scanCodeSpans} from './importTextFormatTransformer';
|
|
53
|
+
import {isEmptyParagraph, isEscaped, unescapeText} from './utils';
|
|
53
54
|
|
|
54
55
|
export type Transformer =
|
|
55
56
|
| ElementTransformer
|
|
@@ -1167,6 +1168,50 @@ function escapeCharacterReferences(value: string): string {
|
|
|
1167
1168
|
);
|
|
1168
1169
|
}
|
|
1169
1170
|
|
|
1171
|
+
// Mask escaped/code brackets without changing source offsets, then find an inner
|
|
1172
|
+
// opener after a literal prefix. Return -1 for balanced labels or null when
|
|
1173
|
+
// unmatched closers leave no recoverable opener.
|
|
1174
|
+
function getLinkLabelOpener(text: string): number | null {
|
|
1175
|
+
const codeSpans = scanCodeSpans(text);
|
|
1176
|
+
let codeIndex = 0;
|
|
1177
|
+
const brackets = text.replace(/\\.|[[\]]/g, (part, index: number) => {
|
|
1178
|
+
while (
|
|
1179
|
+
codeIndex < codeSpans.length &&
|
|
1180
|
+
index >= codeSpans[codeIndex].endIndex
|
|
1181
|
+
)
|
|
1182
|
+
codeIndex++;
|
|
1183
|
+
return (codeIndex < codeSpans.length &&
|
|
1184
|
+
index >= codeSpans[codeIndex].startIndex) ||
|
|
1185
|
+
part[0] === '\\'
|
|
1186
|
+
? ' '.repeat(part.length)
|
|
1187
|
+
: part;
|
|
1188
|
+
});
|
|
1189
|
+
const openers: number[] = [];
|
|
1190
|
+
let unmatchedCloser = false;
|
|
1191
|
+
for (let index = 0; index < brackets.length; index++) {
|
|
1192
|
+
const character = brackets[index];
|
|
1193
|
+
if (character === '[') {
|
|
1194
|
+
openers.push(index);
|
|
1195
|
+
} else if (character === ']') {
|
|
1196
|
+
if (openers.pop() === undefined) unmatchedCloser = true;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return openers.pop() ?? (unmatchedCloser ? null : -1);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function unescapeLinkPrefix(text: string): string {
|
|
1203
|
+
let output = '';
|
|
1204
|
+
let previous = 0;
|
|
1205
|
+
// Keep existing code-prefix source intact; only plain text has escapes.
|
|
1206
|
+
for (const {startIndex, endIndex} of scanCodeSpans(text)) {
|
|
1207
|
+
output +=
|
|
1208
|
+
unescapeText(text.slice(previous, startIndex)) +
|
|
1209
|
+
text.slice(startIndex, endIndex);
|
|
1210
|
+
previous = endIndex;
|
|
1211
|
+
}
|
|
1212
|
+
return output + unescapeText(text.slice(previous));
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1170
1215
|
// Order of text transformers matters:
|
|
1171
1216
|
//
|
|
1172
1217
|
// - code should go first as it prevents any transformations inside
|
|
@@ -1252,7 +1297,13 @@ export const LINK: TextMatchTransformer = {
|
|
|
1252
1297
|
/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\(\s*(?:(?:<((?:\\.|[^<>\n\\])*)>|((?!<)(?:\\[^\s]|\\(?=\s)|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\]|\((?:\\[^\s]|[^\s()\\])*\))*\))*\)|[^\s()\\])+))(?:\s+(?:"((?:[^"]*\\")*[^"]*)"|'((?:[^']*\\')*[^']*)'|\(((?:\\.|[^()\\])*)\)))?\s*)?\))$/,
|
|
1253
1298
|
replace: (textNode, match) => {
|
|
1254
1299
|
// https://spec.commonmark.org/0.31.2/#inline-link
|
|
1255
|
-
|
|
1300
|
+
const source = match.input || '';
|
|
1301
|
+
const startIndex = match.index || 0;
|
|
1302
|
+
if (
|
|
1303
|
+
$findMatchingParent(textNode, $isLinkNode) ||
|
|
1304
|
+
isEscaped(source, startIndex) ||
|
|
1305
|
+
isEscaped(source, startIndex + match[1].length + 1)
|
|
1306
|
+
) {
|
|
1256
1307
|
return;
|
|
1257
1308
|
}
|
|
1258
1309
|
const [
|
|
@@ -1274,16 +1325,14 @@ export const LINK: TextMatchTransformer = {
|
|
|
1274
1325
|
const linkTitle =
|
|
1275
1326
|
rawLinkTitle != null ? unescapeText(rawLinkTitle) : undefined;
|
|
1276
1327
|
const linkNode = $createLinkNode(linkUrl, {title: linkTitle});
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1328
|
+
const openBracketIndex = getLinkLabelOpener(linkText);
|
|
1329
|
+
if (openBracketIndex === null) return;
|
|
1279
1330
|
let parsedLinkText = linkText;
|
|
1280
1331
|
let outsideLinkText = '';
|
|
1281
|
-
if (
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
outsideLinkText = '[' + linkTextParts[0];
|
|
1286
|
-
parsedLinkText = linkTextParts.slice(1).join('[');
|
|
1332
|
+
if (openBracketIndex !== -1) {
|
|
1333
|
+
outsideLinkText =
|
|
1334
|
+
'[' + unescapeLinkPrefix(linkText.slice(0, openBracketIndex));
|
|
1335
|
+
parsedLinkText = linkText.slice(openBracketIndex + 1);
|
|
1287
1336
|
}
|
|
1288
1337
|
// Both new nodes stand in for the TextNode being replaced, so the text
|
|
1289
1338
|
// left outside the link carries its inline format just like the link's own
|
|
@@ -124,7 +124,7 @@ export function findOutermostTextFormatTransformer(
|
|
|
124
124
|
// rules: https://spec.commonmark.org/#code-spans. A run opens a span and the
|
|
125
125
|
// next run of equal length closes it. An escaped backtick (`\``) cannot open a
|
|
126
126
|
// span, but backslashes are otherwise literal and don't prevent closing.
|
|
127
|
-
function scanCodeSpans(text: string): {
|
|
127
|
+
export function scanCodeSpans(text: string): {
|
|
128
128
|
startIndex: number;
|
|
129
129
|
endIndex: number;
|
|
130
130
|
content: string;
|
|
@@ -8,6 +8,22 @@
|
|
|
8
8
|
import type {TextMatchTransformer} from './MarkdownTransformers';
|
|
9
9
|
import type {TextNode} from 'lexical';
|
|
10
10
|
|
|
11
|
+
import {LINK} from './MarkdownTransformers';
|
|
12
|
+
import {isEscaped} from './utils';
|
|
13
|
+
|
|
14
|
+
function matchLink(text: string, regExp: RegExp): RegExpExecArray | null {
|
|
15
|
+
const search = new RegExp(
|
|
16
|
+
regExp.source,
|
|
17
|
+
regExp.flags.replace(/[gy]/g, '') + 'g',
|
|
18
|
+
);
|
|
19
|
+
let match;
|
|
20
|
+
while ((match = search.exec(text)) !== null) {
|
|
21
|
+
if (!isEscaped(text, match.index)) return match;
|
|
22
|
+
search.lastIndex = match.index + 1;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
export function findOutermostTextMatchTransformer(
|
|
12
28
|
textNode_: TextNode,
|
|
13
29
|
textMatchTransformers: TextMatchTransformer[],
|
|
@@ -28,7 +44,13 @@ export function findOutermostTextMatchTransformer(
|
|
|
28
44
|
if (!transformer.replace || !transformer.importRegExp) {
|
|
29
45
|
continue;
|
|
30
46
|
}
|
|
31
|
-
const
|
|
47
|
+
const text = textNode.getTextContent();
|
|
48
|
+
// Transformers sharing the built-in link syntax need the same candidate rules.
|
|
49
|
+
const match =
|
|
50
|
+
LINK.importRegExp !== undefined &&
|
|
51
|
+
transformer.importRegExp.source === LINK.importRegExp.source
|
|
52
|
+
? matchLink(text, transformer.importRegExp)
|
|
53
|
+
: text.match(transformer.importRegExp);
|
|
32
54
|
|
|
33
55
|
if (!match) {
|
|
34
56
|
continue;
|
package/src/utils.ts
CHANGED
|
@@ -76,12 +76,16 @@ export function isEmptyParagraph(node: LexicalNode): boolean {
|
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
//
|
|
79
|
+
// Numeric references have one to seven decimal or one to six hexadecimal digits.
|
|
80
|
+
// A reference that names
|
|
80
81
|
// U+0000, a surrogate or a number past U+10FFFF reads as U+FFFD instead of
|
|
81
82
|
// making `String.fromCodePoint` throw.
|
|
82
83
|
// https://spec.commonmark.org/0.31.2/#decimal-numeric-character
|
|
83
|
-
function
|
|
84
|
-
|
|
84
|
+
function decodeCharacterReference(
|
|
85
|
+
digits: string | undefined,
|
|
86
|
+
hex: string | undefined,
|
|
87
|
+
): string {
|
|
88
|
+
const codePoint = digits !== undefined ? Number(digits) : parseInt(hex!, 16);
|
|
85
89
|
return codePoint === 0 ||
|
|
86
90
|
(codePoint >= 0xd800 && codePoint <= 0xdfff) ||
|
|
87
91
|
codePoint > 0x10ffff
|
|
@@ -90,7 +94,22 @@ function decodeDecimalCharacterReference(_: string, digits: string): string {
|
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
export function unescapeText(value: string): string {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
// Do not decode an escaped ampersand or revisit a decoded reference.
|
|
98
|
+
return value.replace(
|
|
99
|
+
/\\([!-/:-@[-`{-~])|&#(?:(\d{1,7})|[xX]([\da-fA-F]{1,6}));/g,
|
|
100
|
+
(
|
|
101
|
+
_match,
|
|
102
|
+
escaped: string | undefined,
|
|
103
|
+
digits: string | undefined,
|
|
104
|
+
hex: string | undefined,
|
|
105
|
+
) => escaped ?? decodeCharacterReference(digits, hex),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isEscaped(text: string, index: number): boolean {
|
|
110
|
+
let backslashes = 0;
|
|
111
|
+
for (let i = index - 1; i >= 0 && text[i] === '\\'; i--) {
|
|
112
|
+
backslashes++;
|
|
113
|
+
}
|
|
114
|
+
return backslashes % 2 === 1;
|
|
96
115
|
}
|