@lexical/markdown 0.43.1-nightly.20260416.0 → 0.44.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.
@@ -1043,7 +1043,11 @@ const $listExport = (listNode, exportChildren, depth) => {
1043
1043
  const listType = listNode.getListType();
1044
1044
  const listMarker = lexical.$getState(listNode, listMarkerState);
1045
1045
  const prefix = listType === 'number' ? `${listNode.getStart() + index}. ` : listType === 'check' ? `${listMarker} [${listItemNode.getChecked() ? 'x' : ' '}] ` : listMarker + ' ';
1046
- output.push(indent + prefix + exportChildren(listItemNode));
1046
+ let childrenText = exportChildren(listItemNode);
1047
+ if (listType !== 'number') {
1048
+ childrenText = childrenText.replace(/^(\s{0,3}\d+)(\.\s)/, '$1\\$2');
1049
+ }
1050
+ output.push(indent + prefix + childrenText);
1047
1051
  index++;
1048
1052
  }
1049
1053
  }
@@ -1570,6 +1574,11 @@ function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransfor
1570
1574
  continue;
1571
1575
  }
1572
1576
 
1577
+ // Per CommonMark, code spans take precedence over other inline formatting
1578
+ if (!matcher.format.includes('code') && $isInsideUnclosedCodeSpan(openNode, openTagStartIndex)) {
1579
+ continue;
1580
+ }
1581
+
1573
1582
  // Clean text from opening and closing tags (starting from closing tag
1574
1583
  // to prevent any offset shifts if we start from opening one)
1575
1584
  const prevCloseNodeText = closeNode.getTextContent();
@@ -1608,6 +1617,21 @@ function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransfor
1608
1617
  }
1609
1618
  return false;
1610
1619
  }
1620
+
1621
+ // Per CommonMark spec, code spans take precedence over other inline
1622
+ // formatting. Returns true if there is an unclosed backtick (code span
1623
+ // opener) in the text preceding the given offset, which means the offset
1624
+ // is inside a code span that hasn't been closed yet.
1625
+ function $isInsideUnclosedCodeSpan(node, offset) {
1626
+ let backtickCount = 0;
1627
+ const text = node.getTextContent();
1628
+ for (let i = 0; i < offset; i++) {
1629
+ if (text[i] === '`') {
1630
+ backtickCount++;
1631
+ }
1632
+ }
1633
+ return backtickCount % 2 !== 0;
1634
+ }
1611
1635
  function getOpenTagStartIndex(string, maxIndex, tag) {
1612
1636
  const tagLength = tag.length;
1613
1637
  for (let i = maxIndex; i >= tagLength; i--) {
@@ -1651,15 +1675,18 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
1651
1675
  }
1652
1676
  const $transform = (parentNode, anchorNode, anchorOffset) => {
1653
1677
  if (runElementTransformers(parentNode, anchorNode, anchorOffset, byType.element)) {
1654
- return;
1678
+ return true;
1655
1679
  }
1656
1680
  if (runMultilineElementTransformers(parentNode, anchorNode, anchorOffset, byType.multilineElement)) {
1657
- return;
1681
+ return true;
1658
1682
  }
1659
1683
  if (runTextMatchTransformers(anchorNode, anchorOffset, textMatchTransformersByTrigger)) {
1660
- return;
1684
+ return true;
1661
1685
  }
1662
- $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformersByTrigger);
1686
+ if ($runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformersByTrigger)) {
1687
+ return true;
1688
+ }
1689
+ return false;
1663
1690
  };
1664
1691
  return lexical.mergeRegister(editor.registerUpdateListener(({
1665
1692
  tags,
@@ -1698,7 +1725,9 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
1698
1725
  if (parentNode === null || codeCore.$isCodeNode(parentNode)) {
1699
1726
  return;
1700
1727
  }
1701
- $transform(parentNode, anchorNode, selection.anchor.offset);
1728
+ if ($transform(parentNode, anchorNode, selection.anchor.offset)) {
1729
+ lexical.$addUpdateTag(lexical.HISTORY_PUSH_TAG);
1730
+ }
1702
1731
  });
1703
1732
  }), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
1704
1733
  if (event !== null && event.shiftKey) {
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- import { $isParagraphNode, $isTextNode, $getRoot, $isElementNode, $isDecoratorNode, $isLineBreakNode, $getSelection, $createTextNode, $createParagraphNode, $createLineBreakNode, $createTabNode, createState, $setState, $getState, $findMatchingParent as $findMatchingParent$1, mergeRegister, COLLABORATION_TAG, HISTORIC_TAG, $isRangeSelection, KEY_ENTER_COMMAND, COMMAND_PRIORITY_LOW, $isRootOrShadowRoot, $createRangeSelection, $setSelection } from 'lexical';
9
+ import { $isParagraphNode, $isTextNode, $getRoot, $isElementNode, $isDecoratorNode, $isLineBreakNode, $getSelection, $createTextNode, $createParagraphNode, $createLineBreakNode, $createTabNode, createState, $setState, $getState, $findMatchingParent as $findMatchingParent$1, mergeRegister, COLLABORATION_TAG, HISTORIC_TAG, $isRangeSelection, $addUpdateTag, HISTORY_PUSH_TAG, KEY_ENTER_COMMAND, COMMAND_PRIORITY_LOW, $isRootOrShadowRoot, $createRangeSelection, $setSelection } from 'lexical';
10
10
  import { $isListNode, $isListItemNode, ListNode, ListItemNode, $createListItemNode, $createListNode } from '@lexical/list';
11
11
  import { $isQuoteNode, HeadingNode, QuoteNode, $isHeadingNode, $createQuoteNode, $createHeadingNode } from '@lexical/rich-text';
12
12
  import { $findMatchingParent } from '@lexical/utils';
@@ -1041,7 +1041,11 @@ const $listExport = (listNode, exportChildren, depth) => {
1041
1041
  const listType = listNode.getListType();
1042
1042
  const listMarker = $getState(listNode, listMarkerState);
1043
1043
  const prefix = listType === 'number' ? `${listNode.getStart() + index}. ` : listType === 'check' ? `${listMarker} [${listItemNode.getChecked() ? 'x' : ' '}] ` : listMarker + ' ';
1044
- output.push(indent + prefix + exportChildren(listItemNode));
1044
+ let childrenText = exportChildren(listItemNode);
1045
+ if (listType !== 'number') {
1046
+ childrenText = childrenText.replace(/^(\s{0,3}\d+)(\.\s)/, '$1\\$2');
1047
+ }
1048
+ output.push(indent + prefix + childrenText);
1045
1049
  index++;
1046
1050
  }
1047
1051
  }
@@ -1568,6 +1572,11 @@ function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransfor
1568
1572
  continue;
1569
1573
  }
1570
1574
 
1575
+ // Per CommonMark, code spans take precedence over other inline formatting
1576
+ if (!matcher.format.includes('code') && $isInsideUnclosedCodeSpan(openNode, openTagStartIndex)) {
1577
+ continue;
1578
+ }
1579
+
1571
1580
  // Clean text from opening and closing tags (starting from closing tag
1572
1581
  // to prevent any offset shifts if we start from opening one)
1573
1582
  const prevCloseNodeText = closeNode.getTextContent();
@@ -1606,6 +1615,21 @@ function $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransfor
1606
1615
  }
1607
1616
  return false;
1608
1617
  }
1618
+
1619
+ // Per CommonMark spec, code spans take precedence over other inline
1620
+ // formatting. Returns true if there is an unclosed backtick (code span
1621
+ // opener) in the text preceding the given offset, which means the offset
1622
+ // is inside a code span that hasn't been closed yet.
1623
+ function $isInsideUnclosedCodeSpan(node, offset) {
1624
+ let backtickCount = 0;
1625
+ const text = node.getTextContent();
1626
+ for (let i = 0; i < offset; i++) {
1627
+ if (text[i] === '`') {
1628
+ backtickCount++;
1629
+ }
1630
+ }
1631
+ return backtickCount % 2 !== 0;
1632
+ }
1609
1633
  function getOpenTagStartIndex(string, maxIndex, tag) {
1610
1634
  const tagLength = tag.length;
1611
1635
  for (let i = maxIndex; i >= tagLength; i--) {
@@ -1649,15 +1673,18 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
1649
1673
  }
1650
1674
  const $transform = (parentNode, anchorNode, anchorOffset) => {
1651
1675
  if (runElementTransformers(parentNode, anchorNode, anchorOffset, byType.element)) {
1652
- return;
1676
+ return true;
1653
1677
  }
1654
1678
  if (runMultilineElementTransformers(parentNode, anchorNode, anchorOffset, byType.multilineElement)) {
1655
- return;
1679
+ return true;
1656
1680
  }
1657
1681
  if (runTextMatchTransformers(anchorNode, anchorOffset, textMatchTransformersByTrigger)) {
1658
- return;
1682
+ return true;
1659
1683
  }
1660
- $runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformersByTrigger);
1684
+ if ($runTextFormatTransformers(anchorNode, anchorOffset, textFormatTransformersByTrigger)) {
1685
+ return true;
1686
+ }
1687
+ return false;
1661
1688
  };
