PageSourceSearch

https://pika.page/assets/@tiptap--extension-code-block-1d5198888aa…fcec9bf82eb477b0a65e71c7b56aa7c49884b6bb.js

js pika.page collected 2026-10-03 21:39:07 UTC 5,128 bytes, 19 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,textblockTypeInputRule as t,mergeAttributes as n}from"@tiptap/core";import{Plugin as r,TextSelection as i,PluginKey as a,Selection as o}from"@tiptap/pm/state";const s=4,c=/^```([a-z]+)?[\s\n]$/,l=/^~~~([a-z]+)?[\s\n]$/,u=e.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,exitOnArrowUp:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:4,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{var t;let{languageClassPrefix:n}=this.options;return n&&[...((t=e.firstElementChild)==null?void 0:t.classList)||[]].filter(e=>e.startsWith(n)).map(e=>e.replace(n,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,n(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>{var n,r;return((n=e.raw)==null?void 0:n.startsWith("```"))===!1&&((r=e.raw)==null?void 0:r.startsWith(`~~~`))===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[])},renderMarkdown:(e,t)=>{var n;let r=``,i=((n=e.attrs)==null?void 0:n.language)||``;return r=e.content?[`\`\`\`${i}`,t.renderChildren(e.content),"```"].join(`
4`):`\`\`\`${i}\n\n\`\`\``,r},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{var t;if(!this.options.enableTabIndentation)return!1;let n=(t=this.options.tabSize)==null?4:t,{state:r}=e,{selection:i}=r,{$from:a,empty:o}=i;if(a.parent.type!==this.type)return!1;let s=` `.repeat(n);return o?e.commands.insertContent(s):e.commands.command(({tr:e})=>{let{from:t,to:n}=i,a=r.doc.textBetween(t,n,`
5`,`
6`).split(`
7`).map(e=>s+e).join(`
8`);return e.replaceWith(t,n,r.schema.text(a)),!0})},"Shift-Tab":({editor:e})=>{var t;if(!this.options.enableTabIndentation)return!1;let n=(t=this.options.tabSize)==null?4:t,{state:r}=e,{selection:a}=r,{$from:o,empty:s}=a;return o.parent.type===this.type?s?e.commands.command(({tr:e})=>{var t;let{pos:a}=o,s=o.start(),c=o.end(),l=r.doc.textBetween(s,c,`
9`,`
10`).split(`
11`),u=0,d=0,f=a-s;for(let e=0;e<l.length;e+=1){if(d+l[e].length>=f){u=e;break}d+=l[e].length+1}let p=((t=l[u].match(/^ */))==null?void 0:t[0])||``,m=Math.min(p.length,n);if(m===0)return!0;let h=s;for(let e=0;e<u;e+=1)h+=l[e].length+1;return e.delete(h,h+m),a-h<=m&&e.setSelection(i.create(e.doc,h)),!0}):e.commands.command(({tr:e})=>{let{from:t,to:i}=a,o=r.doc.textBetween(t,i,`
12`,`
13`).split(`
14`).map(e=>{var t;let r=((t=e.match(/^ */))==null?void 0:t[0])||``,i=Math.min(r.length,n);return e.slice(i)}).join(`
15`);return e.replaceWith(t,i,r.schema.text(o)),!0}):!1},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;let a=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(`
16
17`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowUp:({editor:e})=>{if(!this.options.exitOnArrowUp)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type||r.parentOffset!==0)return!1;let a=r.before();return a>0?!1:e.commands.insertDefaultBlock({pos:a})},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let s=i.after();return s===void 0?!1:r.nodeAt(s)?e.commands.command(({tr:e})=>(e.setSelection(o.near(r.resolve(s))),!0)):e.commands.exitCode()}}}
17,addInputRules(){return[t({find:c,type:this.type,getAttributes:e=>({language:e[1]})}),t({find:l,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new r({key:new a(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),a=r?JSON.parse(r):void 0,o=a==null?void 0:a.mode;if(!n||!o)return!1;let{tr:s,schema:c}=e.state,l=c.text(n.replace(/\r\n?/g,`
18`));return s.replaceSelectionWith(this.type.create({language:o},l)),s.selection.$from.parent.type!==this.type&&s.setSelection(i.near(s.doc.resolve(Math.max(0,s.selection.from-2)))),s.setMeta(`paste`,!0),e.dispatch(s),!0}}})]}});var d=u;export{u as CodeBlock,c as backtickInputRegex,d as default,l as tildeInputRegex};
19

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.