PageSourceSearch

https://pika.page/assets/@tiptap--extension-mathematics-abebb538a3…3d4ff6a0f3f94ef28cfb274eb686c2991ee87cd6.js

js pika.page collected 2026-10-03 21:42:15 UTC 6,043 bytes, 5 lines download raw bytes

1// @tiptap/[email protected] downloaded from https://ga.jspm.io/npm:@tiptap/[email protected]/dist/index.js
2
3import{Node as e,InputRule as t,mergeAttributes as n,Extension as r}from"@tiptap/core";import i from"katex";const a=e.create({name:`blockMath`,group:`block`,atom:!0,addOptions(){return{onClick:void 0,katexOptions:void 0}},addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertBlockMath:e=>({commands:t,editor:n})=>{let{latex:r,pos:i}=e;return r?t.insertContentAt(i==null?n.state.selection.from:i,{type:this.name,attrs:{latex:r}}):!1},deleteBlockMath:e=>({editor:t,tr:n})=>{var r;let i=(r=e==null?void 0:e.pos)==null?t.state.selection.$from.pos:r,a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.delete(i,i+a.nodeSize),!0)},updateBlockMath:e=>({editor:t,tr:n})=>{let r=e==null?void 0:e.latex,i=e==null?void 0:e.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r==null?a.attrs.latex:r}),!0)}}},parseHTML(){return[{tag:`div[data-type="block-math"]`}]},renderHTML({HTMLAttributes:e}){return[`div`,n(e,{"data-type":`block-math`})]},parseMarkdown:e=>({type:`blockMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>{var t;return[`$$`,((t=e.attrs)==null?void 0:t.latex)||``,`$$`].join(`
4`)},markdownTokenizer:{name:`blockMath`,level:`block`,start:e=>e.indexOf(`$$`),tokenize:e=>{let t=e.match(/^\$\$([^$]+)\$\$/);if(!t)return;let[n,r]=t;return{type:`blockMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new t({find:/^\$\$\$([^$]+)\$\$\$$/,handler:({state:e,range:t,match:n})=>{let[,r]=n,{tr:i}=e,a=e.doc.resolve(t.from),o=this.type.create({latex:r}),s=a.depth>
40&&a.parent.isTextblock&&t.from===a.start()&&t.to===a.end()&&a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),this.type)?{from:a.before(),to:a.after()}:t;i.replaceWith(s.from,s.to,o)}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`div`),a=document.createElement(`div`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),a.className=`block-math-inner`,r.dataset.type=`block-math`,r.setAttribute(`data-latex`,t.attrs.latex),r.appendChild(a);function o(){try{i.render(t.attrs.latex,a,e),r.classList.remove(`block-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`block-math-error`)}}let s=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,s),o(),{dom:r,destroy(){r.removeEventListener(`click`,s)}}}}}),o=e.create({name:`inlineMath`,group:`inline`,inline:!0,atom:!0,addOptions(){return{onClick:void 0,katexOptions:void 0}},addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertInlineMath:e=>({editor:t,tr:n})=>{var r;let i=e.latex,a=(r=e==null?void 0:e.pos)==null?t.state.selection.from:r;return i?(n.replaceWith(a,a,this.type.create({latex:i})),!0):!1},deleteInlineMath:e=>({editor:t,tr:n})=>{var r;let i=(r=e==null?void 0:e.pos)==null?t.state.selection.$from.pos:r,a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.delete(i,i+a.nodeSize),!0)},updateInlineMath:e=>({editor:t,tr:n})=>{let r=e==null?void 0:e.latex,i=e==null?void 0:e.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r}),!0)}}},parseHTML(){return[{tag:`span[data-type="inline-math"]`}]},renderHTML({HTMLAttributes:e}){return[`span`,n(e,{"data-type":`inline-math`})]},parseMarkdown:e=>({type:`inlineMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>{var t;return`$${((t=e.attrs)==null?void 0:t.latex)||``}$`},markdownTokenizer:{name:`inlineMath`,level:`inline`,start:e=>e.indexOf(`$`),tokenize:e=>{let t=e.match(/^\$([^$]+)\$(?!\$)/);if(!t)return;let[n,r]=t;return{type:`inlineMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new t({find:/(?<!\$)(\$\$([^$\n]+?)\$\$)(?!\$)/,handler:({state:e,range:t,match:n})=>{let r=n[2],{tr:i}=e,a=t.from,o=t.to;i.replaceWith(a,o,this.type.create({latex:r}))}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`span`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),r.dataset.type=`inline-math`,r.setAttribute(`data-latex`,t.attrs.latex);function a(){try{i.render(t.attrs.latex,r,e),r.classList.remove(`inline-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`inline-math-error`)}}let o=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,o),a(),{dom:r,destroy(){r.removeEventListener(`click`,o)}}}}}),s=r.create({name:`Mathematics`,addOptions(){return{inlineOptions:void 0,blockOptions:void 0,katexOptions:void 0}},addExtensions(){return[a.configure({...this.options.blockOptions,katexOptions:this.options.katexOptions}),o.configure({...this.options.inlineOptions,katexOptions:this.options.katexOptions})]}}),c=/\$(?!\d+\$)(.+?)\$(?!\d)/g;function l(e,t,n=c){return t.doc.descendants((r,i)=>{if(!r.isText||!r.text||!r.text.includes(`$`))return;let{text:a}=r,o=r.text.match(n);o&&o.forEach(n=>{let r=a.indexOf(n),o=r+n.length,s=t.mapping.map(i+r),c=t.doc.resolve(s),l=c.parent,u=c.index(),{inlineMath:d}=e.schema.nodes;l.canReplaceWith(u,u+1,d)&&t.replaceWith(t.mapping.map(i+r),t.mapping.map(i+o),d.create({latex:n.slice(1,-1)}))})}),t.setMeta(`addToHistory`,!1),t}function u(e,t=c){let n=l(e,e.state.tr,t);e.view.dispatch(n)}var d=s;export{a as BlockMath,o as InlineMath,s as Mathematics,l as createMathMigrateTransaction,d as default,c as mathMigrationRegex,u as migrateMathStrings};
5

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.