From 6bda1e07d93cebe87192fb3984c2e911642a5c2d Mon Sep 17 00:00:00 2001 From: Ying Zhong <0x00eeee@gmail.com> Date: Fri, 18 Sep 2026 20:49:15 +0800 Subject: [PATCH] Handle caret on blank line for tables --- dist/lite/markedit-preview.js | 2 +- dist/markedit-preview.js | 2 +- src/hiddenSyntax/block.ts | 24 +++++++-- tests/hiddenSyntax/table.test.ts | 89 ++++++++++++++++++++++++++++++-- 4 files changed, 108 insertions(+), 9 deletions(-) diff --git a/dist/lite/markedit-preview.js b/dist/lite/markedit-preview.js index d789d6f..10e893b 100644 --- a/dist/lite/markedit-preview.js +++ b/dist/lite/markedit-preview.js @@ -2091,4 +2091,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho .markdown-body { font: inherit; min-width: 0; white-space: normal; word-break: normal; overflow-wrap: break-word; overflow-x: auto; } .markdown-body > table { display: table; width: auto; max-width: min(100%, 960px); margin: 0; overflow: visible; } .source { white-space: pre-wrap; } - `;const i=document.createElement("div");i.className="markdown-body source",i.textContent=this.source,r.append(o,a,i);const c=l=>{l.button!==0||l.shiftKey||l.altKey||l.metaKey||l.ctrlKey||(l.preventDefault(),l.stopPropagation(),t.dispatch({selection:V.EditorSelection.cursor(t.posAtDOM(n)),scrollIntoView:!1}),t.focus())};n.addEventListener("mousedown",c),n.addEventListener("click",l=>l.preventDefault()),r.addEventListener("load",()=>t.requestMeasure(),!0),r.addEventListener("error",()=>t.requestMeasure(),!0);const d=()=>{if(n.isConnected){const l=t.posAtDOM(n);t.dispatch({effects:nc.of({doc:t.state.doc,from:l,to:l+this.source.length})})}};return Promise.all([this.render(),""]).then(([l,s])=>{if(!n.isConnected)return;const f=l.find(b=>b.fromLine===this.doc.lineAt(this.from).number&&b.toLine===this.doc.lineAt(this.to).number);if(f===void 0){d();return}const p=rm.sanitize(f.html,{RETURN_DOM_FRAGMENT:!0,FORBID_TAGS:["style","link","meta","form","input","button","select","textarea","iframe","object","embed","audio","video"],FORBID_ATTR:["tabindex","autofocus","contenteditable"],SANITIZE_NAMED_PROPS:!0}).querySelector("table");if(p===null){d();return}p.querySelectorAll("a").forEach(b=>b.setAttribute("tabindex","-1")),p.querySelectorAll("img").forEach(b=>{const g=b.getAttribute("src");g!==null&&(b.src=Fo(g))}),a.textContent+=s,i.classList.remove("source"),i.replaceChildren(p),t.requestMeasure()}).catch(d),n}destroy(t){Zr.get(t)?.(),Zr.delete(t)}eq(t){return t.source===this.source&&t.referenceContext===this.referenceContext}ignoreEvent(){return!1}}const Zr=new WeakMap,No=V.Facet.define({combine:e=>e[e.length-1]??Ea}),om=V.StateField.define({create:e=>_i(e),update(e,t){if(t.docChanged||t.reconfigured||pe.syntaxTree(t.startState)!==pe.syntaxTree(t.state)){const r=[];for(const o=e.all.iter();o.value!==null;o.next())if(o.value.spec.widget instanceof Un){const u=t.changes.mapPos(o.from,1),a=t.changes.mapPos(o.to,-1);uo!==r.value.from||u!==r.value.to}));return t.selection!==void 0||t.effects.length>0?{all:n,visible:rc(n,t.state)}:e},provide:e=>D.EditorView.decorations.from(e,t=>t.visible)});function _i(e,t=D.Decoration.none){const n=um(e,t);return{all:n,visible:rc(n,e)}}function um(e,t){const n=[],r=pe.syntaxTree(e),o=e.facet(No),u=[];r.iterate({enter:l=>{if(l.name==="Document")return;const s=e.sliceDoc(e.doc.lineAt(l.from).from,e.doc.lineAt(l.to).to);return(l.name!=="Paragraph"&&l.name!=="Table"||s.includes("["))&&u.push(s),!1}});const a=e.sliceDoc(r.length);u.push(a);let i;const c=()=>i??=wh(e.doc.toString()),d=JSON.stringify(u);return r.iterate({enter:l=>{let s;if(l.name==="Table"&&o.includes("table")){for(let b=l.node.parent;b!==null;b=b.parent)if(b.name!=="Document")return!1;if(r.length=r.length)return!1;const f=e.doc.lineAt(l.from).from,h=e.doc.lineAt(l.to).to;let p=new Un(e.doc,f,h,c,d);t.between(f,h,(b,g,y)=>{const x=y.spec.widget;b===f&&g===h&&x instanceof Un&&p.eq(x)&&(p=x)}),s=D.Decoration.replace({block:!0,widget:p}).range(f,h)}if(s!==void 0)return n.push(s),!1}}),D.Decoration.set(n,!0)}function rc(e,t){return e.size===0?e:e.update({filter:(n,r,o)=>{if(be(t,n,r))return!1;let u=!1;return o.spec.widget instanceof Un&&pe.foldedRanges(t).between(n,r,()=>{u=!0}),!u}})}const Ei=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenFence"});function im(e,t){const n=[];if(e.name!=="FencedCode")return n;const r=t.state,o=e.node.firstChild,u=e.node.lastChild;if(o?.name!=="CodeMark"||u?.name!=="CodeMark"||o.from===u.from||!r.sliceDoc(o.from,o.to).startsWith("```"))return n;const a=r.doc.lineAt(o.from),i=r.doc.lineAt(u.from),c=e.node.getChild("CodeInfo");let d=!1;if(pe.foldedRanges(r).between(a.to,i.to,(s,f)=>{if(s>=a.to&&f>=i.to)return d=!0,!1}),d)return n;const l=be(r,e.from,e.to);for(const{from:s,to:f}of t.visibleRanges){const h=Math.max(a.number,r.doc.lineAt(s).number),p=Math.min(i.number,r.doc.lineAt(f).number);for(let b=h;b<=p;b++){const g=r.doc.line(b),y=["cm-md-syntaxHiddenCodeBlock"];b===a.number&&y.push("cm-md-syntaxHiddenCodeStart"),b===i.number&&y.push("cm-md-syntaxHiddenCodeEnd");const x=b===a.number&&!l&&c!==null?{"data-code-language":r.sliceDoc(c.from,c.to).trim().split(/\s+/)[0]}:void 0;n.push(D.Decoration.line({class:y.join(" "),attributes:x}).range(g.from))}}return l||(n.push(Ei.range(o.from,a.to)),n.push(Ei.range(u.from,i.to))),n}function am(e,t){const n=e.node.parent;if(e.name!=="HeaderMark"||n?.name.startsWith("ATXHeading")!==!0||n.firstChild?.from!==e.from)return;const o=sm(t,e.to,n.to);if(!(!lm(t,o,n.to)||be(t,n.from,n.to)))return{from:e.from,to:o}}function cm(e,t){const n=e.node.parent;if(e.name!=="HeaderMark"||n?.name.startsWith("SetextHeading")!==!0)return;const r=t.doc.lineAt(e.from);if(!be(t,n.from,n.to))return r.from}function sm(e,t,n){return t+(/^ */.exec(e.sliceDoc(t,n))?.[0].length??0)}function lm(e,t,n){return/\S/.test(e.sliceDoc(t,n))}function dm(e,t){if(e.name!=="HorizontalRule"||e.node.parent?.name!=="Document")return;const n=t.doc.lineAt(e.from);if(!be(t,n.from,n.to))return D.Decoration.replace({widget:new fm(pe.highlightingFor(t,[Ti.tags.contentSeparator])??"")}).range(n.from,n.to)}class fm extends D.WidgetType{constructor(t){super(),this.highlightClass=t}eq(t){return t.highlightClass===this.highlightClass}toDOM(){const t=document.createElement("span");return t.className=["cm-md-syntaxHiddenHorizontalRule",this.highlightClass].filter(Boolean).join(" "),t.setAttribute("role","separator"),t.setAttribute("aria-orientation","horizontal"),t}}const hm=new Map([["Emphasis","EmphasisMark"],["StrongEmphasis","EmphasisMark"],["Strikethrough","StrikethroughMark"],["InlineCode","CodeMark"]]),pm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),Oo="cm-md-syntaxHiddenInlineCodeBoundary",mm=D.Decoration.mark({class:`${Oo} cm-md-syntaxHiddenInlineCodeStart`}),bm=D.Decoration.mark({class:`${Oo} cm-md-syntaxHiddenInlineCodeEnd`}),gm=D.Decoration.mark({class:`${Oo} cm-md-syntaxHiddenInlineCodeStart cm-md-syntaxHiddenInlineCodeEnd`});function ym(e,t){const n=e.node.parent;if(n===null||hm.get(n.name)!==e.name||be(t,n.from,n.to))return[];const r=[pm.range(e.from,e.to)];if(n.name!=="InlineCode"||e.from!==n.from)return r;const o=n.firstChild?.to,u=n.lastChild?.from;return o===void 0||u===void 0||o>=u||(u-o===1?r.push(gm.range(o,u)):(r.push(mm.range(o,o+1)),r.push(bm.range(u-1,u)))),r}const km=D.EditorView.baseTheme({"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenTable":{boxSizing:"border-box",width:"100%",padding:"0.5em 6px",overflow:"hidden",contain:"content",cursor:"text"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeBlock":{"--code-border":"color-mix(in srgb, currentColor 18%, transparent)",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border)"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart":{position:"relative",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 1px var(--code-border)",borderTopLeftRadius:"6px",borderTopRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart[data-code-language]::after":{content:"attr(data-code-language)",position:"absolute",top:"0.5em",right:"0.5em",maxWidth:"calc(100% - 1em)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8em",lineHeight:"1",opacity:"0.55",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeEnd":{boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 -1px var(--code-border)",borderBottomLeftRadius:"6px",borderBottomRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource *":{fontSize:"0px !important",fontVariantLigatures:"none !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource:has(> *)":{fontSize:"inherit !important",lineHeight:"inherit !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBullet":{display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Menlo, monospace",fontSize:"0.9em",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBulletLayer, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteLayer":{zIndex:"0 !important"},"&.cm-md-syntaxHiddenMode *:has(> .cm-md-syntaxHiddenSource)::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark + *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline":{height:"0",lineHeight:"0",overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeStart .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeStart), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeStart":{borderTopLeftRadius:"3px",borderBottomLeftRadius:"3px",paddingInlineStart:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeEnd .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeEnd), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeEnd":{borderTopRightRadius:"3px",borderBottomRightRadius:"3px",paddingInlineEnd:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-lineNumbers .cm-gutterElement":{overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteBar":{pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert":{display:"inline-flex",alignItems:"center",boxSizing:"border-box",height:"1em",lineHeight:"1em",verticalAlign:"middle",gap:"0.4em",fontFamily:"system-ui, -apple-system, BlinkMacSystemFont, sans-serif",fontStyle:"normal",fontWeight:"500",textIndent:"0"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#0969da"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#1a7f37"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#8250df"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#9a6700"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#d1242f"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#2f81f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#3fb950"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#a371f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#d29922"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#f85149"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon":{display:"inline-block",width:"1em",height:"1em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon svg":{display:"block",width:"100%",height:"100%",fill:"currentColor"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton":{display:"inline-block",appearance:"none",width:"0.9em",height:"0.9em",padding:"0",border:"0",background:"transparent",font:"inherit",marginInlineStart:"0.25em",verticalAlign:"-0.1em",cursor:"pointer"},":where(&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton)":{color:"inherit"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton svg":{display:"block",width:"100%",height:"100%"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenHorizontalRule":{display:"inline-block",width:"100%",borderTop:"2px solid currentColor",verticalAlign:"middle",opacity:"0.35"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenImage":{display:"inline-block",maxWidth:"100%",height:"auto",verticalAlign:"middle"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath .katex-display":{margin:"0"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid svg":{display:"block",maxWidth:"100%",height:"auto",marginInline:"auto"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaidError":{whiteSpace:"pre-wrap",textAlign:"start"}}),Sn=D.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),xm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenQuoteMark"}),Cm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenBulletMark"}),wm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenTaskMark"}),vm=D.Decoration.line({class:"cm-md-syntaxHiddenSetextUnderline"}),Ai=D.Decoration.mark({class:"cm-md-syntaxHiddenLinkLabel"}),_m=D.Decoration.mark({class:"cm-md-syntaxHiddenImageLabel"}),Em=[D.EditorView.editorAttributes.of({class:"cm-md-syntaxHiddenMode"}),Np,Op,D.ViewPlugin.fromClass(class{decorations;constructor(e){this.decorations=Si(e)}update(e){(e.docChanged||e.selectionSet||e.viewportChanged||e.geometryChanged||e.transactions.some(t=>t.reconfigured))&&(this.decorations=Si(e.view))}},{decorations:e=>e.decorations}),Gp,e1,i1,om,km];function oc(e=Ea){return[No.of(e),Em]}const Am=oc();function Si(e){const t=[],n=new Set,r=new Set,o=e.state.facet(No).includes("image"),u=p1(e.state);for(const{from:a,to:i}of e.visibleRanges)pe.syntaxTree(e.state).iterate({from:a,to:i,enter:c=>{c.name==="FencedCode"&&!r.has(c.from)&&(r.add(c.from),t.push(...im(c,e)));const d=Bp(c,e.state);d!==void 0&&!n.has(d.from)&&(n.add(d.from),t.push(D.Decoration.replace({widget:new jp(d.type,d.title)}).range(d.from,d.to)));const l=qp(c,e.state);l!==void 0&&t.push(xm.range(l.from,l.to));const s=Ka(c,e.state);if(s!==void 0){const C=s.task?wm:Cm;t.push(C.range(s.from,s.to))}const f=f1(c,e.state,u);if(f!==void 0){const C=e.state.sliceDoc(f.label.from,f.label.to);if(o&&f.image&&f.destination!=="")t.push(D.Decoration.replace({widget:new _1(f.destination,C)}).range(c.from,c.to));else{f.hidden.forEach(_=>t.push(Sn.range(_.from,_.to)));const w=f.image?_m:Ai;t.push(w.range(f.label.from,f.label.to)),t.push(D.Decoration.widget({widget:new $r(f.image?"image":"link",e.state,f.destination,C,f.highlightTags),side:-1}).range(f.label.to))}}const h=Ro(c,e.state);for(const C of h)be(e.state,C.from,C.to)||(t.push(Sn.range(C.from+1,C.from+2)),t.push(Ai.range(C.from,C.to)),t.push(D.Decoration.widget({widget:new $r("footnote",e.state,C.label,C.label,C.highlightTags),side:-1}).range(C.to)));const p=h1(c,e.state);p!==void 0&&(p.hidden.forEach(C=>t.push(Sn.range(C.from,C.to))),t.push(D.Decoration.widget({widget:new $r("footnoteBack",e.state,p.label,p.label,p.highlightTags),side:-1}).range(p.suffixPosition)),p.suffix!==""&&t.push(D.Decoration.widget({widget:new v1(p.suffix),side:1}).range(p.suffixPosition)));const b=ym(c,e.state);t.push(...b);const g=dm(c,e.state);g!==void 0&&t.push(g);const y=am(c,e.state);y!==void 0&&t.push(Sn.range(y.from,y.to));const x=cm(c,e.state);x!==void 0&&t.push(vm.range(x))}});return D.Decoration.set(t,!0)}const Sm=Object.freeze(Object.defineProperty({__proto__:null,createHiddenSyntaxExtension:oc,hiddenSyntaxExtension:Am},Symbol.toStringTag,{value:"Module"})); + `;const i=document.createElement("div");i.className="markdown-body source",i.textContent=this.source,r.append(o,a,i);const c=l=>{l.button!==0||l.shiftKey||l.altKey||l.metaKey||l.ctrlKey||(l.preventDefault(),l.stopPropagation(),t.dispatch({selection:V.EditorSelection.cursor(t.posAtDOM(n)),scrollIntoView:!1}),t.focus())};n.addEventListener("mousedown",c),n.addEventListener("click",l=>l.preventDefault()),r.addEventListener("load",()=>t.requestMeasure(),!0),r.addEventListener("error",()=>t.requestMeasure(),!0);const d=()=>{if(n.isConnected){const l=t.posAtDOM(n);t.dispatch({effects:nc.of({doc:t.state.doc,from:l,to:l+this.source.length})})}};return Promise.all([this.render(),""]).then(([l,s])=>{if(!n.isConnected)return;const f=l.find(b=>b.fromLine===this.doc.lineAt(this.from).number&&b.toLine===this.doc.lineAt(this.to).number);if(f===void 0){d();return}const p=rm.sanitize(f.html,{RETURN_DOM_FRAGMENT:!0,FORBID_TAGS:["style","link","meta","form","input","button","select","textarea","iframe","object","embed","audio","video"],FORBID_ATTR:["tabindex","autofocus","contenteditable"],SANITIZE_NAMED_PROPS:!0}).querySelector("table");if(p===null){d();return}p.querySelectorAll("a").forEach(b=>b.setAttribute("tabindex","-1")),p.querySelectorAll("img").forEach(b=>{const g=b.getAttribute("src");g!==null&&(b.src=Fo(g))}),a.textContent+=s,i.classList.remove("source"),i.replaceChildren(p),t.requestMeasure()}).catch(d),n}destroy(t){Zr.get(t)?.(),Zr.delete(t)}eq(t){return t.source===this.source&&t.referenceContext===this.referenceContext}ignoreEvent(){return!1}}const Zr=new WeakMap,No=V.Facet.define({combine:e=>e[e.length-1]??Ea}),om=V.StateField.define({create:e=>_i(e),update(e,t){if(t.docChanged||t.reconfigured||pe.syntaxTree(t.startState)!==pe.syntaxTree(t.state)){const r=[];for(const o=e.all.iter();o.value!==null;o.next())if(o.value.spec.widget instanceof Un){const u=t.changes.mapPos(o.from,1),a=t.changes.mapPos(o.to,-1);uo!==r.value.from||u!==r.value.to}));return t.selection!==void 0||t.effects.length>0?{all:n,visible:rc(n,t.state)}:e},provide:e=>D.EditorView.decorations.from(e,t=>t.visible)});function _i(e,t=D.Decoration.none){const n=um(e,t);return{all:n,visible:rc(n,e)}}function um(e,t){const n=[],r=pe.syntaxTree(e),o=e.facet(No),u=[];r.iterate({enter:l=>{if(l.name==="Document")return;const s=e.sliceDoc(e.doc.lineAt(l.from).from,e.doc.lineAt(l.to).to);return(l.name!=="Paragraph"&&l.name!=="Table"||s.includes("["))&&u.push(s),!1}});const a=e.sliceDoc(r.length);u.push(a);let i;const c=()=>i??=wh(e.doc.toString()),d=JSON.stringify(u);return r.iterate({enter:l=>{let s;if(l.name==="Table"&&o.includes("table")){for(let b=l.node.parent;b!==null;b=b.parent)if(b.name!=="Document")return!1;if(r.length=r.length)return!1;const f=e.doc.lineAt(l.from).from,h=e.doc.lineAt(l.to).to;let p=new Un(e.doc,f,h,c,d);t.between(f,h,(b,g,y)=>{const x=y.spec.widget;b===f&&g===h&&x instanceof Un&&p.eq(x)&&(p=x)}),s=D.Decoration.replace({block:!0,widget:p}).range(f,h)}if(s!==void 0)return n.push(s),!1}}),D.Decoration.set(n,!0)}function rc(e,t){return e.size===0?e:e.update({filter:(n,r,o)=>{const u=o.spec.widget instanceof Un;let a=!1;if(u&&pe.foldedRanges(t).between(n,r,()=>{a=!0}),a||be(t,n,r))return!1;if(u&&rc.empty&&c.goalColumn===void 0&&c.head>=i.from&&c.head<=i.to))return!1}return!0}})}const Ei=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenFence"});function im(e,t){const n=[];if(e.name!=="FencedCode")return n;const r=t.state,o=e.node.firstChild,u=e.node.lastChild;if(o?.name!=="CodeMark"||u?.name!=="CodeMark"||o.from===u.from||!r.sliceDoc(o.from,o.to).startsWith("```"))return n;const a=r.doc.lineAt(o.from),i=r.doc.lineAt(u.from),c=e.node.getChild("CodeInfo");let d=!1;if(pe.foldedRanges(r).between(a.to,i.to,(s,f)=>{if(s>=a.to&&f>=i.to)return d=!0,!1}),d)return n;const l=be(r,e.from,e.to);for(const{from:s,to:f}of t.visibleRanges){const h=Math.max(a.number,r.doc.lineAt(s).number),p=Math.min(i.number,r.doc.lineAt(f).number);for(let b=h;b<=p;b++){const g=r.doc.line(b),y=["cm-md-syntaxHiddenCodeBlock"];b===a.number&&y.push("cm-md-syntaxHiddenCodeStart"),b===i.number&&y.push("cm-md-syntaxHiddenCodeEnd");const x=b===a.number&&!l&&c!==null?{"data-code-language":r.sliceDoc(c.from,c.to).trim().split(/\s+/)[0]}:void 0;n.push(D.Decoration.line({class:y.join(" "),attributes:x}).range(g.from))}}return l||(n.push(Ei.range(o.from,a.to)),n.push(Ei.range(u.from,i.to))),n}function am(e,t){const n=e.node.parent;if(e.name!=="HeaderMark"||n?.name.startsWith("ATXHeading")!==!0||n.firstChild?.from!==e.from)return;const o=sm(t,e.to,n.to);if(!(!lm(t,o,n.to)||be(t,n.from,n.to)))return{from:e.from,to:o}}function cm(e,t){const n=e.node.parent;if(e.name!=="HeaderMark"||n?.name.startsWith("SetextHeading")!==!0)return;const r=t.doc.lineAt(e.from);if(!be(t,n.from,n.to))return r.from}function sm(e,t,n){return t+(/^ */.exec(e.sliceDoc(t,n))?.[0].length??0)}function lm(e,t,n){return/\S/.test(e.sliceDoc(t,n))}function dm(e,t){if(e.name!=="HorizontalRule"||e.node.parent?.name!=="Document")return;const n=t.doc.lineAt(e.from);if(!be(t,n.from,n.to))return D.Decoration.replace({widget:new fm(pe.highlightingFor(t,[Ti.tags.contentSeparator])??"")}).range(n.from,n.to)}class fm extends D.WidgetType{constructor(t){super(),this.highlightClass=t}eq(t){return t.highlightClass===this.highlightClass}toDOM(){const t=document.createElement("span");return t.className=["cm-md-syntaxHiddenHorizontalRule",this.highlightClass].filter(Boolean).join(" "),t.setAttribute("role","separator"),t.setAttribute("aria-orientation","horizontal"),t}}const hm=new Map([["Emphasis","EmphasisMark"],["StrongEmphasis","EmphasisMark"],["Strikethrough","StrikethroughMark"],["InlineCode","CodeMark"]]),pm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),Oo="cm-md-syntaxHiddenInlineCodeBoundary",mm=D.Decoration.mark({class:`${Oo} cm-md-syntaxHiddenInlineCodeStart`}),bm=D.Decoration.mark({class:`${Oo} cm-md-syntaxHiddenInlineCodeEnd`}),gm=D.Decoration.mark({class:`${Oo} cm-md-syntaxHiddenInlineCodeStart cm-md-syntaxHiddenInlineCodeEnd`});function ym(e,t){const n=e.node.parent;if(n===null||hm.get(n.name)!==e.name||be(t,n.from,n.to))return[];const r=[pm.range(e.from,e.to)];if(n.name!=="InlineCode"||e.from!==n.from)return r;const o=n.firstChild?.to,u=n.lastChild?.from;return o===void 0||u===void 0||o>=u||(u-o===1?r.push(gm.range(o,u)):(r.push(mm.range(o,o+1)),r.push(bm.range(u-1,u)))),r}const km=D.EditorView.baseTheme({"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenTable":{boxSizing:"border-box",width:"100%",padding:"0.5em 6px",overflow:"hidden",contain:"content",cursor:"text"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeBlock":{"--code-border":"color-mix(in srgb, currentColor 18%, transparent)",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border)"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart":{position:"relative",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 1px var(--code-border)",borderTopLeftRadius:"6px",borderTopRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart[data-code-language]::after":{content:"attr(data-code-language)",position:"absolute",top:"0.5em",right:"0.5em",maxWidth:"calc(100% - 1em)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8em",lineHeight:"1",opacity:"0.55",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeEnd":{boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 -1px var(--code-border)",borderBottomLeftRadius:"6px",borderBottomRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource *":{fontSize:"0px !important",fontVariantLigatures:"none !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource:has(> *)":{fontSize:"inherit !important",lineHeight:"inherit !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBullet":{display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Menlo, monospace",fontSize:"0.9em",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBulletLayer, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteLayer":{zIndex:"0 !important"},"&.cm-md-syntaxHiddenMode *:has(> .cm-md-syntaxHiddenSource)::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark + *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline":{height:"0",lineHeight:"0",overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeStart .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeStart), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeStart":{borderTopLeftRadius:"3px",borderBottomLeftRadius:"3px",paddingInlineStart:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeEnd .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeEnd), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeEnd":{borderTopRightRadius:"3px",borderBottomRightRadius:"3px",paddingInlineEnd:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-lineNumbers .cm-gutterElement":{overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteBar":{pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert":{display:"inline-flex",alignItems:"center",boxSizing:"border-box",height:"1em",lineHeight:"1em",verticalAlign:"middle",gap:"0.4em",fontFamily:"system-ui, -apple-system, BlinkMacSystemFont, sans-serif",fontStyle:"normal",fontWeight:"500",textIndent:"0"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#0969da"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#1a7f37"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#8250df"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#9a6700"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#d1242f"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#2f81f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#3fb950"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#a371f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#d29922"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#f85149"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon":{display:"inline-block",width:"1em",height:"1em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon svg":{display:"block",width:"100%",height:"100%",fill:"currentColor"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton":{display:"inline-block",appearance:"none",width:"0.9em",height:"0.9em",padding:"0",border:"0",background:"transparent",font:"inherit",marginInlineStart:"0.25em",verticalAlign:"-0.1em",cursor:"pointer"},":where(&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton)":{color:"inherit"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton svg":{display:"block",width:"100%",height:"100%"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenHorizontalRule":{display:"inline-block",width:"100%",borderTop:"2px solid currentColor",verticalAlign:"middle",opacity:"0.35"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenImage":{display:"inline-block",maxWidth:"100%",height:"auto",verticalAlign:"middle"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath .katex-display":{margin:"0"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid svg":{display:"block",maxWidth:"100%",height:"auto",marginInline:"auto"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaidError":{whiteSpace:"pre-wrap",textAlign:"start"}}),Sn=D.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),xm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenQuoteMark"}),Cm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenBulletMark"}),wm=D.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenTaskMark"}),vm=D.Decoration.line({class:"cm-md-syntaxHiddenSetextUnderline"}),Ai=D.Decoration.mark({class:"cm-md-syntaxHiddenLinkLabel"}),_m=D.Decoration.mark({class:"cm-md-syntaxHiddenImageLabel"}),Em=[D.EditorView.editorAttributes.of({class:"cm-md-syntaxHiddenMode"}),Np,Op,D.ViewPlugin.fromClass(class{decorations;constructor(e){this.decorations=Si(e)}update(e){(e.docChanged||e.selectionSet||e.viewportChanged||e.geometryChanged||e.transactions.some(t=>t.reconfigured))&&(this.decorations=Si(e.view))}},{decorations:e=>e.decorations}),Gp,e1,i1,om,km];function oc(e=Ea){return[No.of(e),Em]}const Am=oc();function Si(e){const t=[],n=new Set,r=new Set,o=e.state.facet(No).includes("image"),u=p1(e.state);for(const{from:a,to:i}of e.visibleRanges)pe.syntaxTree(e.state).iterate({from:a,to:i,enter:c=>{c.name==="FencedCode"&&!r.has(c.from)&&(r.add(c.from),t.push(...im(c,e)));const d=Bp(c,e.state);d!==void 0&&!n.has(d.from)&&(n.add(d.from),t.push(D.Decoration.replace({widget:new jp(d.type,d.title)}).range(d.from,d.to)));const l=qp(c,e.state);l!==void 0&&t.push(xm.range(l.from,l.to));const s=Ka(c,e.state);if(s!==void 0){const C=s.task?wm:Cm;t.push(C.range(s.from,s.to))}const f=f1(c,e.state,u);if(f!==void 0){const C=e.state.sliceDoc(f.label.from,f.label.to);if(o&&f.image&&f.destination!=="")t.push(D.Decoration.replace({widget:new _1(f.destination,C)}).range(c.from,c.to));else{f.hidden.forEach(_=>t.push(Sn.range(_.from,_.to)));const w=f.image?_m:Ai;t.push(w.range(f.label.from,f.label.to)),t.push(D.Decoration.widget({widget:new $r(f.image?"image":"link",e.state,f.destination,C,f.highlightTags),side:-1}).range(f.label.to))}}const h=Ro(c,e.state);for(const C of h)be(e.state,C.from,C.to)||(t.push(Sn.range(C.from+1,C.from+2)),t.push(Ai.range(C.from,C.to)),t.push(D.Decoration.widget({widget:new $r("footnote",e.state,C.label,C.label,C.highlightTags),side:-1}).range(C.to)));const p=h1(c,e.state);p!==void 0&&(p.hidden.forEach(C=>t.push(Sn.range(C.from,C.to))),t.push(D.Decoration.widget({widget:new $r("footnoteBack",e.state,p.label,p.label,p.highlightTags),side:-1}).range(p.suffixPosition)),p.suffix!==""&&t.push(D.Decoration.widget({widget:new v1(p.suffix),side:1}).range(p.suffixPosition)));const b=ym(c,e.state);t.push(...b);const g=dm(c,e.state);g!==void 0&&t.push(g);const y=am(c,e.state);y!==void 0&&t.push(Sn.range(y.from,y.to));const x=cm(c,e.state);x!==void 0&&t.push(vm.range(x))}});return D.Decoration.set(t,!0)}const Sm=Object.freeze(Object.defineProperty({__proto__:null,createHiddenSyntaxExtension:oc,hiddenSyntaxExtension:Am},Symbol.toStringTag,{value:"Module"})); diff --git a/dist/markedit-preview.js b/dist/markedit-preview.js index 3be71af..190c4e9 100644 --- a/dist/markedit-preview.js +++ b/dist/markedit-preview.js @@ -4153,7 +4153,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),Tt=St,dt=Nt),vt===void .markdown-body { font: inherit; min-width: 0; white-space: normal; word-break: normal; overflow-wrap: break-word; overflow-x: auto; } .markdown-body > table { display: table; width: auto; max-width: min(100%, 960px); margin: 0; overflow: visible; } .source { white-space: pre-wrap; } - `;const o=document.createElement("div");o.className="markdown-body source",o.textContent=this.source,n.append(i,s,o);const l=d=>{d.button!==0||d.shiftKey||d.altKey||d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),e.dispatch({selection:Hi.EditorSelection.cursor(e.posAtDOM(r)),scrollIntoView:!1}),e.focus())};r.addEventListener("mousedown",l),r.addEventListener("click",d=>d.preventDefault()),n.addEventListener("load",()=>e.requestMeasure(),!0),n.addEventListener("error",()=>e.requestMeasure(),!0);const u=()=>{if(r.isConnected){const d=e.posAtDOM(r);e.dispatch({effects:p_e.of({doc:e.state.doc,from:d,to:d+this.source.length})})}};return Promise.all([this.render(),Promise.resolve().then(()=>TG).then(d=>d.default)]).then(([d,h])=>{if(!r.isConnected)return;const f=d.find(m=>m.fromLine===this.doc.lineAt(this.from).number&&m.toLine===this.doc.lineAt(this.to).number);if(f===void 0){u();return}const g=uu.sanitize(f.html,{RETURN_DOM_FRAGMENT:!0,FORBID_TAGS:["style","link","meta","form","input","button","select","textarea","iframe","object","embed","audio","video"],FORBID_ATTR:["tabindex","autofocus","contenteditable"],SANITIZE_NAMED_PROPS:!0}).querySelector("table");if(g===null){u();return}g.querySelectorAll("a").forEach(m=>m.setAttribute("tabindex","-1")),g.querySelectorAll("img").forEach(m=>{const y=m.getAttribute("src");y!==null&&(m.src=vG(y))}),s.textContent+=h,o.classList.remove("source"),o.replaceChildren(g),e.requestMeasure()}).catch(u),r}destroy(e){KL.get(e)?.(),KL.delete(e)}eq(e){return e.source===this.source&&e.referenceContext===this.referenceContext}ignoreEvent(){return!1}}const KL=new WeakMap,aY=Hi.Facet.define({combine:t=>t[t.length-1]??khe}),qct=Hi.StateField.define({create:t=>mne(t),update(t,e){if(e.docChanged||e.reconfigured||Do.syntaxTree(e.startState)!==Do.syntaxTree(e.state)){const n=[];for(const i=t.all.iter();i.value!==null;i.next())if(i.value.spec.widget instanceof B3){const a=e.changes.mapPos(i.from,1),s=e.changes.mapPos(i.to,-1);ai!==n.value.from||a!==n.value.to}));return e.selection!==void 0||e.effects.length>0?{all:r,visible:g_e(r,e.state)}:t},provide:t=>Tr.EditorView.decorations.from(t,e=>e.visible)});function mne(t,e=Tr.Decoration.none){const r=Yct(t,e);return{all:r,visible:g_e(r,t)}}function Yct(t,e){const r=[],n=Do.syntaxTree(t),i=t.facet(aY),a=[];n.iterate({enter:d=>{if(d.name==="Document")return;const h=t.sliceDoc(t.doc.lineAt(d.from).from,t.doc.lineAt(d.to).to);return(d.name!=="Paragraph"&&d.name!=="Table"||h.includes("["))&&a.push(h),!1}});const s=t.sliceDoc(n.length);a.push(s);let o;const l=()=>o??=m$e(t.doc.toString()),u=JSON.stringify(a);return n.iterate({enter:d=>{let h;if(d.name==="Table"&&i.includes("table")){for(let m=d.node.parent;m!==null;m=m.parent)if(m.name!=="Document")return!1;if(n.length=n.length)return!1;const f=t.doc.lineAt(d.from).from,p=t.doc.lineAt(d.to).to;let g=new B3(t.doc,f,p,l,u);e.between(f,p,(m,y,v)=>{const b=v.spec.widget;m===f&&y===p&&b instanceof B3&&g.eq(b)&&(g=b)}),h=Tr.Decoration.replace({block:!0,widget:g}).range(f,p)}else d.name==="BlockMath"&&i.includes("math")?h=Hct(d,t):i.includes("mermaid")&&(h=Vct(d,t));if(h!==void 0)return r.push(h),!1}}),Tr.Decoration.set(r,!0)}function Hct(t,e){const r=e.sliceDoc(t.from,t.to),n=r.slice(2,-2);if(!(!r.startsWith("$$")||!r.endsWith("$$")||n.trim()===""))return Tr.Decoration.replace({block:!0,widget:new Uct(n)}).range(t.from,t.to)}function Vct(t,e){if(t.name!=="FencedCode")return;const r=t.node.getChild("CodeInfo"),n=t.node.lastChild;if(r===null||e.sliceDoc(r.from,r.to).trim()!=="mermaid"||n?.name!=="CodeMark")return;const i=e.sliceDoc(r.to,n.from).trim();if(i!=="")return Tr.Decoration.replace({block:!0,widget:new Gct(i)}).range(t.from,t.to)}function g_e(t,e){return t.size===0?t:t.update({filter:(r,n,i)=>{if(Fo(e,r,n))return!1;let a=!1;return i.spec.widget instanceof B3&&Do.foldedRanges(e).between(r,n,()=>{a=!0}),!a}})}const yne=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenFence"});function Wct(t,e){const r=[];if(t.name!=="FencedCode")return r;const n=e.state,i=t.node.firstChild,a=t.node.lastChild;if(i?.name!=="CodeMark"||a?.name!=="CodeMark"||i.from===a.from||!n.sliceDoc(i.from,i.to).startsWith("```"))return r;const s=n.doc.lineAt(i.from),o=n.doc.lineAt(a.from),l=t.node.getChild("CodeInfo");if(l!==null&&n.sliceDoc(l.from,l.to).trim()==="mermaid")return r;let u=!1;if(Do.foldedRanges(n).between(s.to,o.to,(h,f)=>{if(h>=s.to&&f>=o.to)return u=!0,!1}),u)return r;const d=Fo(n,t.from,t.to);for(const{from:h,to:f}of e.visibleRanges){const p=Math.max(s.number,n.doc.lineAt(h).number),g=Math.min(o.number,n.doc.lineAt(f).number);for(let m=p;m<=g;m++){const y=n.doc.line(m),v=["cm-md-syntaxHiddenCodeBlock"];m===s.number&&v.push("cm-md-syntaxHiddenCodeStart"),m===o.number&&v.push("cm-md-syntaxHiddenCodeEnd");const b=m===s.number&&!d&&l!==null?{"data-code-language":n.sliceDoc(l.from,l.to).trim().split(/\s+/)[0]}:void 0;r.push(Tr.Decoration.line({class:v.join(" "),attributes:b}).range(y.from))}}return d||(r.push(yne.range(i.from,s.to)),r.push(yne.range(a.from,o.to))),r}function Kct(t,e){const r=t.node.parent;if(t.name!=="HeaderMark"||r?.name.startsWith("ATXHeading")!==!0||r.firstChild?.from!==t.from)return;const i=jct(e,t.to,r.to);if(!(!Qct(e,i,r.to)||Fo(e,r.from,r.to)))return{from:t.from,to:i}}function Xct(t,e){const r=t.node.parent;if(t.name!=="HeaderMark"||r?.name.startsWith("SetextHeading")!==!0)return;const n=e.doc.lineAt(t.from);if(!Fo(e,r.from,r.to))return n.from}function jct(t,e,r){return e+(/^ */.exec(t.sliceDoc(e,r))?.[0].length??0)}function Qct(t,e,r){return/\S/.test(t.sliceDoc(e,r))}function Zct(t,e){if(t.name!=="HorizontalRule"||t.node.parent?.name!=="Document")return;const r=e.doc.lineAt(t.from);if(!Fo(e,r.from,r.to))return Tr.Decoration.replace({widget:new Jct(Do.highlightingFor(e,[Nde.tags.contentSeparator])??"")}).range(r.from,r.to)}class Jct extends Tr.WidgetType{constructor(e){super(),this.highlightClass=e}eq(e){return e.highlightClass===this.highlightClass}toDOM(){const e=document.createElement("span");return e.className=["cm-md-syntaxHiddenHorizontalRule",this.highlightClass].filter(Boolean).join(" "),e.setAttribute("role","separator"),e.setAttribute("aria-orientation","horizontal"),e}}const eut=new Map([["Emphasis","EmphasisMark"],["StrongEmphasis","EmphasisMark"],["Strikethrough","StrikethroughMark"],["InlineCode","CodeMark"]]),tut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),sY="cm-md-syntaxHiddenInlineCodeBoundary",rut=Tr.Decoration.mark({class:`${sY} cm-md-syntaxHiddenInlineCodeStart`}),nut=Tr.Decoration.mark({class:`${sY} cm-md-syntaxHiddenInlineCodeEnd`}),iut=Tr.Decoration.mark({class:`${sY} cm-md-syntaxHiddenInlineCodeStart cm-md-syntaxHiddenInlineCodeEnd`});function aut(t,e){const r=t.node.parent;if(r===null||eut.get(r.name)!==t.name||Fo(e,r.from,r.to))return[];const n=[tut.range(t.from,t.to)];if(r.name!=="InlineCode"||t.from!==r.from)return n;const i=r.firstChild?.to,a=r.lastChild?.from;return i===void 0||a===void 0||i>=a||(a-i===1?n.push(iut.range(i,a)):(n.push(rut.range(i,i+1)),n.push(nut.range(a-1,a)))),n}const sut=Tr.EditorView.baseTheme({"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenTable":{boxSizing:"border-box",width:"100%",padding:"0.5em 6px",overflow:"hidden",contain:"content",cursor:"text"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeBlock":{"--code-border":"color-mix(in srgb, currentColor 18%, transparent)",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border)"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart":{position:"relative",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 1px var(--code-border)",borderTopLeftRadius:"6px",borderTopRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart[data-code-language]::after":{content:"attr(data-code-language)",position:"absolute",top:"0.5em",right:"0.5em",maxWidth:"calc(100% - 1em)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8em",lineHeight:"1",opacity:"0.55",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeEnd":{boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 -1px var(--code-border)",borderBottomLeftRadius:"6px",borderBottomRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource *":{fontSize:"0px !important",fontVariantLigatures:"none !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource:has(> *)":{fontSize:"inherit !important",lineHeight:"inherit !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBullet":{display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Menlo, monospace",fontSize:"0.9em",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBulletLayer, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteLayer":{zIndex:"0 !important"},"&.cm-md-syntaxHiddenMode *:has(> .cm-md-syntaxHiddenSource)::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark + *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline":{height:"0",lineHeight:"0",overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeStart .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeStart), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeStart":{borderTopLeftRadius:"3px",borderBottomLeftRadius:"3px",paddingInlineStart:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeEnd .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeEnd), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeEnd":{borderTopRightRadius:"3px",borderBottomRightRadius:"3px",paddingInlineEnd:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-lineNumbers .cm-gutterElement":{overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteBar":{pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert":{display:"inline-flex",alignItems:"center",boxSizing:"border-box",height:"1em",lineHeight:"1em",verticalAlign:"middle",gap:"0.4em",fontFamily:"system-ui, -apple-system, BlinkMacSystemFont, sans-serif",fontStyle:"normal",fontWeight:"500",textIndent:"0"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#0969da"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#1a7f37"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#8250df"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#9a6700"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#d1242f"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#2f81f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#3fb950"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#a371f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#d29922"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#f85149"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon":{display:"inline-block",width:"1em",height:"1em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon svg":{display:"block",width:"100%",height:"100%",fill:"currentColor"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton":{display:"inline-block",appearance:"none",width:"0.9em",height:"0.9em",padding:"0",border:"0",background:"transparent",font:"inherit",marginInlineStart:"0.25em",verticalAlign:"-0.1em",cursor:"pointer"},":where(&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton)":{color:"inherit"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton svg":{display:"block",width:"100%",height:"100%"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenHorizontalRule":{display:"inline-block",width:"100%",borderTop:"2px solid currentColor",verticalAlign:"middle",opacity:"0.35"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenImage":{display:"inline-block",maxWidth:"100%",height:"auto",verticalAlign:"middle"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath .katex-display":{margin:"0"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid svg":{display:"block",maxWidth:"100%",height:"auto",marginInline:"auto"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaidError":{whiteSpace:"pre-wrap",textAlign:"start"}}),sw=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),out=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenQuoteMark"}),lut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenBulletMark"}),cut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenTaskMark"}),uut=Tr.Decoration.line({class:"cm-md-syntaxHiddenSetextUnderline"}),vne=Tr.Decoration.mark({class:"cm-md-syntaxHiddenLinkLabel"}),dut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenImageLabel"}),hut=[Tr.EditorView.editorAttributes.of({class:"cm-md-syntaxHiddenMode"}),Qlt,Zlt,Tr.ViewPlugin.fromClass(class{decorations;constructor(t){this.decorations=_ne(t)}update(t){(t.docChanged||t.selectionSet||t.viewportChanged||t.geometryChanged||t.transactions.some(e=>e.reconfigured))&&(this.decorations=_ne(t.view))}},{decorations:t=>t.decorations}),oct,mct,Tct,qct,sut];function m_e(t=khe){return[aY.of(t),hut]}const fut=m_e();function _ne(t){const e=[],r=new Set,n=new Set,i=t.state.facet(aY).includes("image"),a=Nct(t.state);for(const{from:s,to:o}of t.visibleRanges)Do.syntaxTree(t.state).iterate({from:s,to:o,enter:l=>{l.name==="FencedCode"&&!n.has(l.from)&&(n.add(l.from),e.push(...Wct(l,t)));const u=rct(l,t.state);u!==void 0&&!r.has(u.from)&&(r.add(u.from),e.push(Tr.Decoration.replace({widget:new sct(u.type,u.title)}).range(u.from,u.to)));const d=nct(l,t.state);d!==void 0&&e.push(out.range(d.from,d.to));const h=d_e(l,t.state);if(h!==void 0){const _=h.task?cut:lut;e.push(_.range(h.from,h.to))}const f=Act(l,t.state,a);if(f!==void 0){const _=t.state.sliceDoc(f.label.from,f.label.to);if(i&&f.image&&f.destination!=="")e.push(Tr.Decoration.replace({widget:new zct(f.destination,_)}).range(l.from,l.to));else{f.hidden.forEach(S=>e.push(sw.range(S.from,S.to)));const T=f.image?dut:vne;e.push(T.range(f.label.from,f.label.to)),e.push(Tr.Decoration.widget({widget:new VL(f.image?"image":"link",t.state,f.destination,_,f.highlightTags),side:-1}).range(f.label.to))}}const p=iY(l,t.state);for(const _ of p)Fo(t.state,_.from,_.to)||(e.push(sw.range(_.from+1,_.from+2)),e.push(vne.range(_.from,_.to)),e.push(Tr.Decoration.widget({widget:new VL("footnote",t.state,_.label,_.label,_.highlightTags),side:-1}).range(_.to)));const g=Rct(l,t.state);g!==void 0&&(g.hidden.forEach(_=>e.push(sw.range(_.from,_.to))),e.push(Tr.Decoration.widget({widget:new VL("footnoteBack",t.state,g.label,g.label,g.highlightTags),side:-1}).range(g.suffixPosition)),g.suffix!==""&&e.push(Tr.Decoration.widget({widget:new $ct(g.suffix),side:1}).range(g.suffixPosition)));const m=aut(l,t.state);e.push(...m);const y=Zct(l,t.state);y!==void 0&&e.push(y);const v=Kct(l,t.state);v!==void 0&&e.push(sw.range(v.from,v.to));const b=Xct(l,t.state);b!==void 0&&e.push(uut.range(b))}});return Tr.Decoration.set(e,!0)}const put=Object.freeze(Object.defineProperty({__proto__:null,createHiddenSyntaxExtension:m_e,hiddenSyntaxExtension:fut},Symbol.toStringTag,{value:"Module"}));class Gt extends Error{constructor(e,r){var n="KaTeX parse error: "+e,i,a,s=r&&r.loc;if(s&&s.start<=s.end){var o=s.lexer.input;i=s.start,a=s.end,i===o.length?n+=" at end of input: ":n+=" at position "+(i+1)+": ";var l=o.slice(i,a).replace(/[^]/g,"$&̲"),u;i>15?u="…"+o.slice(i-15,i):u=o.slice(0,i);var d;a+15t.replace(gut,"-$1").toLowerCase(),yut={"&":"&",">":">","<":"<",'"':""","'":"'"},vut=/[&><"']/g,Es=t=>String(t).replace(vut,e=>yut[e]),A4=t=>t.type==="ordgroup"||t.type==="color"?t.body.length===1?A4(t.body[0]):t:t.type==="font"?A4(t.body):t,_ut=new Set(["mathord","textord","atom"]),Qd=t=>_ut.has(A4(t).type),but=t=>{var e=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(t);return e?e[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(e[1])?null:e[1].toLowerCase():"_relative"},F3={displayMode:{type:"boolean",description:"Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.",cli:"-d, --display-mode"},output:{type:{enum:["htmlAndMathml","html","mathml"]},description:"Determines the markup language of the output.",cli:"-F, --format "},leqno:{type:"boolean",description:"Render display math in leqno style (left-justified tags)."},fleqn:{type:"boolean",description:"Render display math flush left."},throwOnError:{type:"boolean",default:!0,cli:"-t, --no-throw-on-error",cliDescription:"Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error."},errorColor:{type:"string",default:"#cc0000",cli:"-c, --error-color ",cliDescription:"A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.",cliProcessor:t=>"#"+t},macros:{type:"object",cli:"-m, --macro ",cliDescription:"Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).",cliDefault:[],cliProcessor:(t,e)=>(e.push(t),e)},minRuleThickness:{type:"number",description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:t=>Math.max(0,t),cli:"--min-rule-thickness ",cliProcessor:parseFloat},colorIsTextColor:{type:"boolean",description:"Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.",cli:"-b, --color-is-text-color"},strict:{type:[{enum:["warn","ignore","error"]},"boolean","function"],description:"Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.",cli:"-S, --strict",cliDefault:!1},trust:{type:["boolean","function"],description:"Trust the input, enabling all HTML features such as \\url.",cli:"-T, --trust"},maxSize:{type:"number",default:1/0,description:"If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large",processor:t=>Math.max(0,t),cli:"-s, --max-size ",cliProcessor:parseInt},maxExpand:{type:"number",default:1e3,description:"Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.",processor:t=>Math.max(0,t),cli:"-e, --max-expand ",cliProcessor:t=>t==="Infinity"?1/0:parseInt(t)},globalGroup:{type:"boolean",cli:!1}};function Eut(t){if(typeof t!="string")return t.enum[0];switch(t){case"boolean":return!1;case"string":return"";case"number":return 0;case"object":return{};default:throw new Error("Unexpected schema type; settings must declare an explicit default.")}}function Tut(t){if(t.default!==void 0)return t.default;var e=Array.isArray(t.type)?t.type[0]:t.type;return Eut(e)}function Sut(t,e,r,n){var i=r[e];t[e]=i!==void 0?n.processor?n.processor(i):i:Tut(n)}class oY{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e=e||{};for(var r of Object.keys(F3)){var n=F3[r];n&&Sut(this,r,e,n)}}reportNonstrict(e,r,n){var i=this.strict;if(typeof i=="function"&&(i=i(e,r,n)),!(!i||i==="ignore")){if(i===!0||i==="error")throw new Gt("LaTeX-incompatible input and strict mode is set to 'error': "+(r+" ["+e+"]"),n);i==="warn"?typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(r+" ["+e+"]")):typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+r+" ["+e+"]"))}}useStrictBehavior(e,r,n){var i=this.strict;if(typeof i=="function")try{i=i(e,r,n)}catch{i="error"}return!i||i==="ignore"?!1:i===!0||i==="error"?!0:i==="warn"?(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(r+" ["+e+"]")),!1):(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+r+" ["+e+"]")),!1)}isTrusted(e){if("url"in e&&e.url&&!e.protocol){var r=but(e.url);if(r==null)return!1;e.protocol=r}var n=typeof this.trust=="function"?this.trust(e):this.trust;return!!n}}class mh{constructor(e,r,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=r,this.cramped=n}sup(){return Kc[xut[this.id]]}sub(){return Kc[Cut[this.id]]}fracNum(){return Kc[wut[this.id]]}fracDen(){return Kc[kut[this.id]]}cramp(){return Kc[Aut[this.id]]}text(){return Kc[Rut[this.id]]}isTight(){return this.size>=2}}var lY=0,$3=1,p1=2,Td=3,AS=4,Al=5,Lb=6,js=7,Kc=[new mh(lY,0,!1),new mh($3,0,!0),new mh(p1,1,!1),new mh(Td,1,!0),new mh(AS,2,!1),new mh(Al,2,!0),new mh(Lb,3,!1),new mh(js,3,!0)],xut=[AS,Al,AS,Al,Lb,js,Lb,js],Cut=[Al,Al,Al,Al,js,js,js,js],wut=[p1,Td,AS,Al,Lb,js,Lb,js],kut=[Td,Td,Al,Al,js,js,js,js],Aut=[$3,$3,Td,Td,Al,Al,js,js],Rut=[lY,$3,p1,Td,p1,Td,p1,Td],Kr={DISPLAY:Kc[lY],TEXT:Kc[p1],SCRIPT:Kc[AS],SCRIPTSCRIPT:Kc[Lb]},CB=[{name:"latin",blocks:[[256,591],[768,879]]},{name:"cyrillic",blocks:[[1024,1279]]},{name:"armenian",blocks:[[1328,1423]]},{name:"brahmic",blocks:[[2304,4255]]},{name:"georgian",blocks:[[4256,4351]]},{name:"cjk",blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:"hangul",blocks:[[44032,55215]]}];function Nut(t){for(var e=0;e=i[0]&&t<=i[1])return r.name}return null}var R4=[];CB.forEach(t=>t.blocks.forEach(e=>R4.push(...e)));function y_e(t){for(var e=0;e=R4[e]&&t<=R4[e+1])return!0;return!1}var ma=t=>t+" "+t,Hg=80,Iut=function(e,r){return"M95,"+(622+e+r)+` + `;const o=document.createElement("div");o.className="markdown-body source",o.textContent=this.source,n.append(i,s,o);const l=d=>{d.button!==0||d.shiftKey||d.altKey||d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),e.dispatch({selection:Hi.EditorSelection.cursor(e.posAtDOM(r)),scrollIntoView:!1}),e.focus())};r.addEventListener("mousedown",l),r.addEventListener("click",d=>d.preventDefault()),n.addEventListener("load",()=>e.requestMeasure(),!0),n.addEventListener("error",()=>e.requestMeasure(),!0);const u=()=>{if(r.isConnected){const d=e.posAtDOM(r);e.dispatch({effects:p_e.of({doc:e.state.doc,from:d,to:d+this.source.length})})}};return Promise.all([this.render(),Promise.resolve().then(()=>TG).then(d=>d.default)]).then(([d,h])=>{if(!r.isConnected)return;const f=d.find(m=>m.fromLine===this.doc.lineAt(this.from).number&&m.toLine===this.doc.lineAt(this.to).number);if(f===void 0){u();return}const g=uu.sanitize(f.html,{RETURN_DOM_FRAGMENT:!0,FORBID_TAGS:["style","link","meta","form","input","button","select","textarea","iframe","object","embed","audio","video"],FORBID_ATTR:["tabindex","autofocus","contenteditable"],SANITIZE_NAMED_PROPS:!0}).querySelector("table");if(g===null){u();return}g.querySelectorAll("a").forEach(m=>m.setAttribute("tabindex","-1")),g.querySelectorAll("img").forEach(m=>{const y=m.getAttribute("src");y!==null&&(m.src=vG(y))}),s.textContent+=h,o.classList.remove("source"),o.replaceChildren(g),e.requestMeasure()}).catch(u),r}destroy(e){KL.get(e)?.(),KL.delete(e)}eq(e){return e.source===this.source&&e.referenceContext===this.referenceContext}ignoreEvent(){return!1}}const KL=new WeakMap,aY=Hi.Facet.define({combine:t=>t[t.length-1]??khe}),qct=Hi.StateField.define({create:t=>mne(t),update(t,e){if(e.docChanged||e.reconfigured||Do.syntaxTree(e.startState)!==Do.syntaxTree(e.state)){const n=[];for(const i=t.all.iter();i.value!==null;i.next())if(i.value.spec.widget instanceof B3){const a=e.changes.mapPos(i.from,1),s=e.changes.mapPos(i.to,-1);ai!==n.value.from||a!==n.value.to}));return e.selection!==void 0||e.effects.length>0?{all:r,visible:g_e(r,e.state)}:t},provide:t=>Tr.EditorView.decorations.from(t,e=>e.visible)});function mne(t,e=Tr.Decoration.none){const r=Yct(t,e);return{all:r,visible:g_e(r,t)}}function Yct(t,e){const r=[],n=Do.syntaxTree(t),i=t.facet(aY),a=[];n.iterate({enter:d=>{if(d.name==="Document")return;const h=t.sliceDoc(t.doc.lineAt(d.from).from,t.doc.lineAt(d.to).to);return(d.name!=="Paragraph"&&d.name!=="Table"||h.includes("["))&&a.push(h),!1}});const s=t.sliceDoc(n.length);a.push(s);let o;const l=()=>o??=m$e(t.doc.toString()),u=JSON.stringify(a);return n.iterate({enter:d=>{let h;if(d.name==="Table"&&i.includes("table")){for(let m=d.node.parent;m!==null;m=m.parent)if(m.name!=="Document")return!1;if(n.length=n.length)return!1;const f=t.doc.lineAt(d.from).from,p=t.doc.lineAt(d.to).to;let g=new B3(t.doc,f,p,l,u);e.between(f,p,(m,y,v)=>{const b=v.spec.widget;m===f&&y===p&&b instanceof B3&&g.eq(b)&&(g=b)}),h=Tr.Decoration.replace({block:!0,widget:g}).range(f,p)}else d.name==="BlockMath"&&i.includes("math")?h=Hct(d,t):i.includes("mermaid")&&(h=Vct(d,t));if(h!==void 0)return r.push(h),!1}}),Tr.Decoration.set(r,!0)}function Hct(t,e){const r=e.sliceDoc(t.from,t.to),n=r.slice(2,-2);if(!(!r.startsWith("$$")||!r.endsWith("$$")||n.trim()===""))return Tr.Decoration.replace({block:!0,widget:new Uct(n)}).range(t.from,t.to)}function Vct(t,e){if(t.name!=="FencedCode")return;const r=t.node.getChild("CodeInfo"),n=t.node.lastChild;if(r===null||e.sliceDoc(r.from,r.to).trim()!=="mermaid"||n?.name!=="CodeMark")return;const i=e.sliceDoc(r.to,n.from).trim();if(i!=="")return Tr.Decoration.replace({block:!0,widget:new Gct(i)}).range(t.from,t.to)}function g_e(t,e){return t.size===0?t:t.update({filter:(r,n,i)=>{const a=i.spec.widget instanceof B3;let s=!1;if(a&&Do.foldedRanges(e).between(r,n,()=>{s=!0}),s||Fo(e,r,n))return!1;if(a&&nl.empty&&l.goalColumn===void 0&&l.head>=o.from&&l.head<=o.to))return!1}return!0}})}const yne=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenFence"});function Wct(t,e){const r=[];if(t.name!=="FencedCode")return r;const n=e.state,i=t.node.firstChild,a=t.node.lastChild;if(i?.name!=="CodeMark"||a?.name!=="CodeMark"||i.from===a.from||!n.sliceDoc(i.from,i.to).startsWith("```"))return r;const s=n.doc.lineAt(i.from),o=n.doc.lineAt(a.from),l=t.node.getChild("CodeInfo");if(l!==null&&n.sliceDoc(l.from,l.to).trim()==="mermaid")return r;let u=!1;if(Do.foldedRanges(n).between(s.to,o.to,(h,f)=>{if(h>=s.to&&f>=o.to)return u=!0,!1}),u)return r;const d=Fo(n,t.from,t.to);for(const{from:h,to:f}of e.visibleRanges){const p=Math.max(s.number,n.doc.lineAt(h).number),g=Math.min(o.number,n.doc.lineAt(f).number);for(let m=p;m<=g;m++){const y=n.doc.line(m),v=["cm-md-syntaxHiddenCodeBlock"];m===s.number&&v.push("cm-md-syntaxHiddenCodeStart"),m===o.number&&v.push("cm-md-syntaxHiddenCodeEnd");const b=m===s.number&&!d&&l!==null?{"data-code-language":n.sliceDoc(l.from,l.to).trim().split(/\s+/)[0]}:void 0;r.push(Tr.Decoration.line({class:v.join(" "),attributes:b}).range(y.from))}}return d||(r.push(yne.range(i.from,s.to)),r.push(yne.range(a.from,o.to))),r}function Kct(t,e){const r=t.node.parent;if(t.name!=="HeaderMark"||r?.name.startsWith("ATXHeading")!==!0||r.firstChild?.from!==t.from)return;const i=jct(e,t.to,r.to);if(!(!Qct(e,i,r.to)||Fo(e,r.from,r.to)))return{from:t.from,to:i}}function Xct(t,e){const r=t.node.parent;if(t.name!=="HeaderMark"||r?.name.startsWith("SetextHeading")!==!0)return;const n=e.doc.lineAt(t.from);if(!Fo(e,r.from,r.to))return n.from}function jct(t,e,r){return e+(/^ */.exec(t.sliceDoc(e,r))?.[0].length??0)}function Qct(t,e,r){return/\S/.test(t.sliceDoc(e,r))}function Zct(t,e){if(t.name!=="HorizontalRule"||t.node.parent?.name!=="Document")return;const r=e.doc.lineAt(t.from);if(!Fo(e,r.from,r.to))return Tr.Decoration.replace({widget:new Jct(Do.highlightingFor(e,[Nde.tags.contentSeparator])??"")}).range(r.from,r.to)}class Jct extends Tr.WidgetType{constructor(e){super(),this.highlightClass=e}eq(e){return e.highlightClass===this.highlightClass}toDOM(){const e=document.createElement("span");return e.className=["cm-md-syntaxHiddenHorizontalRule",this.highlightClass].filter(Boolean).join(" "),e.setAttribute("role","separator"),e.setAttribute("aria-orientation","horizontal"),e}}const eut=new Map([["Emphasis","EmphasisMark"],["StrongEmphasis","EmphasisMark"],["Strikethrough","StrikethroughMark"],["InlineCode","CodeMark"]]),tut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),sY="cm-md-syntaxHiddenInlineCodeBoundary",rut=Tr.Decoration.mark({class:`${sY} cm-md-syntaxHiddenInlineCodeStart`}),nut=Tr.Decoration.mark({class:`${sY} cm-md-syntaxHiddenInlineCodeEnd`}),iut=Tr.Decoration.mark({class:`${sY} cm-md-syntaxHiddenInlineCodeStart cm-md-syntaxHiddenInlineCodeEnd`});function aut(t,e){const r=t.node.parent;if(r===null||eut.get(r.name)!==t.name||Fo(e,r.from,r.to))return[];const n=[tut.range(t.from,t.to)];if(r.name!=="InlineCode"||t.from!==r.from)return n;const i=r.firstChild?.to,a=r.lastChild?.from;return i===void 0||a===void 0||i>=a||(a-i===1?n.push(iut.range(i,a)):(n.push(rut.range(i,i+1)),n.push(nut.range(a-1,a)))),n}const sut=Tr.EditorView.baseTheme({"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenTable":{boxSizing:"border-box",width:"100%",padding:"0.5em 6px",overflow:"hidden",contain:"content",cursor:"text"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeBlock":{"--code-border":"color-mix(in srgb, currentColor 18%, transparent)",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border)"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart":{position:"relative",boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 1px var(--code-border)",borderTopLeftRadius:"6px",borderTopRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeStart[data-code-language]::after":{content:"attr(data-code-language)",position:"absolute",top:"0.5em",right:"0.5em",maxWidth:"calc(100% - 1em)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8em",lineHeight:"1",opacity:"0.55",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenCodeEnd":{boxShadow:"inset 1px 0 var(--code-border), inset -1px 0 var(--code-border), inset 0 -1px var(--code-border)",borderBottomLeftRadius:"6px",borderBottomRightRadius:"6px"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource *":{fontSize:"0px !important",fontVariantLigatures:"none !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSource:has(> *)":{fontSize:"inherit !important",lineHeight:"inherit !important"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenFence *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListMark *":{fontSize:"inherit !important",visibility:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBullet":{display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"Menlo, monospace",fontSize:"0.9em",pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenListBulletLayer, &.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteLayer":{zIndex:"0 !important"},"&.cm-md-syntaxHiddenMode *:has(> .cm-md-syntaxHiddenSource)::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenQuoteMark + *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline":{height:"0",lineHeight:"0",overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenSetextUnderline *::before":{display:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeStart .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeStart), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeStart":{borderTopLeftRadius:"3px",borderBottomLeftRadius:"3px",paddingInlineStart:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenInlineCodeEnd .cm-md-inlineCode, &.cm-md-syntaxHiddenMode .cm-md-inlineCode:has(.cm-md-syntaxHiddenInlineCodeEnd), &.cm-md-syntaxHiddenMode .cm-md-inlineCode.cm-md-syntaxHiddenInlineCodeEnd":{borderTopRightRadius:"3px",borderBottomRightRadius:"3px",paddingInlineEnd:"0.25em"},"&.cm-md-syntaxHiddenMode .cm-lineNumbers .cm-gutterElement":{overflow:"hidden"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockquoteBar":{pointerEvents:"none"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert":{display:"inline-flex",alignItems:"center",boxSizing:"border-box",height:"1em",lineHeight:"1em",verticalAlign:"middle",gap:"0.4em",fontFamily:"system-ui, -apple-system, BlinkMacSystemFont, sans-serif",fontStyle:"normal",fontWeight:"500",textIndent:"0"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#0969da"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#1a7f37"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#8250df"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#9a6700"},'&light.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#d1242f"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="note"]':{color:"#2f81f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="tip"]':{color:"#3fb950"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="important"]':{color:"#a371f7"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="warning"]':{color:"#d29922"},'&dark.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlert[data-type="caution"]':{color:"#f85149"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon":{display:"inline-block",width:"1em",height:"1em"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenAlertIcon svg":{display:"block",width:"100%",height:"100%",fill:"currentColor"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton":{display:"inline-block",appearance:"none",width:"0.9em",height:"0.9em",padding:"0",border:"0",background:"transparent",font:"inherit",marginInlineStart:"0.25em",verticalAlign:"-0.1em",cursor:"pointer"},":where(&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton)":{color:"inherit"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenLinkButton svg":{display:"block",width:"100%",height:"100%"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenHorizontalRule":{display:"inline-block",width:"100%",borderTop:"2px solid currentColor",verticalAlign:"middle",opacity:"0.35"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenImage":{display:"inline-block",maxWidth:"100%",height:"auto",verticalAlign:"middle"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenBlockMath .katex-display":{margin:"0"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid":{boxSizing:"border-box",width:"100%",paddingBlock:"0.5em",overflowX:"auto",overflowY:"hidden",textAlign:"center"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaid svg":{display:"block",maxWidth:"100%",height:"auto",marginInline:"auto"},"&.cm-md-syntaxHiddenMode .cm-md-syntaxHiddenMermaidError":{whiteSpace:"pre-wrap",textAlign:"start"}}),sw=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource"}),out=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenQuoteMark"}),lut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenBulletMark"}),cut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenSource cm-md-syntaxHiddenListMark cm-md-syntaxHiddenTaskMark"}),uut=Tr.Decoration.line({class:"cm-md-syntaxHiddenSetextUnderline"}),vne=Tr.Decoration.mark({class:"cm-md-syntaxHiddenLinkLabel"}),dut=Tr.Decoration.mark({class:"cm-md-syntaxHiddenImageLabel"}),hut=[Tr.EditorView.editorAttributes.of({class:"cm-md-syntaxHiddenMode"}),Qlt,Zlt,Tr.ViewPlugin.fromClass(class{decorations;constructor(t){this.decorations=_ne(t)}update(t){(t.docChanged||t.selectionSet||t.viewportChanged||t.geometryChanged||t.transactions.some(e=>e.reconfigured))&&(this.decorations=_ne(t.view))}},{decorations:t=>t.decorations}),oct,mct,Tct,qct,sut];function m_e(t=khe){return[aY.of(t),hut]}const fut=m_e();function _ne(t){const e=[],r=new Set,n=new Set,i=t.state.facet(aY).includes("image"),a=Nct(t.state);for(const{from:s,to:o}of t.visibleRanges)Do.syntaxTree(t.state).iterate({from:s,to:o,enter:l=>{l.name==="FencedCode"&&!n.has(l.from)&&(n.add(l.from),e.push(...Wct(l,t)));const u=rct(l,t.state);u!==void 0&&!r.has(u.from)&&(r.add(u.from),e.push(Tr.Decoration.replace({widget:new sct(u.type,u.title)}).range(u.from,u.to)));const d=nct(l,t.state);d!==void 0&&e.push(out.range(d.from,d.to));const h=d_e(l,t.state);if(h!==void 0){const _=h.task?cut:lut;e.push(_.range(h.from,h.to))}const f=Act(l,t.state,a);if(f!==void 0){const _=t.state.sliceDoc(f.label.from,f.label.to);if(i&&f.image&&f.destination!=="")e.push(Tr.Decoration.replace({widget:new zct(f.destination,_)}).range(l.from,l.to));else{f.hidden.forEach(S=>e.push(sw.range(S.from,S.to)));const T=f.image?dut:vne;e.push(T.range(f.label.from,f.label.to)),e.push(Tr.Decoration.widget({widget:new VL(f.image?"image":"link",t.state,f.destination,_,f.highlightTags),side:-1}).range(f.label.to))}}const p=iY(l,t.state);for(const _ of p)Fo(t.state,_.from,_.to)||(e.push(sw.range(_.from+1,_.from+2)),e.push(vne.range(_.from,_.to)),e.push(Tr.Decoration.widget({widget:new VL("footnote",t.state,_.label,_.label,_.highlightTags),side:-1}).range(_.to)));const g=Rct(l,t.state);g!==void 0&&(g.hidden.forEach(_=>e.push(sw.range(_.from,_.to))),e.push(Tr.Decoration.widget({widget:new VL("footnoteBack",t.state,g.label,g.label,g.highlightTags),side:-1}).range(g.suffixPosition)),g.suffix!==""&&e.push(Tr.Decoration.widget({widget:new $ct(g.suffix),side:1}).range(g.suffixPosition)));const m=aut(l,t.state);e.push(...m);const y=Zct(l,t.state);y!==void 0&&e.push(y);const v=Kct(l,t.state);v!==void 0&&e.push(sw.range(v.from,v.to));const b=Xct(l,t.state);b!==void 0&&e.push(uut.range(b))}});return Tr.Decoration.set(e,!0)}const put=Object.freeze(Object.defineProperty({__proto__:null,createHiddenSyntaxExtension:m_e,hiddenSyntaxExtension:fut},Symbol.toStringTag,{value:"Module"}));class Gt extends Error{constructor(e,r){var n="KaTeX parse error: "+e,i,a,s=r&&r.loc;if(s&&s.start<=s.end){var o=s.lexer.input;i=s.start,a=s.end,i===o.length?n+=" at end of input: ":n+=" at position "+(i+1)+": ";var l=o.slice(i,a).replace(/[^]/g,"$&̲"),u;i>15?u="…"+o.slice(i-15,i):u=o.slice(0,i);var d;a+15t.replace(gut,"-$1").toLowerCase(),yut={"&":"&",">":">","<":"<",'"':""","'":"'"},vut=/[&><"']/g,Es=t=>String(t).replace(vut,e=>yut[e]),A4=t=>t.type==="ordgroup"||t.type==="color"?t.body.length===1?A4(t.body[0]):t:t.type==="font"?A4(t.body):t,_ut=new Set(["mathord","textord","atom"]),Qd=t=>_ut.has(A4(t).type),but=t=>{var e=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(t);return e?e[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(e[1])?null:e[1].toLowerCase():"_relative"},F3={displayMode:{type:"boolean",description:"Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.",cli:"-d, --display-mode"},output:{type:{enum:["htmlAndMathml","html","mathml"]},description:"Determines the markup language of the output.",cli:"-F, --format "},leqno:{type:"boolean",description:"Render display math in leqno style (left-justified tags)."},fleqn:{type:"boolean",description:"Render display math flush left."},throwOnError:{type:"boolean",default:!0,cli:"-t, --no-throw-on-error",cliDescription:"Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error."},errorColor:{type:"string",default:"#cc0000",cli:"-c, --error-color ",cliDescription:"A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.",cliProcessor:t=>"#"+t},macros:{type:"object",cli:"-m, --macro ",cliDescription:"Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).",cliDefault:[],cliProcessor:(t,e)=>(e.push(t),e)},minRuleThickness:{type:"number",description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:t=>Math.max(0,t),cli:"--min-rule-thickness ",cliProcessor:parseFloat},colorIsTextColor:{type:"boolean",description:"Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.",cli:"-b, --color-is-text-color"},strict:{type:[{enum:["warn","ignore","error"]},"boolean","function"],description:"Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.",cli:"-S, --strict",cliDefault:!1},trust:{type:["boolean","function"],description:"Trust the input, enabling all HTML features such as \\url.",cli:"-T, --trust"},maxSize:{type:"number",default:1/0,description:"If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large",processor:t=>Math.max(0,t),cli:"-s, --max-size ",cliProcessor:parseInt},maxExpand:{type:"number",default:1e3,description:"Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.",processor:t=>Math.max(0,t),cli:"-e, --max-expand ",cliProcessor:t=>t==="Infinity"?1/0:parseInt(t)},globalGroup:{type:"boolean",cli:!1}};function Eut(t){if(typeof t!="string")return t.enum[0];switch(t){case"boolean":return!1;case"string":return"";case"number":return 0;case"object":return{};default:throw new Error("Unexpected schema type; settings must declare an explicit default.")}}function Tut(t){if(t.default!==void 0)return t.default;var e=Array.isArray(t.type)?t.type[0]:t.type;return Eut(e)}function Sut(t,e,r,n){var i=r[e];t[e]=i!==void 0?n.processor?n.processor(i):i:Tut(n)}class oY{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e=e||{};for(var r of Object.keys(F3)){var n=F3[r];n&&Sut(this,r,e,n)}}reportNonstrict(e,r,n){var i=this.strict;if(typeof i=="function"&&(i=i(e,r,n)),!(!i||i==="ignore")){if(i===!0||i==="error")throw new Gt("LaTeX-incompatible input and strict mode is set to 'error': "+(r+" ["+e+"]"),n);i==="warn"?typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(r+" ["+e+"]")):typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+r+" ["+e+"]"))}}useStrictBehavior(e,r,n){var i=this.strict;if(typeof i=="function")try{i=i(e,r,n)}catch{i="error"}return!i||i==="ignore"?!1:i===!0||i==="error"?!0:i==="warn"?(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(r+" ["+e+"]")),!1):(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+i+"': "+r+" ["+e+"]")),!1)}isTrusted(e){if("url"in e&&e.url&&!e.protocol){var r=but(e.url);if(r==null)return!1;e.protocol=r}var n=typeof this.trust=="function"?this.trust(e):this.trust;return!!n}}class mh{constructor(e,r,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=r,this.cramped=n}sup(){return Kc[xut[this.id]]}sub(){return Kc[Cut[this.id]]}fracNum(){return Kc[wut[this.id]]}fracDen(){return Kc[kut[this.id]]}cramp(){return Kc[Aut[this.id]]}text(){return Kc[Rut[this.id]]}isTight(){return this.size>=2}}var lY=0,$3=1,p1=2,Td=3,AS=4,Al=5,Lb=6,js=7,Kc=[new mh(lY,0,!1),new mh($3,0,!0),new mh(p1,1,!1),new mh(Td,1,!0),new mh(AS,2,!1),new mh(Al,2,!0),new mh(Lb,3,!1),new mh(js,3,!0)],xut=[AS,Al,AS,Al,Lb,js,Lb,js],Cut=[Al,Al,Al,Al,js,js,js,js],wut=[p1,Td,AS,Al,Lb,js,Lb,js],kut=[Td,Td,Al,Al,js,js,js,js],Aut=[$3,$3,Td,Td,Al,Al,js,js],Rut=[lY,$3,p1,Td,p1,Td,p1,Td],Kr={DISPLAY:Kc[lY],TEXT:Kc[p1],SCRIPT:Kc[AS],SCRIPTSCRIPT:Kc[Lb]},CB=[{name:"latin",blocks:[[256,591],[768,879]]},{name:"cyrillic",blocks:[[1024,1279]]},{name:"armenian",blocks:[[1328,1423]]},{name:"brahmic",blocks:[[2304,4255]]},{name:"georgian",blocks:[[4256,4351]]},{name:"cjk",blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:"hangul",blocks:[[44032,55215]]}];function Nut(t){for(var e=0;e=i[0]&&t<=i[1])return r.name}return null}var R4=[];CB.forEach(t=>t.blocks.forEach(e=>R4.push(...e)));function y_e(t){for(var e=0;e=R4[e]&&t<=R4[e+1])return!0;return!1}var ma=t=>t+" "+t,Hg=80,Iut=function(e,r){return"M95,"+(622+e+r)+` c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 diff --git a/src/hiddenSyntax/block.ts b/src/hiddenSyntax/block.ts index c94837b..c25a674 100644 --- a/src/hiddenSyntax/block.ts +++ b/src/hiddenSyntax/block.ts @@ -174,16 +174,32 @@ function hideSelectedBlocks(decorations: DecorationSet, state: EditorState) { return decorations.update({ filter: (from, to, decoration) => { + const isTable = decoration.spec.widget instanceof TableWidget; + let folded = false; + if (isTable) { + foldedRanges(state).between(from, to, () => { folded = true; }); + } + + if (folded) { + return false; + } + if (selectionReveals(state, from, to)) { return false; } - let folded = false; - if (decoration.spec.widget instanceof TableWidget) { - foldedRanges(state).between(from, to, () => { folded = true; }); + if (isTable) { + if (to < state.doc.length) { + // Keep source for typing on the next blank line, not vertical navigation. + const nextLine = state.doc.lineAt(to + 1); + if (nextLine.text.trim() === '' && state.selection.ranges.some(range => + range.empty && range.goalColumn === undefined && range.head >= nextLine.from && range.head <= nextLine.to)) { + return false; + } + } } - return !folded; + return true; }, }); } diff --git a/tests/hiddenSyntax/table.test.ts b/tests/hiddenSyntax/table.test.ts index 6dc3491..ceaa900 100644 --- a/tests/hiddenSyntax/table.test.ts +++ b/tests/hiddenSyntax/table.test.ts @@ -4,7 +4,7 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'; import { EditorSelection, EditorState } from '@codemirror/state'; import { EditorView, keymap, runScopeHandlers } from '@codemirror/view'; import { standardKeymap } from '@codemirror/commands'; -import { codeFolding, foldEffect, unfoldEffect } from '@codemirror/language'; +import { codeFolding, foldedRanges, foldEffect, unfoldEffect } from '@codemirror/language'; import { hiddenSyntaxExtension } from '../../src/hiddenSyntax'; import { TableWidget } from '../../src/hiddenSyntax/components/table'; import * as renderer from '../../src/render'; @@ -25,6 +25,49 @@ function setUp(text = source) { } describe('Hidden tables', () => { + test.each([ + '| asdf | asdf |\n| ---- | ---- |\n', + '| asdf | asdf |\n| ---- | ---- |\n ', + `${table}\n`, + `${table}\n\t`, + ])('keeps source while the caret is on the next blank line: %j', text => { + setUp(text); + expect(widget()).toBeNull(); + expect(window.editor.state.doc.toString()).toBe(text); + }); + + test('keeps source while adding rows and renders after a blank separator', async () => { + const text = '| asdf | asdf |\n| ---- | ---- |'; + setUp(text); + window.editor.dispatch(window.editor.state.replaceSelection('\n'), { userEvent: 'input.type' }); + expect(widget()).toBeNull(); + + window.editor.dispatch(window.editor.state.replaceSelection('| one | two |'), { userEvent: 'input.type' }); + expect(widget()).toBeNull(); + window.editor.dispatch(window.editor.state.replaceSelection('\n'), { userEvent: 'input.type' }); + expect(widget()).toBeNull(); + + window.editor.dispatch(window.editor.state.replaceSelection('\n'), { userEvent: 'input.type' }); + await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); + expect([...renderedTable()!.querySelectorAll('td')].map(cell => cell.textContent)).toEqual(['one', 'two']); + expect(window.editor.state.doc.toString()).toBe(`${text}\n| one | two |\n\n`); + }); + + test('reveals source for a secondary caret on the next blank line and reuses the render on leaving', async () => { + const render = vi.spyOn(renderer, 'renderTableBlocks'); + setUp(); + await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); + + window.editor.dispatch({selection: EditorSelection.create([EditorSelection.cursor(table.length + 1), EditorSelection.cursor(source.length)], 1)}); + expect(widget()).toBeNull(); + + window.editor.dispatch({ selection: { anchor: source.length } }); + await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); + + expect(render).toHaveBeenCalledTimes(1); + expect(window.editor.state.doc.toString()).toBe(source); + }); + test('does not leave an empty source line before a rendered table', async () => { setUp(); await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); @@ -143,7 +186,7 @@ describe('Hidden tables', () => { test.each(['ArrowRight', 'ArrowLeft'])('%s reveals source at the table boundary', async key => { const prefix = 'Before\n\n'; - const text = `${prefix}${source}`; + const text = `${prefix}${table}\n# After\n\n[target]: https://example.com`; editor.setUp(text, [hiddenSyntaxExtension, keymap.of(standardKeymap)]); const boundary = key === 'ArrowRight' ? prefix.length : prefix.length + table.length; @@ -170,7 +213,7 @@ describe('Hidden tables', () => { const forward = key === 'ArrowDown'; const start = forward ? before : after; const target = forward ? after : before; - window.editor.dispatch({ selection: { anchor: start } }); + window.editor.dispatch({ selection: EditorSelection.create([EditorSelection.cursor(start, 0, undefined, 24)]) }); await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); const rendered = renderedTable(); @@ -210,6 +253,23 @@ describe('Hidden tables', () => { expect(window.editor.state.doc.toString()).toBe(source); }); + test.each(['ArrowLeft', 'ArrowRight', 'typing'])('reveals source on %s after vertical arrival at the next blank line', async action => { + const text = `${table}\n \nAfter\n\n[target]: https://example.com`; + editor.setUp(text, [hiddenSyntaxExtension, keymap.of(standardKeymap)]); + const start = table.length + 2; + window.editor.dispatch({ selection: EditorSelection.create([EditorSelection.cursor(start, 0, undefined, 24)]) }); + await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); + + if (action === 'typing') { + window.editor.dispatch(window.editor.state.replaceSelection(' '), { userEvent: 'input.type' }); + } else { + expect(runScopeHandlers(window.editor, new KeyboardEvent('keydown', { key: action }), 'editor')).toBe(true); + } + + expect(window.editor.state.selection.main.goalColumn).toBeUndefined(); + expect(widget()).toBeNull(); + }); + test('reuses a pending render when source is revealed and restored', async () => { let finish: (tables: Awaited>) => void = () => {}; const pending = new Promise>>(resolve => { finish = resolve; }); @@ -327,6 +387,29 @@ describe('Hidden tables', () => { await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); }); + test.each([undefined, 24])('preserves an explicit fold beside a blank-line caret with goal column %s', async goal => { + setUp(); + const range = { from: window.editor.state.doc.line(1).to, to: table.length }; + window.editor.dispatch({ effects: foldEffect.of(range) }); + window.editor.dispatch({ selection: EditorSelection.create([ + EditorSelection.cursor(table.length + 1, 0, undefined, goal), + ]) }); + + expect(widget()).toBeNull(); + expect(window.editor.dom.querySelector('.cm-foldPlaceholder')).not.toBeNull(); + expect(foldedRanges(window.editor.state).size).toBe(1); + + window.editor.dispatch(window.editor.state.replaceSelection(' '), { userEvent: 'input.type' }); + expect(widget()).toBeNull(); + expect(window.editor.dom.querySelector('.cm-foldPlaceholder')).not.toBeNull(); + expect(foldedRanges(window.editor.state).size).toBe(1); + + window.editor.dispatch({ selection: { anchor: window.editor.state.doc.length } }); + expect(widget()).toBeNull(); + window.editor.dispatch({ effects: unfoldEffect.of(range) }); + await vi.waitFor(() => expect(renderedTable()).toBeTruthy()); + }); + test.each([false, true])('falls back at the current position after a pending render fails, rejected: %s', async rejected => { let finish: () => void = () => {}; const pending = new Promise>>((resolve, reject) => {