1662
1689
  return mergeRegister(editor.registerUpdateListener(({
1663
1690
  tags,
@@ -1696,7 +1723,9 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
1696
1723
  if (parentNode === null || $isCodeNode(parentNode)) {
1697
1724
  return;
1698
1725
  }
1699
- $transform(parentNode, anchorNode, selection.anchor.offset);
1726
+ if ($transform(parentNode, anchorNode, selection.anchor.offset)) {
1727
+ $addUpdateTag(HISTORY_PUSH_TAG);
1728
+ }
1700
1729
  });
1701
1730
  }), editor.registerCommand(KEY_ENTER_COMMAND, event => {
1702
1731
  if (event !== null && event.shiftKey) {
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical"),t=require("@lexical/list"),n=require("@lexical/rich-text"),o=require("@lexical/utils"),r=require("@lexical/code-core"),s=require("@lexical/link");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 c(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 l=/[!-/:-@[-`{-~\s]/,a=/[ \t\n\r\f]/,d=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,f=/^\s{0,3}$/;function g(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 u(e){return e.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}function p(t,n,o,r,s){for(const e of n){if(!e.export)continue;const n=e.export(t,e=>x(e,o,r,void 0,void 0,s));if(null!=n)return n}return e.$isElementNode(t)?x(t,o,r,void 0,void 0,s):e.$isDecoratorNode(t)?t.getTextContent():null}function x(t,n,o,r,s,i=!1){const c=[],l=t.getChildren();r||(r=[]),s||(s=[]);e:for(const t of l){for(const e of o){if(!e.export)continue;const l=e.export(t,e=>x(e,n,o,r,[...s,...r],i),(e,t)=>h(e,t,n,r,s,i));if(null!=l){c.push(l);continue e}}e.$isLineBreakNode(t)?c.push("\n"):e.$isTextNode(t)?c.push(h(t,t.getTextContent(),n,r,s,i)):e.$isElementNode(t)?c.push(x(t,n,o,r,s,i)):e.$isDecoratorNode(t)&&c.push(t.getTextContent())}return c.join("")}function h(e,t,n,o,r,s=!1){let i=t;e.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const c=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],l=c[1],a=c[2],d=c[3],f=""===a;let g="",u="",p="";const x=m(e,!0),h=m(e,!1),T=new Set;for(const t of n){const n=t.format[0],r=t.tag;N(e,n)&&!T.has(n)&&(T.add(n),N(x,n)&&o.find(e=>e.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let t=0;t<o.length;t++){const n=$(e,o[t].format),s=$(h,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):u+=e.tag),o.pop())}break}return f&&!e.hasFormat("code")?u+i:u+l+g+a+p+d}function m(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e.$isTextNode(o)?o:null}function $(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function N(e,t){return!!$(e,t)&&("code"===t||(!e||!/^\s*$/.test(e.getTextContent())))}function T(e,t){const n=e.getTextContent(),o=t.fullMatchRegExpByTag["`"],r=t.transformersByTag["`"],s=[];let i=null;if(o&&r){const e=new RegExp(o.source,"g"),t=Array.from(n.matchAll(e));for(const e of t){const t=e.index+e[1].length,n=e.index+e[0].length;i||(i={content:e[3],endIndex:n,startIndex:t,tag:"`"}),s.push({end:n,start:t})}}const c=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 c=0;for(;c<e.length;){const t=e[c];if(!r.has(t)||s(c)||i(c)){c++;continue}let n=1;for(;c+n<e.length&&e[c+n]===t;)n++;const l=E(t,e,c,n,!0),a=E(t,e,c,n,!1);(l||a)&&o.push({active:!0,canClose:a,canOpen:l,char:t,index:c,length:n,originalLength:n}),c+=n}return o}(n,t,s),l=c.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 c=`${i.char}${i.canOpen}`,l=o[c]??-1;let a=!1;for(let o=r-1;o>l;o--){const c=t[o];if(!c.active||!c.canOpen||0===c.length||c.char!==i.char)continue;if(c.canClose||i.canOpen){if((c.originalLength+i.originalLength)%3==0&&c.originalLength%3!=0&&i.originalLength%3!=0)continue}const l=Math.min(c.length,i.length),d=Object.keys(n.transformersByTag).filter(e=>e[0]===c.char&&e.length<=l).sort((e,t)=>t.length-e.length)[0];if(!d)continue;a=!0;const f=d.length,g={content:e.slice(c.index+c.length,i.index),endIndex:i.index+f,startIndex:c.index+(c.length-f),tag:d};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);for(let e=o+1;e<r;e++)t[e].active=!1;c.length-=f,i.length-=f,c.active=c.length>0,i.length>0?i.index+=f:(i.active=!1,r++);break}a||(o[c]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,c,t):null;let a=null,d=null;if(i&&l?l.startIndex<=i.startIndex&&l.endIndex>=i.endIndex?(a=l,d=t.transformersByTag[l.tag]):(a=i,d=r):i?(a=i,d=r):l&&(a=l,d=t.transformersByTag[l.tag]),!a||!d)return null;const f=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return f.index=a.startIndex,f.input=n,{endIndex:a.endIndex,match:f,startIndex:a.startIndex,transformer:d}}function E(e,t,n,o,r){if(!C(t,n,o,r))return!1;if("*"===e)return!0;if("_"===e){if(!C(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 C(e,t,n,o){const r=e[t-1],s=e[t+n],[i,c]=o?[s,r]:[r,s];return void 0!==i&&!a.test(i)&&(!d.test(i)||(void 0===c||a.test(c)||d.test(c)))}function S(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function I(e,t,n){let o=T(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 c=t.index||0,l=e.getEndIndex?e.getEndIndex(n,t):c+t[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&(l>r||l<=o))&&(o=c,r=l,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.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,c,l;if(r[0]===s?i=e:0===t?[i,c]=e.splitText(n):[l,i,c]=e.splitText(t,n),i.setTextContent(r[2]),o)for(const e of o.format)i.hasFormat(e)||i.toggleFormat(e);return{nodeAfter:c,nodeBefore:l,transformedNode:i}}(e,o.startIndex,o.endIndex,o.transformer,o.match);S(r.nodeAfter)&&I(r.nodeAfter,t,n),S(r.nodeBefore)&&I(r.nodeBefore,t,n),S(r.transformedNode)&&I(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let s,i,c;return 0===t?[s,i]=e.splitText(n):[c,s,i]=e.splitText(t,n),o.replace?{nodeAfter:i,nodeBefore:c,transformedNode:o.replace(s,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;S(o.nodeAfter)&&I(o.nodeAfter,t,n),S(o.nodeBefore)&&I(o.nodeBefore,t,n),S(o.transformedNode)&&I(o.transformedNode,t,n)}const s=u(e.getTextContent());e.setTextContent(s)}function L(t,n=!1){const o=c(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"),c=i.length,l=s||e.$getRoot();l.clear();for(let e=0;e<c;e++){const t=i[e],[s,c]=R(i,e,o.multilineElement,l);s?e=c:v(t,l,o.element,r,o.textMatch,n)}const a=l.getChildren();for(const t of a)if(!n&&g(t)&&l.getChildrenSize()>1)t.remove();else if(e.$isElementNode(t))for(const e of t.getAllTextNodes())y(e);null!==e.$getSelection()&&l.selectStart()}}function R(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:c}=r,l=e[t].match(i);if(!l)continue;if(n){const s=n({lines:e,rootNode:o,startLineIndex:t,startMatch:l,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 g=e.length;for(;f<g;){const n=a?e[f].match(a):null;if(!n&&(!d||d&&f<g-1)){f++;continue}if(n&&t===f&&n.index===l.index){f++;continue}const r=[];if(n&&t===f)r.push(e[t].slice(l[0].length,-n[0].length));else for(let o=t;o<=f;o++)if(o===t){const t=e[o].slice(l[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!==c(o,null,l,n,r,!0))return[!0,f];break}}return[!1,t]}function v(r,s,i,c,l,a){const d=e.$createTextNode(r),f=e.$createParagraphNode();f.append(d),s.append(f);for(const{regExp:e,replace:t}of i){const n=r.match(e);if(n&&(d.setTextContent(r.slice(n[0].length)),!1!==t(f,[d],n,!0)))break}if(I(d,c,l),f.isAttached()&&r.length>0){const r=f.getPreviousSibling();if(!a&&(e.$isParagraphNode(r)||n.$isQuoteNode(r)||t.$isListNode(r))){let n=r;if(t.$isListNode(r)){const e=r.getLastDescendant();n=null==e?null:o.$findMatchingParent(e,t.$isListItemNode)}if(null!=n&&n.getTextContentSize()>0){const t=n.getLastChild();if(e.$isTextNode(t)){const e=t.getTextContent();e.endsWith("\\")?t.setTextContent(e.slice(0,-1)):/ {2,}$/.test(e)&&t.setTextContent(e.replace(/ {2,}$/,""))}n.splice(n.getChildrenSize(),0,[e.$createLineBreakNode(),...f.getChildren()]),f.remove()}}}}function y(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 O(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.`)}const _=/^(\s*)(\d{1,})\.\s/,M=/^(\s*)[-*+]\s/,A=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,b=/^(#{1,6})\s/,k=/^>\s/,F=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,w=/^[ \t]*`{3,}$/,B=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,D=/^(?:\|)(.+)(?:\|)\s?$/,P=/^(\| ?:?-*:? ?)+\|\s?$/,j=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,H=/^<\/[a-z_][\w-]*\s*>/i,U=e=>new RegExp(`(?:${e.source})$`,e.flags),z=e.createState("mdListMarker",{parse:e=>"string"==typeof e&&/^[-*+]$/.test(e)?e:"-",resetOnCopyNode:!0}),q=e.createState("mdCodeFence",{parse:e=>"string"==typeof e&&/^`{3,}$/.test(e)?e:"```",resetOnCopyNode:!0}),G=e=>(t,n,o,r)=>{const s=e(o);s.append(...n),t.replace(s),r||s.select(0,0)};const Q=n=>(o,r,s,i)=>{const c=o.getPreviousSibling(),l=o.getNextSibling(),a=t.$createListItemNode("check"===n?"x"===s[3]:void 0),d=s[0].trim()[0],f="bullet"!==n&&"check"!==n||d!==z.parse(d)?void 0:d;if(t.$isListNode(l)&&l.getListType()===n){f&&e.$setState(l,z,f);const t=l.getFirstChild();null!==t?t.insertBefore(a):l.append(a),o.remove()}else if(t.$isListNode(c)&&c.getListType()===n)f&&e.$setState(c,z,f),c.append(a),o.remove();else{const r=t.$createListNode(n,"number"===n?Number(s[2]):void 0);f&&e.$setState(r,z,f),r.append(a),o.replace(r)}a.append(...r),i||a.select(0,0);const g=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]);g&&a.setIndent(g)},W=(n,o,r)=>{const s=[],i=n.getChildren();let c=0;for(const l of i)if(t.$isListItemNode(l)){if(1===l.getChildrenSize()){const e=l.getFirstChild();if(t.$isListNode(e)){s.push(W(e,o,r+1));continue}}const i=" ".repeat(4*r),a=n.getListType(),d=e.$getState(n,z),f="number"===a?`${n.getStart()+c}. `:"check"===a?`${d} [${l.getChecked()?"x":" "}] `:d+" ";s.push(i+f+o(l)),c++}return s.join("\n")},K={dependencies:[n.HeadingNode],export:(e,t)=>{if(!n.$isHeadingNode(e))return null;const o=Number(e.getTag().slice(1));return"#".repeat(o)+" "+t(e)},regExp:b,replace:G(e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)}),type:"element"},X={dependencies:[n.QuoteNode],export:(e,t)=>{if(!n.$isQuoteNode(e))return null;const o=t(e).split("\n"),r=[];for(const e of o)r.push("> "+e);return r.join("\n")},regExp:k,replace:(t,o,r,s)=>{if(s){const r=t.getPreviousSibling();if(n.$isQuoteNode(r))return r.splice(r.getChildrenSize(),0,[e.$createLineBreakNode(),...o]),void t.remove()}const i=n.$createQuoteNode();i.append(...o),t.replace(i),s||i.select(0,0)},type:"element"},Y={dependencies:[r.CodeNode],export:t=>{if(!r.$isCodeNode(t))return null;const n=t.getTextContent();let o=e.$getState(t,q);if(n.indexOf(o)>-1){const e=n.match(/`{3,}/g);if(e){const t=Math.max(...e.map(e=>e.length));o="`".repeat(t+1)}}return o+(t.getLanguage()||"")+(n?"\n"+n:"")+"\n"+o},handleImportAfterStartMatch:({lines:e,rootNode:t,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=e[n],c=o.index+r.length,l=i.slice(c),a=new RegExp(`\`{${s},}$`);if(a.test(l)){const e=l.match(a),r=l.slice(0,l.lastIndexOf(e[0])),s=[...o];return s[2]="",Y.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 c=s.match(d),l=e.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&l.unshift(a),Y.replace(t,null,o,c,l,!0),[!0,r]}}const f=e.slice(n+1),g=i.slice(o[0].length);return g.length>0&&f.unshift(g),Y.replace(t,null,o,null,f,!0),[!0,e.length-1]},regExpEnd:{optional:!0,regExp:w},regExpStart:F,replace:(t,n,o,s,i,c)=>{let l,a;const d=o[1]?o[1].trim():"```",f=o[2]||void 0;if(!n&&i){if(1===i.length)s?(l=r.$createCodeNode(f),a=i[0]):(l=r.$createCodeNode(f),a=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(l=r.$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(l,q,d);const n=e.$createTextNode(a);l.append(n),t.append(l)}else n&&G(e=>r.$createCodeNode(e?e[2]:void 0))(t,n,o,c)},type:"multiline-element"},J={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:M,replace:Q("bullet"),type:"element"},V={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:A,replace:Q("check"),type:"element"},Z={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:_,replace:Q("number"),type:"element"},ee={format:["code"],tag:"`",type:"text-format"},te={format:["highlight"],tag:"==",type:"text-format"},ne={format:["bold","italic"],tag:"***",type:"text-format"},oe={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},re={format:["bold"],tag:"**",type:"text-format"},se={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ie={format:["strikethrough"],tag:"~~",type:"text-format"},ce={format:["italic"],tag:"*",type:"text-format"},le={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ae={dependencies:[s.LinkNode],export:(e,t,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o=t(e);let r=e.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${e.getURL()} "${r}")`:`[${o}](${e.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{if(e.$findMatchingParent(t,s.$isLinkNode))return;const[,o,r,i]=n,c=null!=r?u(r):void 0,l=null!=i?u(i):void 0,a=s.$createLinkNode(c,{title:l}),d=o.split("[").length-1,f=o.split("]").length-1;let g=o,p="";if(d<f)return;if(d>f){const e=o.split("[");p="["+e[0],g=e.slice(1).join("[")}const x=e.$createTextNode(g);return x.setFormat(t.getFormat()),a.append(x),t.replace(a),p&&a.insertBefore(e.$createTextNode(p)),x},trigger:")",type:"text-match"},de=[K,X,J,Z],fe=[Y],ge=[ee,ne,oe,re,se,te,ce,le,ie],ue=[ae],pe=[...de,...fe,...ge,...ue];function xe(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const c=n.getTextContent();if(!s&&" "!==c[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:l}of r){if(l&&!("optional"in l)||l&&"optional"in l&&!l.optional)continue;const r=c.match(e);if(r){const e=s||r[0].endsWith(" ")?o:o-1;if(r[0].length!==e)continue;const c=n.getNextSiblings(),[l,a]=n.splitText(o);if(!1!==i(t,a?[a,...c]:c,r,null,null,!1))return l.remove(),!0}}return!1}function he(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(me(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function me(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=pe,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(),c=r[r.length-1];B.test(i)?r.push(i):F.test(i)||w.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===c||!c||b.test(c)||b.test(i)||k.test(i)||_.test(i)||M.test(i)||A.test(i)||D.test(i)||P.test(i)||!t||j.test(i)||H.test(i)||U(H).test(c)||U(j).test(c)||w.test(c)?r.push(t||""===i?i:s):r[r.length-1]=c+" "+i.trimStart()}return r.join("\n")}(e,r);return L(t,o)(s,n)},exports.$convertToMarkdownString=function(t=pe,n,o=!1){return function(t,n=!1){const o=c(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 c=[],l=(t||e.$getRoot()).getChildren();for(let e=0;e<l.length;e++){const t=l[e],a=p(t,r,i,o.textMatch,n);null!=a&&c.push(s&&e>0&&!g(t)&&!g(l[e-1])?"\n".concat(a):a)}return c.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=ne,exports.BOLD_ITALIC_UNDERSCORE=oe,exports.BOLD_STAR=re,exports.BOLD_UNDERSCORE=se,exports.CHECK_LIST=V,exports.CODE=Y,exports.ELEMENT_TRANSFORMERS=de,exports.HEADING=K,exports.HIGHLIGHT=te,exports.INLINE_CODE=ee,exports.ITALIC_STAR=ce,exports.ITALIC_UNDERSCORE=le,exports.LINK=ae,exports.MULTILINE_ELEMENT_TRANSFORMERS=fe,exports.ORDERED_LIST=Z,exports.QUOTE=X,exports.STRIKETHROUGH=ie,exports.TEXT_FORMAT_TRANSFORMERS=ge,exports.TEXT_MATCH_TRANSFORMERS=ue,exports.TRANSFORMERS=pe,exports.UNORDERED_LIST=J,exports.registerMarkdownShortcuts=function(t,n=pe){const o=c(n),s=i(o.textFormat,({tag:e})=>e[e.length-1]),a=i(o.textMatch,({trigger:e})=>e);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)||O(173,e.getType())}}const d=(t,n,r)=>{(function(t,n,o,r){const s=t.getParent();if(!e.$isRootOrShadowRoot(s)||t.getFirstChild()!==n)return!1;const i=n.getTextContent();if(" "!==i[o-1])return!1;for(const{regExp:e,replace:s}of r){const r=i.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[i,c]=n.splitText(o);if(!1!==s(t,c?[c,...e]:e,r,!1))return i.remove(),!0}}return!1})(t,n,r,o.element)||xe(t,n,r,o.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,r,a)||function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],c=o[i];if(!c)return!1;for(const n of c){const{tag:o}=n,c=o.length,a=s-c+1;if(c>1&&!me(r,a,o,0,c))continue;if(" "===r[a-1])continue;const d=r[s+1];if(!1===n.intraword&&d&&!l.test(d))continue;const f=t;let g=f,u=he(r,a,o),p=g;for(;u<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();g=p,u=he(e,e.length,o)}if(u<0)continue;if(g===f&&u+c===a)continue;const x=g.getTextContent();if(u>0&&x[u-1]===i)continue;const h=x[u-1];if(!1===n.intraword&&h&&!l.test(h))continue;const m=f.getTextContent(),$=m.slice(0,a)+m.slice(s+1);f.setTextContent($);const N=g===f?$:x;g.setTextContent(N.slice(0,u)+N.slice(u+c));const T=e.$getSelection(),E=e.$createRangeSelection();e.$setSelection(E);const C=s-c*(g===f?2:1)+1;E.anchor.set(g.__key,u,"text"),E.focus.set(f.__key,C,"text");for(const e of n.format)E.hasFormat(e)||E.formatText(e);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const e of n.format)E.hasFormat(e)&&E.toggleFormat(e);return e.$isRangeSelection(T)&&(E.format=T.format),!0}}(n,r,s)};return e.mergeRegister(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:s,prevEditorState:i})=>{if(n.has(e.COLLABORATION_TAG)||n.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const c=s.read(e.$getSelection),l=i.read(e.$getSelection);if(!e.$isRangeSelection(l)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(l))return;const a=c.anchor.key,f=c.anchor.offset,g=s._nodeMap.get(a);!e.$isTextNode(g)||!o.has(a)||1!==f&&f>l.anchor.offset+1||t.update(()=>{if(!S(g))return;const e=g.getParent();null===e||r.$isCodeNode(e)||d(e,g,c.anchor.offset)})}),t.registerCommand(e.KEY_ENTER_COMMAND,t=>{if(null!==t&&t.shiftKey)return!1;const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e.$isTextNode(i)||!S(i))return!1;const c=i.getParent();if(null===c||r.$isCodeNode(c))return!1;return s===i.getTextContent().length&&(!!xe(c,i,s,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},e.COMMAND_PRIORITY_LOW))};
9
+ "use strict";var e=require("lexical"),t=require("@lexical/list"),n=require("@lexical/rich-text"),o=require("@lexical/utils"),r=require("@lexical/code-core"),s=require("@lexical/link");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 c(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 l=/[!-/:-@[-`{-~\s]/,a=/[ \t\n\r\f]/,d=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,f=/^\s{0,3}$/;function g(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 u(e){return e.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}function p(t,n,o,r,s){for(const e of n){if(!e.export)continue;const n=e.export(t,e=>x(e,o,r,void 0,void 0,s));if(null!=n)return n}return e.$isElementNode(t)?x(t,o,r,void 0,void 0,s):e.$isDecoratorNode(t)?t.getTextContent():null}function x(t,n,o,r,s,i=!1){const c=[],l=t.getChildren();r||(r=[]),s||(s=[]);e:for(const t of l){for(const e of o){if(!e.export)continue;const l=e.export(t,e=>x(e,n,o,r,[...s,...r],i),(e,t)=>h(e,t,n,r,s,i));if(null!=l){c.push(l);continue e}}e.$isLineBreakNode(t)?c.push("\n"):e.$isTextNode(t)?c.push(h(t,t.getTextContent(),n,r,s,i)):e.$isElementNode(t)?c.push(x(t,n,o,r,s,i)):e.$isDecoratorNode(t)&&c.push(t.getTextContent())}return c.join("")}function h(e,t,n,o,r,s=!1){let i=t;e.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const c=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],l=c[1],a=c[2],d=c[3],f=""===a;let g="",u="",p="";const x=m(e,!0),h=m(e,!1),T=new Set;for(const t of n){const n=t.format[0],r=t.tag;N(e,n)&&!T.has(n)&&(T.add(n),N(x,n)&&o.find(e=>e.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let t=0;t<o.length;t++){const n=$(e,o[t].format),s=$(h,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):u+=e.tag),o.pop())}break}return f&&!e.hasFormat("code")?u+i:u+l+g+a+p+d}function m(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e.$isTextNode(o)?o:null}function $(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function N(e,t){return!!$(e,t)&&("code"===t||(!e||!/^\s*$/.test(e.getTextContent())))}function T(e,t){const n=e.getTextContent(),o=t.fullMatchRegExpByTag["`"],r=t.transformersByTag["`"],s=[];let i=null;if(o&&r){const e=new RegExp(o.source,"g"),t=Array.from(n.matchAll(e));for(const e of t){const t=e.index+e[1].length,n=e.index+e[0].length;i||(i={content:e[3],endIndex:n,startIndex:t,tag:"`"}),s.push({end:n,start:t})}}const c=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 c=0;for(;c<e.length;){const t=e[c];if(!r.has(t)||s(c)||i(c)){c++;continue}let n=1;for(;c+n<e.length&&e[c+n]===t;)n++;const l=E(t,e,c,n,!0),a=E(t,e,c,n,!1);(l||a)&&o.push({active:!0,canClose:a,canOpen:l,char:t,index:c,length:n,originalLength:n}),c+=n}return o}(n,t,s),l=c.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 c=`${i.char}${i.canOpen}`,l=o[c]??-1;let a=!1;for(let o=r-1;o>l;o--){const c=t[o];if(!c.active||!c.canOpen||0===c.length||c.char!==i.char)continue;if(c.canClose||i.canOpen){if((c.originalLength+i.originalLength)%3==0&&c.originalLength%3!=0&&i.originalLength%3!=0)continue}const l=Math.min(c.length,i.length),d=Object.keys(n.transformersByTag).filter(e=>e[0]===c.char&&e.length<=l).sort((e,t)=>t.length-e.length)[0];if(!d)continue;a=!0;const f=d.length,g={content:e.slice(c.index+c.length,i.index),endIndex:i.index+f,startIndex:c.index+(c.length-f),tag:d};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);for(let e=o+1;e<r;e++)t[e].active=!1;c.length-=f,i.length-=f,c.active=c.length>0,i.length>0?i.index+=f:(i.active=!1,r++);break}a||(o[c]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,c,t):null;let a=null,d=null;if(i&&l?l.startIndex<=i.startIndex&&l.endIndex>=i.endIndex?(a=l,d=t.transformersByTag[l.tag]):(a=i,d=r):i?(a=i,d=r):l&&(a=l,d=t.transformersByTag[l.tag]),!a||!d)return null;const f=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return f.index=a.startIndex,f.input=n,{endIndex:a.endIndex,match:f,startIndex:a.startIndex,transformer:d}}function E(e,t,n,o,r){if(!C(t,n,o,r))return!1;if("*"===e)return!0;if("_"===e){if(!C(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 C(e,t,n,o){const r=e[t-1],s=e[t+n],[i,c]=o?[s,r]:[r,s];return void 0!==i&&!a.test(i)&&(!d.test(i)||(void 0===c||a.test(c)||d.test(c)))}function S(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function I(e,t,n){let o=T(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 c=t.index||0,l=e.getEndIndex?e.getEndIndex(n,t):c+t[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&(l>r||l<=o))&&(o=c,r=l,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.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,c,l;if(r[0]===s?i=e:0===t?[i,c]=e.splitText(n):[l,i,c]=e.splitText(t,n),i.setTextContent(r[2]),o)for(const e of o.format)i.hasFormat(e)||i.toggleFormat(e);return{nodeAfter:c,nodeBefore:l,transformedNode:i}}(e,o.startIndex,o.endIndex,o.transformer,o.match);S(r.nodeAfter)&&I(r.nodeAfter,t,n),S(r.nodeBefore)&&I(r.nodeBefore,t,n),S(r.transformedNode)&&I(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let s,i,c;return 0===t?[s,i]=e.splitText(n):[c,s,i]=e.splitText(t,n),o.replace?{nodeAfter:i,nodeBefore:c,transformedNode:o.replace(s,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;S(o.nodeAfter)&&I(o.nodeAfter,t,n),S(o.nodeBefore)&&I(o.nodeBefore,t,n),S(o.transformedNode)&&I(o.transformedNode,t,n)}const s=u(e.getTextContent());e.setTextContent(s)}function L(t,n=!1){const o=c(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"),c=i.length,l=s||e.$getRoot();l.clear();for(let e=0;e<c;e++){const t=i[e],[s,c]=R(i,e,o.multilineElement,l);s?e=c:v(t,l,o.element,r,o.textMatch,n)}const a=l.getChildren();for(const t of a)if(!n&&g(t)&&l.getChildrenSize()>1)t.remove();else if(e.$isElementNode(t))for(const e of t.getAllTextNodes())y(e);null!==e.$getSelection()&&l.selectStart()}}function R(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:c}=r,l=e[t].match(i);if(!l)continue;if(n){const s=n({lines:e,rootNode:o,startLineIndex:t,startMatch:l,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 g=e.length;for(;f<g;){const n=a?e[f].match(a):null;if(!n&&(!d||d&&f<g-1)){f++;continue}if(n&&t===f&&n.index===l.index){f++;continue}const r=[];if(n&&t===f)r.push(e[t].slice(l[0].length,-n[0].length));else for(let o=t;o<=f;o++)if(o===t){const t=e[o].slice(l[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!==c(o,null,l,n,r,!0))return[!0,f];break}}return[!1,t]}function v(r,s,i,c,l,a){const d=e.$createTextNode(r),f=e.$createParagraphNode();f.append(d),s.append(f);for(const{regExp:e,replace:t}of i){const n=r.match(e);if(n&&(d.setTextContent(r.slice(n[0].length)),!1!==t(f,[d],n,!0)))break}if(I(d,c,l),f.isAttached()&&r.length>0){const r=f.getPreviousSibling();if(!a&&(e.$isParagraphNode(r)||n.$isQuoteNode(r)||t.$isListNode(r))){let n=r;if(t.$isListNode(r)){const e=r.getLastDescendant();n=null==e?null:o.$findMatchingParent(e,t.$isListItemNode)}if(null!=n&&n.getTextContentSize()>0){const t=n.getLastChild();if(e.$isTextNode(t)){const e=t.getTextContent();e.endsWith("\\")?t.setTextContent(e.slice(0,-1)):/ {2,}$/.test(e)&&t.setTextContent(e.replace(/ {2,}$/,""))}n.splice(n.getChildrenSize(),0,[e.$createLineBreakNode(),...f.getChildren()]),f.remove()}}}}function y(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 _(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.`)}const O=/^(\s*)(\d{1,})\.\s/,A=/^(\s*)[-*+]\s/,M=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,b=/^(#{1,6})\s/,k=/^>\s/,F=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,w=/^[ \t]*`{3,}$/,B=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,D=/^(?:\|)(.+)(?:\|)\s?$/,P=/^(\| ?:?-*:? ?)+\|\s?$/,H=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,U=/^<\/[a-z_][\w-]*\s*>/i,j=e=>new RegExp(`(?:${e.source})$`,e.flags),z=e.createState("mdListMarker",{parse:e=>"string"==typeof e&&/^[-*+]$/.test(e)?e:"-",resetOnCopyNode:!0}),G=e.createState("mdCodeFence",{parse:e=>"string"==typeof e&&/^`{3,}$/.test(e)?e:"```",resetOnCopyNode:!0}),q=e=>(t,n,o,r)=>{const s=e(o);s.append(...n),t.replace(s),r||s.select(0,0)};const Q=n=>(o,r,s,i)=>{const c=o.getPreviousSibling(),l=o.getNextSibling(),a=t.$createListItemNode("check"===n?"x"===s[3]:void 0),d=s[0].trim()[0],f="bullet"!==n&&"check"!==n||d!==z.parse(d)?void 0:d;if(t.$isListNode(l)&&l.getListType()===n){f&&e.$setState(l,z,f);const t=l.getFirstChild();null!==t?t.insertBefore(a):l.append(a),o.remove()}else if(t.$isListNode(c)&&c.getListType()===n)f&&e.$setState(c,z,f),c.append(a),o.remove();else{const r=t.$createListNode(n,"number"===n?Number(s[2]):void 0);f&&e.$setState(r,z,f),r.append(a),o.replace(r)}a.append(...r),i||a.select(0,0);const g=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]);g&&a.setIndent(g)},W=(n,o,r)=>{const s=[],i=n.getChildren();let c=0;for(const l of i)if(t.$isListItemNode(l)){if(1===l.getChildrenSize()){const e=l.getFirstChild();if(t.$isListNode(e)){s.push(W(e,o,r+1));continue}}const i=" ".repeat(4*r),a=n.getListType(),d=e.$getState(n,z),f="number"===a?`${n.getStart()+c}. `:"check"===a?`${d} [${l.getChecked()?"x":" "}] `:d+" ";let g=o(l);"number"!==a&&(g=g.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),s.push(i+f+g),c++}return s.join("\n")},K={dependencies:[n.HeadingNode],export:(e,t)=>{if(!n.$isHeadingNode(e))return null;const o=Number(e.getTag().slice(1));return"#".repeat(o)+" "+t(e)},regExp:b,replace:q(e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)}),type:"element"},Y={dependencies:[n.QuoteNode],export:(e,t)=>{if(!n.$isQuoteNode(e))return null;const o=t(e).split("\n"),r=[];for(const e of o)r.push("> "+e);return r.join("\n")},regExp:k,replace:(t,o,r,s)=>{if(s){const r=t.getPreviousSibling();if(n.$isQuoteNode(r))return r.splice(r.getChildrenSize(),0,[e.$createLineBreakNode(),...o]),void t.remove()}const i=n.$createQuoteNode();i.append(...o),t.replace(i),s||i.select(0,0)},type:"element"},X={dependencies:[r.CodeNode],export:t=>{if(!r.$isCodeNode(t))return null;const n=t.getTextContent();let o=e.$getState(t,G);if(n.indexOf(o)>-1){const e=n.match(/`{3,}/g);if(e){const t=Math.max(...e.map(e=>e.length));o="`".repeat(t+1)}}return o+(t.getLanguage()||"")+(n?"\n"+n:"")+"\n"+o},handleImportAfterStartMatch:({lines:e,rootNode:t,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=e[n],c=o.index+r.length,l=i.slice(c),a=new RegExp(`\`{${s},}$`);if(a.test(l)){const e=l.match(a),r=l.slice(0,l.lastIndexOf(e[0])),s=[...o];return s[2]="",X.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 c=s.match(d),l=e.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&l.unshift(a),X.replace(t,null,o,c,l,!0),[!0,r]}}const f=e.slice(n+1),g=i.slice(o[0].length);return g.length>0&&f.unshift(g),X.replace(t,null,o,null,f,!0),[!0,e.length-1]},regExpEnd:{optional:!0,regExp:w},regExpStart:F,replace:(t,n,o,s,i,c)=>{let l,a;const d=o[1]?o[1].trim():"```",f=o[2]||void 0;if(!n&&i){if(1===i.length)s?(l=r.$createCodeNode(f),a=i[0]):(l=r.$createCodeNode(f),a=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(l=r.$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(l,G,d);const n=e.$createTextNode(a);l.append(n),t.append(l)}else n&&q(e=>r.$createCodeNode(e?e[2]:void 0))(t,n,o,c)},type:"multiline-element"},J={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:A,replace:Q("bullet"),type:"element"},V={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:M,replace:Q("check"),type:"element"},Z={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:O,replace:Q("number"),type:"element"},ee={format:["code"],tag:"`",type:"text-format"},te={format:["highlight"],tag:"==",type:"text-format"},ne={format:["bold","italic"],tag:"***",type:"text-format"},oe={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},re={format:["bold"],tag:"**",type:"text-format"},se={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ie={format:["strikethrough"],tag:"~~",type:"text-format"},ce={format:["italic"],tag:"*",type:"text-format"},le={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ae={dependencies:[s.LinkNode],export:(e,t,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o=t(e);let r=e.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${e.getURL()} "${r}")`:`[${o}](${e.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{if(e.$findMatchingParent(t,s.$isLinkNode))return;const[,o,r,i]=n,c=null!=r?u(r):void 0,l=null!=i?u(i):void 0,a=s.$createLinkNode(c,{title:l}),d=o.split("[").length-1,f=o.split("]").length-1;let g=o,p="";if(d<f)return;if(d>f){const e=o.split("[");p="["+e[0],g=e.slice(1).join("[")}const x=e.$createTextNode(g);return x.setFormat(t.getFormat()),a.append(x),t.replace(a),p&&a.insertBefore(e.$createTextNode(p)),x},trigger:")",type:"text-match"},de=[K,Y,J,Z],fe=[X],ge=[ee,ne,oe,re,se,te,ce,le,ie],ue=[ae],pe=[...de,...fe,...ge,...ue];function xe(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const c=n.getTextContent();if(!s&&" "!==c[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:l}of r){if(l&&!("optional"in l)||l&&"optional"in l&&!l.optional)continue;const r=c.match(e);if(r){const e=s||r[0].endsWith(" ")?o:o-1;if(r[0].length!==e)continue;const c=n.getNextSiblings(),[l,a]=n.splitText(o);if(!1!==i(t,a?[a,...c]:c,r,null,null,!1))return l.remove(),!0}}return!1}function he(e,t){let n=0;const o=e.getTextContent();for(let e=0;e<t;e++)"`"===o[e]&&n++;return n%2!=0}function me(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if($e(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function $e(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=pe,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(),c=r[r.length-1];B.test(i)?r.push(i):F.test(i)||w.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===c||!c||b.test(c)||b.test(i)||k.test(i)||O.test(i)||A.test(i)||M.test(i)||D.test(i)||P.test(i)||!t||H.test(i)||U.test(i)||j(U).test(c)||j(H).test(c)||w.test(c)?r.push(t||""===i?i:s):r[r.length-1]=c+" "+i.trimStart()}return r.join("\n")}(e,r);return L(t,o)(s,n)},exports.$convertToMarkdownString=function(t=pe,n,o=!1){return function(t,n=!1){const o=c(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 c=[],l=(t||e.$getRoot()).getChildren();for(let e=0;e<l.length;e++){const t=l[e],a=p(t,r,i,o.textMatch,n);null!=a&&c.push(s&&e>0&&!g(t)&&!g(l[e-1])?"\n".concat(a):a)}return c.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=ne,exports.BOLD_ITALIC_UNDERSCORE=oe,exports.BOLD_STAR=re,exports.BOLD_UNDERSCORE=se,exports.CHECK_LIST=V,exports.CODE=X,exports.ELEMENT_TRANSFORMERS=de,exports.HEADING=K,exports.HIGHLIGHT=te,exports.INLINE_CODE=ee,exports.ITALIC_STAR=ce,exports.ITALIC_UNDERSCORE=le,exports.LINK=ae,exports.MULTILINE_ELEMENT_TRANSFORMERS=fe,exports.ORDERED_LIST=Z,exports.QUOTE=Y,exports.STRIKETHROUGH=ie,exports.TEXT_FORMAT_TRANSFORMERS=ge,exports.TEXT_MATCH_TRANSFORMERS=ue,exports.TRANSFORMERS=pe,exports.UNORDERED_LIST=J,exports.registerMarkdownShortcuts=function(t,n=pe){const o=c(n),s=i(o.textFormat,({tag:e})=>e[e.length-1]),a=i(o.textMatch,({trigger:e})=>e);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)||_(173,e.getType())}}const d=(t,n,r)=>!!function(t,n,o,r){const s=t.getParent();if(!e.$isRootOrShadowRoot(s)||t.getFirstChild()!==n)return!1;const i=n.getTextContent();if(" "!==i[o-1])return!1;for(const{regExp:e,replace:s}of r){const r=i.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[i,c]=n.splitText(o);if(!1!==s(t,c?[c,...e]:e,r,!1))return i.remove(),!0}}return!1}(t,n,r,o.element)||(!!xe(t,n,r,o.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,r,a)||!!function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],c=o[i];if(!c)return!1;for(const n of c){const{tag:o}=n,c=o.length,a=s-c+1;if(c>1&&!$e(r,a,o,0,c))continue;if(" "===r[a-1])continue;const d=r[s+1];if(!1===n.intraword&&d&&!l.test(d))continue;const f=t;let g=f,u=me(r,a,o),p=g;for(;u<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();g=p,u=me(e,e.length,o)}if(u<0)continue;if(g===f&&u+c===a)continue;const x=g.getTextContent();if(u>0&&x[u-1]===i)continue;const h=x[u-1];if(!1===n.intraword&&h&&!l.test(h))continue;if(!n.format.includes("code")&&he(g,u))continue;const m=f.getTextContent(),$=m.slice(0,a)+m.slice(s+1);f.setTextContent($);const N=g===f?$:x;g.setTextContent(N.slice(0,u)+N.slice(u+c));const T=e.$getSelection(),E=e.$createRangeSelection();e.$setSelection(E);const C=s-c*(g===f?2:1)+1;E.anchor.set(g.__key,u,"text"),E.focus.set(f.__key,C,"text");for(const e of n.format)E.hasFormat(e)||E.formatText(e);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const e of n.format)E.hasFormat(e)&&E.toggleFormat(e);return e.$isRangeSelection(T)&&(E.format=T.format),!0}return!1}(n,r,s)));return e.mergeRegister(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:s,prevEditorState:i})=>{if(n.has(e.COLLABORATION_TAG)||n.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const c=s.read(e.$getSelection),l=i.read(e.$getSelection);if(!e.$isRangeSelection(l)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(l))return;const a=c.anchor.key,f=c.anchor.offset,g=s._nodeMap.get(a);!e.$isTextNode(g)||!o.has(a)||1!==f&&f>l.anchor.offset+1||t.update(()=>{if(!S(g))return;const t=g.getParent();null===t||r.$isCodeNode(t)||d(t,g,c.anchor.offset)&&e.$addUpdateTag(e.HISTORY_PUSH_TAG)})}),t.registerCommand(e.KEY_ENTER_COMMAND,t=>{if(null!==t&&t.shiftKey)return!1;const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e.$isTextNode(i)||!S(i))return!1;const c=i.getParent();if(null===c||r.$isCodeNode(c))return!1;return s===i.getTextContent().length&&(!!xe(c,i,s,o.multilineElement,!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,$getRoot as n,$isElementNode as o,$isDecoratorNode as r,$isLineBreakNode as s,$getSelection as i,$createTextNode as l,$createParagraphNode as c,$createLineBreakNode as a,$createTabNode as f,createState as u,$setState as g,$getState as d,$findMatchingParent as p,mergeRegister as h,COLLABORATION_TAG as x,HISTORIC_TAG as m,$isRangeSelection as C,KEY_ENTER_COMMAND as T,COMMAND_PRIORITY_LOW as v,$isRootOrShadowRoot as $,$createRangeSelection as y,$setSelection as E}from"lexical";import{$isListNode as I,$isListItemNode as S,ListNode as b,ListItemNode as w,$createListItemNode as N,$createListNode as F}from"@lexical/list";import{$isQuoteNode as L,HeadingNode as k,QuoteNode as R,$isHeadingNode as M,$createQuoteNode as _,$createHeadingNode as B}from"@lexical/rich-text";import{$findMatchingParent as O}from"@lexical/utils";import{CodeNode as j,$createCodeNode as A,$isCodeNode as P}from"@lexical/code-core";import{LinkNode as z,$isLinkNode as U,$createLinkNode as W,$isAutoLinkNode as D}from"@lexical/link";function K(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=K(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const G=/[!-/:-@[-`{-~\s]/,H=/[ \t\n\r\f]/,J=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,Q=/^\s{0,3}$/;function V(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&Q.test(o.getTextContent())}function X(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}function Y(t,e,n,s,i){for(const o of e){if(!o.export)continue;const e=o.export(t,t=>Z(t,n,s,void 0,void 0,i));if(null!=e)return e}return o(t)?Z(t,n,s,void 0,void 0,i):r(t)?t.getTextContent():null}function Z(t,n,i,l,c,a=!1){const f=[],u=t.getChildren();l||(l=[]),c||(c=[]);t:for(const t of u){for(const e of i){if(!e.export)continue;const o=e.export(t,t=>Z(t,n,i,l,[...c,...l],a),(t,e)=>tt(t,e,n,l,c,a));if(null!=o){f.push(o);continue t}}s(t)?f.push("\n"):e(t)?f.push(tt(t,t.getTextContent(),n,l,c,a)):o(t)?f.push(Z(t,n,i,l,c,a)):r(t)&&f.push(t.getTextContent())}return f.join("")}function tt(t,e,n,o,r,s=!1){let i=e;t.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const l=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],c=l[1],a=l[2],f=l[3],u=""===a;let g="",d="",p="";const h=et(t,!0),x=et(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;ot(t,n)&&!m.has(n)&&(m.add(n),ot(h,n)&&o.find(t=>t.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let e=0;e<o.length;e++){const n=nt(t,o[e].format),s=nt(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||(p+=t.tag):d+=t.tag),o.pop())}break}return u&&!t.hasFormat("code")?d+i:d+c+g+a+p+f}function et(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function nt(t,n){return e(t)&&t.hasFormat(n)}function ot(t,e){return!!nt(t,e)&&("code"===e||(!t||!/^\s*$/.test(t.getTextContent())))}function rt(t,e){const n=t.getTextContent(),o=e.fullMatchRegExpByTag["`"],r=e.transformersByTag["`"],s=[];let i=null;if(o&&r){const t=new RegExp(o.source,"g"),e=Array.from(n.matchAll(t));for(const t of e){const e=t.index+t[1].length,n=t.index+t[0].length;i||(i={content:t[3],endIndex:n,startIndex:e,tag:"`"}),s.push({end:n,start:e})}}const l=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),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=st(e,t,l,n,!0),a=st(e,t,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,s),c=l.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 a=!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),f=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!f)continue;a=!0;const u=f.length,g={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:f};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);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}a||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,l,e):null;let a=null,f=null;if(i&&c?c.startIndex<=i.startIndex&&c.endIndex>=i.endIndex?(a=c,f=e.transformersByTag[c.tag]):(a=i,f=r):i?(a=i,f=r):c&&(a=c,f=e.transformersByTag[c.tag]),!a||!f)return null;const u=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return u.index=a.startIndex,u.input=n,{endIndex:a.endIndex,match:u,startIndex:a.startIndex,transformer:f}}function st(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&&J.test(t)}return!0}function it(t,e,n,o){const r=t[e-1],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!H.test(i)&&(!J.test(i)||(void 0===l||H.test(l)||J.test(l)))}function lt(t){return e(t)&&!t.hasFormat("code")}function ct(t,e,n){let o=rt(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.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);lt(r.nodeAfter)&&ct(r.nodeAfter,e,n),lt(r.nodeBefore)&&ct(r.nodeBefore,e,n),lt(r.transformedNode)&&ct(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;lt(o.nodeAfter)&&ct(o.nodeAfter,e,n),lt(o.nodeBefore)&&ct(o.nodeBefore,e,n),lt(o.transformedNode)&&ct(o.transformedNode,e,n)}const s=X(t.getTextContent());t.setTextContent(s)}function at(t,e=!1){const r=q(t),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);return(t,l)=>{const c=t.split("\n"),a=c.length,f=l||n();f.clear();for(let t=0;t<a;t++){const n=c[t],[o,i]=ft(c,t,r.multilineElement,f);o?t=i:ut(n,f,r.element,s,r.textMatch,e)}const u=f.getChildren();for(const t of u)if(!e&&V(t)&&f.getChildrenSize()>1)t.remove();else if(o(t))for(const e of t.getAllTextNodes())gt(e);null!==i()&&f.selectStart()}}function ft(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 a="object"==typeof s&&"regExp"in s?s.regExp:s,f=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const g=t.length;for(;u<g;){const n=a?t[u].match(a):null;if(!n&&(!f||f&&u<g-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 ut(n,o,r,s,i,f){const u=l(n),g=c();g.append(u),o.append(g);for(const{regExp:t,replace:e}of r){const o=n.match(t);if(o&&(u.setTextContent(n.slice(o[0].length)),!1!==e(g,[u],o,!0)))break}if(ct(u,s,i),g.isAttached()&&n.length>0){const n=g.getPreviousSibling();if(!f&&(t(n)||L(n)||I(n))){let t=n;if(I(n)){const e=n.getLastDescendant();t=null==e?null:O(e,S)}if(null!=t&&t.getTextContentSize()>0){const n=t.getLastChild();if(e(n)){const t=n.getTextContent();t.endsWith("\\")?n.setTextContent(t.slice(0,-1)):/ {2,}$/.test(t)&&n.setTextContent(t.replace(/ {2,}$/,""))}t.splice(t.getChildrenSize(),0,[a(),...g.getChildren()]),g.remove()}}}}function gt(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(f())})}function dt(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.`)}const pt=/^(\s*)(\d{1,})\.\s/,ht=/^(\s*)[-*+]\s/,xt=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,mt=/^(#{1,6})\s/,Ct=/^>\s/,Tt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,vt=/^[ \t]*`{3,}$/,$t=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,yt=/^(?:\|)(.+)(?:\|)\s?$/,Et=/^(\| ?:?-*:? ?)+\|\s?$/,It=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,St=/^<\/[a-z_][\w-]*\s*>/i,bt=t=>new RegExp(`(?:${t.source})$`,t.flags),wt=u("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Nt=u("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),Ft=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};const Lt=t=>(e,n,o,r)=>{const s=e.getPreviousSibling(),i=e.getNextSibling(),l=N("check"===t?"x"===o[3]:void 0),c=o[0].trim()[0],a="bullet"!==t&&"check"!==t||c!==wt.parse(c)?void 0:c;if(I(i)&&i.getListType()===t){a&&g(i,wt,a);const t=i.getFirstChild();null!==t?t.insertBefore(l):i.append(l),e.remove()}else if(I(s)&&s.getListType()===t)a&&g(s,wt,a),s.append(l),e.remove();else{const n=F(t,"number"===t?Number(o[2]):void 0);a&&g(n,wt,a),n.append(l),e.replace(n)}l.append(...n),r||l.select(0,0);const f=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}(o[1]);f&&l.setIndent(f)},kt=(t,e,n)=>{const o=[],r=t.getChildren();let s=0;for(const i of r)if(S(i)){if(1===i.getChildrenSize()){const t=i.getFirstChild();if(I(t)){o.push(kt(t,e,n+1));continue}}const r=" ".repeat(4*n),l=t.getListType(),c=d(t,wt),a="number"===l?`${t.getStart()+s}. `:"check"===l?`${c} [${i.getChecked()?"x":" "}] `:c+" ";o.push(r+a+e(i)),s++}return o.join("\n")},Rt={dependencies:[k],export:(t,e)=>{if(!M(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:mt,replace:Ft(t=>{const e="h"+t[1].length;return B(e)}),type:"element"},Mt={dependencies:[R],export:(t,e)=>{if(!L(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:Ct,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(L(n))return n.splice(n.getChildrenSize(),0,[a(),...e]),void t.remove()}const r=_();r.append(...e),t.replace(r),o||r.select(0,0)},type:"element"},_t={dependencies:[j],export:t=>{if(!P(t))return null;const e=t.getTextContent();let n=d(t,Nt);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),a=new RegExp(`\`{${s},}$`);if(a.test(c)){const t=c.match(a),r=c.slice(0,c.lastIndexOf(t[0])),s=[...o];return s[2]="",_t.replace(e,null,s,t,[r],!0),[!0,n]}const f=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(f.test(s)){const l=s.match(f),c=t.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&c.unshift(a),_t.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),g=i.slice(o[0].length);return g.length>0&&u.unshift(g),_t.replace(e,null,o,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:vt},regExpStart:Tt,replace:(t,e,n,o,r,s)=>{let i,c;const a=n[1]?n[1].trim():"```",f=n[2]||void 0;if(!e&&r){if(1===r.length)o?(i=A(f),c=r[0]):(i=A(f),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{for(i=A(f),r.length>0&&(0===r[0].trim().length?r.shift():r[0].startsWith(" ")&&(r[0]=r[0].slice(1)));r.length>0&&!r[r.length-1].length;)r.pop();c=r.join("\n")}g(i,Nt,a);const e=l(c);i.append(e),t.append(i)}else e&&Ft(t=>A(t?t[2]:void 0))(t,e,n,s)},type:"multiline-element"},Bt={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:ht,replace:Lt("bullet"),type:"element"},Ot={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:xt,replace:Lt("check"),type:"element"},jt={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:pt,replace:Lt("number"),type:"element"},At={format:["code"],tag:"`",type:"text-format"},Pt={format:["highlight"],tag:"==",type:"text-format"},zt={format:["bold","italic"],tag:"***",type:"text-format"},Ut={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Wt={format:["bold"],tag:"**",type:"text-format"},Dt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Kt={format:["strikethrough"],tag:"~~",type:"text-format"},qt={format:["italic"],tag:"*",type:"text-format"},Gt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Ht={dependencies:[z],export:(t,e,n)=>{if(!U(t)||D(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(p(t,U))return;const[,n,o,r]=e,s=null!=o?X(o):void 0,i=null!=r?X(r):void 0,c=W(s,{title:i}),a=n.split("[").length-1,f=n.split("]").length-1;let u=n,g="";if(a<f)return;if(a>f){const t=n.split("[");g="["+t[0],u=t.slice(1).join("[")}const d=l(u);return d.setFormat(t.getFormat()),c.append(d),t.replace(c),g&&c.insertBefore(l(g)),d},trigger:")",type:"text-match"},Jt=[Rt,Mt,Bt,jt],Qt=[_t],Vt=[At,zt,Ut,Wt,Dt,Pt,qt,Gt,Kt],Xt=[Ht],Yt=[...Jt,...Qt,...Vt,...Xt];function Zt(t,e,n,o,r){const s=t.getParent();if(!$(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,a]=e.splitText(n);if(!1!==l(t,a?[a,...i]:i,o,null,null,!1))return c.remove(),!0}}return!1}function te(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(ee(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function ee(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function ne(t,n=Yt){const o=q(n),r=K(o.textFormat,({tag:t})=>t[t.length-1]),l=K(o.textMatch,({trigger:t})=>t);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)||dt(173,e.getType())}}const c=(t,n,c)=>{(function(t,e,n,o){const r=t.getParent();if(!$(r)||t.getFirstChild()!==e)return!1;const s=e.getTextContent();if(" "!==s[n-1])return!1;for(const{regExp:r,replace:i}of o){const o=s.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){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})(t,n,c,o.element)||Zt(t,n,c,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,c,l)||function(t,n,o){const r=t.getTextContent(),l=n-1,c=r[l],a=o[c];if(!a)return!1;for(const n of a){const{tag:o}=n,a=o.length,f=l-a+1;if(a>1&&!ee(r,f,o,0,a))continue;if(" "===r[f-1])continue;const u=r[l+1];if(!1===n.intraword&&u&&!G.test(u))continue;const g=t;let d=g,p=te(r,f,o),h=d;for(;p<0&&(h=h.getPreviousSibling())&&!s(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,p=te(t,t.length,o)}if(p<0)continue;if(d===g&&p+a===f)continue;const x=d.getTextContent();if(p>0&&x[p-1]===c)continue;const m=x[p-1];if(!1===n.intraword&&m&&!G.test(m))continue;const T=g.getTextContent(),v=T.slice(0,f)+T.slice(l+1);g.setTextContent(v);const $=d===g?v:x;d.setTextContent($.slice(0,p)+$.slice(p+a));const I=i(),S=y();E(S);const b=l-a*(d===g?2:1)+1;S.anchor.set(d.__key,p,"text"),S.focus.set(g.__key,b,"text");for(const t of n.format)S.hasFormat(t)||S.formatText(t);S.anchor.set(S.focus.key,S.focus.offset,S.focus.type);for(const t of n.format)S.hasFormat(t)&&S.toggleFormat(t);return C(I)&&(S.format=I.format),!0}}(n,c,r)};return h(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:s})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const l=r.read(i),a=s.read(i);if(!C(a)||!C(l)||!l.isCollapsed()||l.is(a))return;const f=l.anchor.key,u=l.anchor.offset,g=r._nodeMap.get(f);!e(g)||!o.has(f)||1!==u&&u>a.anchor.offset+1||t.update(()=>{if(!lt(g))return;const t=g.getParent();null===t||P(t)||c(t,g,l.anchor.offset)})}),t.registerCommand(T,t=>{if(null!==t&&t.shiftKey)return!1;const n=i();if(!C(n)||!n.isCollapsed())return!1;const r=n.anchor.offset,s=n.anchor.getNode();if(!e(s)||!lt(s))return!1;const l=s.getParent();if(null===l||P(l))return!1;return r===s.getTextContent().length&&(!!Zt(l,s,r,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},v))}function oe(t,e=Yt,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];$t.test(i)?r.push(i):Tt.test(i)||vt.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===l||!l||mt.test(l)||mt.test(i)||Ct.test(i)||pt.test(i)||ht.test(i)||xt.test(i)||yt.test(i)||Et.test(i)||!e||It.test(i)||St.test(i)||bt(St).test(l)||bt(It).test(l)||vt.test(l)?r.push(e||""===i?i:s):r[r.length-1]=l+" "+i.trimStart()}return r.join("\n")}(t,r);return at(e,o)(s,n)}function re(t=Yt,e,o=!1){const r=function(t,e=!1){const o=q(t),r=[...o.multilineElement,...o.element],s=!e,i=o.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const l=[],c=(t||n()).getChildren();for(let t=0;t<c.length;t++){const n=c[t],a=Y(n,r,i,o.textMatch,e);null!=a&&l.push(s&&t>0&&!V(n)&&!V(c[t-1])?"\n".concat(a):a)}return l.join("\n")}}(t,o);return r(e)}export{oe as $convertFromMarkdownString,re as $convertToMarkdownString,zt as BOLD_ITALIC_STAR,Ut as BOLD_ITALIC_UNDERSCORE,Wt as BOLD_STAR,Dt as BOLD_UNDERSCORE,Ot as CHECK_LIST,_t as CODE,Jt as ELEMENT_TRANSFORMERS,Rt as HEADING,Pt as HIGHLIGHT,At as INLINE_CODE,qt as ITALIC_STAR,Gt as ITALIC_UNDERSCORE,Ht as LINK,Qt as MULTILINE_ELEMENT_TRANSFORMERS,jt as ORDERED_LIST,Mt as QUOTE,Kt as STRIKETHROUGH,Vt as TEXT_FORMAT_TRANSFORMERS,Xt as TEXT_MATCH_TRANSFORMERS,Yt as TRANSFORMERS,Bt as UNORDERED_LIST,ne as registerMarkdownShortcuts};
9
+ import{$isParagraphNode as t,$isTextNode as e,$getRoot as n,$isElementNode as o,$isDecoratorNode as r,$isLineBreakNode as s,$getSelection as i,$createTextNode as l,$createParagraphNode as c,$createLineBreakNode as a,$createTabNode as f,createState as u,$setState as g,$getState as d,$findMatchingParent as p,mergeRegister as h,COLLABORATION_TAG as x,HISTORIC_TAG as m,$isRangeSelection as C,$addUpdateTag as T,HISTORY_PUSH_TAG as $,KEY_ENTER_COMMAND as v,COMMAND_PRIORITY_LOW as y,$isRootOrShadowRoot as E,$createRangeSelection as I,$setSelection as b}from"lexical";import{$isListNode as S,$isListItemNode as w,ListNode as N,ListItemNode as F,$createListItemNode as L,$createListNode as k}from"@lexical/list";import{$isQuoteNode as R,HeadingNode as M,QuoteNode as _,$isHeadingNode as B,$createQuoteNode as O,$createHeadingNode as j}from"@lexical/rich-text";import{$findMatchingParent as A}from"@lexical/utils";import{CodeNode as P,$createCodeNode as z,$isCodeNode as U}from"@lexical/code-core";import{LinkNode as W,$isLinkNode as D,$createLinkNode as K,$isAutoLinkNode as q}from"@lexical/link";function G(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 H(t){const e=G(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const J=/[!-/:-@[-`{-~\s]/,Q=/[ \t\n\r\f]/,V=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,X=/^\s{0,3}$/;function Y(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&X.test(o.getTextContent())}function Z(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}function tt(t,e,n,s,i){for(const o of e){if(!o.export)continue;const e=o.export(t,t=>et(t,n,s,void 0,void 0,i));if(null!=e)return e}return o(t)?et(t,n,s,void 0,void 0,i):r(t)?t.getTextContent():null}function et(t,n,i,l,c,a=!1){const f=[],u=t.getChildren();l||(l=[]),c||(c=[]);t:for(const t of u){for(const e of i){if(!e.export)continue;const o=e.export(t,t=>et(t,n,i,l,[...c,...l],a),(t,e)=>nt(t,e,n,l,c,a));if(null!=o){f.push(o);continue t}}s(t)?f.push("\n"):e(t)?f.push(nt(t,t.getTextContent(),n,l,c,a)):o(t)?f.push(et(t,n,i,l,c,a)):r(t)&&f.push(t.getTextContent())}return f.join("")}function nt(t,e,n,o,r,s=!1){let i=e;t.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const l=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],c=l[1],a=l[2],f=l[3],u=""===a;let g="",d="",p="";const h=ot(t,!0),x=ot(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;st(t,n)&&!m.has(n)&&(m.add(n),st(h,n)&&o.find(t=>t.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let e=0;e<o.length;e++){const n=rt(t,o[e].format),s=rt(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||(p+=t.tag):d+=t.tag),o.pop())}break}return u&&!t.hasFormat("code")?d+i:d+c+g+a+p+f}function ot(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function rt(t,n){return e(t)&&t.hasFormat(n)}function st(t,e){return!!rt(t,e)&&("code"===e||(!t||!/^\s*$/.test(t.getTextContent())))}function it(t,e){const n=t.getTextContent(),o=e.fullMatchRegExpByTag["`"],r=e.transformersByTag["`"],s=[];let i=null;if(o&&r){const t=new RegExp(o.source,"g"),e=Array.from(n.matchAll(t));for(const t of e){const e=t.index+t[1].length,n=t.index+t[0].length;i||(i={content:t[3],endIndex:n,startIndex:e,tag:"`"}),s.push({end:n,start:e})}}const l=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),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=lt(e,t,l,n,!0),a=lt(e,t,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,s),c=l.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 a=!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),f=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!f)continue;a=!0;const u=f.length,g={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:f};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);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}a||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,l,e):null;let a=null,f=null;if(i&&c?c.startIndex<=i.startIndex&&c.endIndex>=i.endIndex?(a=c,f=e.transformersByTag[c.tag]):(a=i,f=r):i?(a=i,f=r):c&&(a=c,f=e.transformersByTag[c.tag]),!a||!f)return null;const u=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return u.index=a.startIndex,u.input=n,{endIndex:a.endIndex,match:u,startIndex:a.startIndex,transformer:f}}function lt(t,e,n,o,r){if(!ct(e,n,o,r))return!1;if("*"===t)return!0;if("_"===t){if(!ct(e,n,o,!r))return!0;const t=r?e[n-1]:e[n+o];return void 0!==t&&V.test(t)}return!0}function ct(t,e,n,o){const r=t[e-1],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!Q.test(i)&&(!V.test(i)||(void 0===l||Q.test(l)||V.test(l)))}function at(t){return e(t)&&!t.hasFormat("code")}function ft(t,e,n){let o=it(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.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);at(r.nodeAfter)&&ft(r.nodeAfter,e,n),at(r.nodeBefore)&&ft(r.nodeBefore,e,n),at(r.transformedNode)&&ft(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;at(o.nodeAfter)&&ft(o.nodeAfter,e,n),at(o.nodeBefore)&&ft(o.nodeBefore,e,n),at(o.transformedNode)&&ft(o.transformedNode,e,n)}const s=Z(t.getTextContent());t.setTextContent(s)}function ut(t,e=!1){const r=H(t),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);return(t,l)=>{const c=t.split("\n"),a=c.length,f=l||n();f.clear();for(let t=0;t<a;t++){const n=c[t],[o,i]=gt(c,t,r.multilineElement,f);o?t=i:dt(n,f,r.element,s,r.textMatch,e)}const u=f.getChildren();for(const t of u)if(!e&&Y(t)&&f.getChildrenSize()>1)t.remove();else if(o(t))for(const e of t.getAllTextNodes())pt(e);null!==i()&&f.selectStart()}}function gt(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 a="object"==typeof s&&"regExp"in s?s.regExp:s,f=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const g=t.length;for(;u<g;){const n=a?t[u].match(a):null;if(!n&&(!f||f&&u<g-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 dt(n,o,r,s,i,f){const u=l(n),g=c();g.append(u),o.append(g);for(const{regExp:t,replace:e}of r){const o=n.match(t);if(o&&(u.setTextContent(n.slice(o[0].length)),!1!==e(g,[u],o,!0)))break}if(ft(u,s,i),g.isAttached()&&n.length>0){const n=g.getPreviousSibling();if(!f&&(t(n)||R(n)||S(n))){let t=n;if(S(n)){const e=n.getLastDescendant();t=null==e?null:A(e,w)}if(null!=t&&t.getTextContentSize()>0){const n=t.getLastChild();if(e(n)){const t=n.getTextContent();t.endsWith("\\")?n.setTextContent(t.slice(0,-1)):/ {2,}$/.test(t)&&n.setTextContent(t.replace(/ {2,}$/,""))}t.splice(t.getChildrenSize(),0,[a(),...g.getChildren()]),g.remove()}}}}function pt(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(f())})}function ht(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.`)}const xt=/^(\s*)(\d{1,})\.\s/,mt=/^(\s*)[-*+]\s/,Ct=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,Tt=/^(#{1,6})\s/,$t=/^>\s/,vt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,yt=/^[ \t]*`{3,}$/,Et=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,It=/^(?:\|)(.+)(?:\|)\s?$/,bt=/^(\| ?:?-*:? ?)+\|\s?$/,St=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,wt=/^<\/[a-z_][\w-]*\s*>/i,Nt=t=>new RegExp(`(?:${t.source})$`,t.flags),Ft=u("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Lt=u("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),kt=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};const Rt=t=>(e,n,o,r)=>{const s=e.getPreviousSibling(),i=e.getNextSibling(),l=L("check"===t?"x"===o[3]:void 0),c=o[0].trim()[0],a="bullet"!==t&&"check"!==t||c!==Ft.parse(c)?void 0:c;if(S(i)&&i.getListType()===t){a&&g(i,Ft,a);const t=i.getFirstChild();null!==t?t.insertBefore(l):i.append(l),e.remove()}else if(S(s)&&s.getListType()===t)a&&g(s,Ft,a),s.append(l),e.remove();else{const n=k(t,"number"===t?Number(o[2]):void 0);a&&g(n,Ft,a),n.append(l),e.replace(n)}l.append(...n),r||l.select(0,0);const f=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}(o[1]);f&&l.setIndent(f)},Mt=(t,e,n)=>{const o=[],r=t.getChildren();let s=0;for(const i of r)if(w(i)){if(1===i.getChildrenSize()){const t=i.getFirstChild();if(S(t)){o.push(Mt(t,e,n+1));continue}}const r=" ".repeat(4*n),l=t.getListType(),c=d(t,Ft),a="number"===l?`${t.getStart()+s}. `:"check"===l?`${c} [${i.getChecked()?"x":" "}] `:c+" ";let f=e(i);"number"!==l&&(f=f.replace(/^(\s{0,3}\d+)(\.\s)/,"$1\\$2")),o.push(r+a+f),s++}return o.join("\n")},_t={dependencies:[M],export:(t,e)=>{if(!B(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:Tt,replace:kt(t=>{const e="h"+t[1].length;return j(e)}),type:"element"},Bt={dependencies:[_],export:(t,e)=>{if(!R(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:$t,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(R(n))return n.splice(n.getChildrenSize(),0,[a(),...e]),void t.remove()}const r=O();r.append(...e),t.replace(r),o||r.select(0,0)},type:"element"},Ot={dependencies:[P],export:t=>{if(!U(t))return null;const e=t.getTextContent();let n=d(t,Lt);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),a=new RegExp(`\`{${s},}$`);if(a.test(c)){const t=c.match(a),r=c.slice(0,c.lastIndexOf(t[0])),s=[...o];return s[2]="",Ot.replace(e,null,s,t,[r],!0),[!0,n]}const f=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(f.test(s)){const l=s.match(f),c=t.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&c.unshift(a),Ot.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),g=i.slice(o[0].length);return g.length>0&&u.unshift(g),Ot.replace(e,null,o,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:yt},regExpStart:vt,replace:(t,e,n,o,r,s)=>{let i,c;const a=n[1]?n[1].trim():"```",f=n[2]||void 0;if(!e&&r){if(1===r.length)o?(i=z(f),c=r[0]):(i=z(f),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{for(i=z(f),r.length>0&&(0===r[0].trim().length?r.shift():r[0].startsWith(" ")&&(r[0]=r[0].slice(1)));r.length>0&&!r[r.length-1].length;)r.pop();c=r.join("\n")}g(i,Lt,a);const e=l(c);i.append(e),t.append(i)}else e&&kt(t=>z(t?t[2]:void 0))(t,e,n,s)},type:"multiline-element"},jt={dependencies:[N,F],export:(t,e)=>S(t)?Mt(t,e,0):null,regExp:mt,replace:Rt("bullet"),type:"element"},At={dependencies:[N,F],export:(t,e)=>S(t)?Mt(t,e,0):null,regExp:Ct,replace:Rt("check"),type:"element"},Pt={dependencies:[N,F],export:(t,e)=>S(t)?Mt(t,e,0):null,regExp:xt,replace:Rt("number"),type:"element"},zt={format:["code"],tag:"`",type:"text-format"},Ut={format:["highlight"],tag:"==",type:"text-format"},Wt={format:["bold","italic"],tag:"***",type:"text-format"},Dt={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"},Ht={format:["italic"],tag:"*",type:"text-format"},Jt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Qt={dependencies:[W],export:(t,e,n)=>{if(!D(t)||q(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(p(t,D))return;const[,n,o,r]=e,s=null!=o?Z(o):void 0,i=null!=r?Z(r):void 0,c=K(s,{title:i}),a=n.split("[").length-1,f=n.split("]").length-1;let u=n,g="";if(a<f)return;if(a>f){const t=n.split("[");g="["+t[0],u=t.slice(1).join("[")}const d=l(u);return d.setFormat(t.getFormat()),c.append(d),t.replace(c),g&&c.insertBefore(l(g)),d},trigger:")",type:"text-match"},Vt=[_t,Bt,jt,Pt],Xt=[Ot],Yt=[zt,Wt,Dt,Kt,qt,Ut,Ht,Jt,Gt],Zt=[Qt],te=[...Vt,...Xt,...Yt,...Zt];function ee(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,a]=e.splitText(n);if(!1!==l(t,a?[a,...i]:i,o,null,null,!1))return c.remove(),!0}}return!1}function ne(t,e){let n=0;const o=t.getTextContent();for(let t=0;t<e;t++)"`"===o[t]&&n++;return n%2!=0}function oe(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(re(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function re(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function se(t,n=te){const o=H(n),r=G(o.textFormat,({tag:t})=>t[t.length-1]),l=G(o.textMatch,({trigger:t})=>t);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)||ht(173,e.getType())}}const c=(t,n,c)=>!!function(t,e,n,o){const r=t.getParent();if(!E(r)||t.getFirstChild()!==e)return!1;const s=e.getTextContent();if(" "!==s[n-1])return!1;for(const{regExp:r,replace:i}of o){const o=s.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){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}(t,n,c,o.element)||(!!ee(t,n,c,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,c,l)||!!function(t,n,o){const r=t.getTextContent(),l=n-1,c=r[l],a=o[c];if(!a)return!1;for(const n of a){const{tag:o}=n,a=o.length,f=l-a+1;if(a>1&&!re(r,f,o,0,a))continue;if(" "===r[f-1])continue;const u=r[l+1];if(!1===n.intraword&&u&&!J.test(u))continue;const g=t;let d=g,p=oe(r,f,o),h=d;for(;p<0&&(h=h.getPreviousSibling())&&!s(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,p=oe(t,t.length,o)}if(p<0)continue;if(d===g&&p+a===f)continue;const x=d.getTextContent();if(p>0&&x[p-1]===c)continue;const m=x[p-1];if(!1===n.intraword&&m&&!J.test(m))continue;if(!n.format.includes("code")&&ne(d,p))continue;const T=g.getTextContent(),$=T.slice(0,f)+T.slice(l+1);g.setTextContent($);const v=d===g?$:x;d.setTextContent(v.slice(0,p)+v.slice(p+a));const y=i(),E=I();b(E);const S=l-a*(d===g?2:1)+1;E.anchor.set(d.__key,p,"text"),E.focus.set(g.__key,S,"text");for(const t of n.format)E.hasFormat(t)||E.formatText(t);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const t of n.format)E.hasFormat(t)&&E.toggleFormat(t);return C(y)&&(E.format=y.format),!0}return!1}(n,c,r)));return h(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:s})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const l=r.read(i),a=s.read(i);if(!C(a)||!C(l)||!l.isCollapsed()||l.is(a))return;const f=l.anchor.key,u=l.anchor.offset,g=r._nodeMap.get(f);!e(g)||!o.has(f)||1!==u&&u>a.anchor.offset+1||t.update(()=>{if(!at(g))return;const t=g.getParent();null===t||U(t)||c(t,g,l.anchor.offset)&&T($)})}),t.registerCommand(v,t=>{if(null!==t&&t.shiftKey)return!1;const n=i();if(!C(n)||!n.isCollapsed())return!1;const r=n.anchor.offset,s=n.anchor.getNode();if(!e(s)||!at(s))return!1;const l=s.getParent();if(null===l||U(l))return!1;return r===s.getTextContent().length&&(!!ee(l,s,r,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},y))}function ie(t,e=te,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];Et.test(i)?r.push(i):vt.test(i)||yt.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===l||!l||Tt.test(l)||Tt.test(i)||$t.test(i)||xt.test(i)||mt.test(i)||Ct.test(i)||It.test(i)||bt.test(i)||!e||St.test(i)||wt.test(i)||Nt(wt).test(l)||Nt(St).test(l)||yt.test(l)?r.push(e||""===i?i:s):r[r.length-1]=l+" "+i.trimStart()}return r.join("\n")}(t,r);return ut(e,o)(s,n)}function le(t=te,e,o=!1){const r=function(t,e=!1){const o=H(t),r=[...o.multilineElement,...o.element],s=!e,i=o.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const l=[],c=(t||n()).getChildren();for(let t=0;t<c.length;t++){const n=c[t],a=tt(n,r,i,o.textMatch,e);null!=a&&l.push(s&&t>0&&!Y(n)&&!Y(c[t-1])?"\n".concat(a):a)}return l.join("\n")}}(t,o);return r(e)}export{ie as $convertFromMarkdownString,le as $convertToMarkdownString,Wt as BOLD_ITALIC_STAR,Dt as BOLD_ITALIC_UNDERSCORE,Kt as BOLD_STAR,qt as BOLD_UNDERSCORE,At as CHECK_LIST,Ot as CODE,Vt as ELEMENT_TRANSFORMERS,_t as HEADING,Ut as HIGHLIGHT,zt as INLINE_CODE,Ht as ITALIC_STAR,Jt as ITALIC_UNDERSCORE,Qt as LINK,Xt as MULTILINE_ELEMENT_TRANSFORMERS,Pt as ORDERED_LIST,Bt as QUOTE,Gt as STRIKETHROUGH,Yt as TEXT_FORMAT_TRANSFORMERS,Zt as TEXT_MATCH_TRANSFORMERS,te as TRANSFORMERS,jt as UNORDERED_LIST,se as registerMarkdownShortcuts};
package/package.json CHANGED
@@ -8,17 +8,17 @@
8
8
  "markdown"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.43.1-nightly.20260416.0",
11
+ "version": "0.44.0",
12
12
  "main": "LexicalMarkdown.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/code-core": "0.43.1-nightly.20260416.0",
16
- "@lexical/link": "0.43.1-nightly.20260416.0",
17
- "@lexical/list": "0.43.1-nightly.20260416.0",
18
- "@lexical/rich-text": "0.43.1-nightly.20260416.0",
19
- "@lexical/text": "0.43.1-nightly.20260416.0",
20
- "@lexical/utils": "0.43.1-nightly.20260416.0",
21
- "lexical": "0.43.1-nightly.20260416.0"
15
+ "@lexical/code-core": "0.44.0",
16
+ "@lexical/link": "0.44.0",
17
+ "@lexical/list": "0.44.0",
18
+ "@lexical/rich-text": "0.44.0",
19
+ "@lexical/text": "0.44.0",
20
+ "@lexical/utils": "0.44.0",
21
+ "lexical": "0.44.0"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",