@lexical/code-prism 0.51.0 → 0.51.1-nightly.20260921.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$createCodeHighlightNode as e,DEFAULT_CODE_LANGUAGE as t,$plainifyCodeContent as n,$isCodeNode as r,$isCodeHighlightNode as i,CodeNode as o,CodeHighlightNode as s,registerCodeIndentation as a,CodeExtension as c,CodeIndentExtension as l}from"@lexical/code-core";import{effect as p}from"@lexical/extension/signals";import{namedSignals as g}from"@lexical/extension/namedSignals";import{tokenizeRawText as u,$createTabNode as f,$createLineBreakNode as d,$createTextNode as m,$isLineBreakNode as h,$onUpdate as y,$getNodeByKey as j,$getSelection as x,$isRangeSelection as b,$isTextNode as k,$isTabNode as w,TextNode as v,mergeRegister as S}from"lexical";import"prismjs";import"prismjs/components/prism-clike.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-markdown.js";import"prismjs/components/prism-c.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-objectivec.js";import"prismjs/components/prism-sql.js";import"prismjs/components/prism-powershell.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-swift.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-cpp.js";!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism),Prism.languages.go=Prism.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),Prism.languages.insertBefore("go","string",{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete Prism.languages.go["class-name"];const _=globalThis.Prism||window.Prism,C={c:"C",clike:"C-like",cpp:"C++",css:"CSS",go:"Go",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},P={cpp:"cpp",golang:"go",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function T(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function L(e){return T(P,e)||e}function A(e){const t=L(e);return T(C,t)||t}const z=()=>Object.keys(_.languages).filter(e=>"function"!=typeof _.languages[e]).sort();function H(){const e=[];for(const[t,n]of Object.entries(C))e.push([t,n]);return e}function I(){return[]}function O(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&_.languages.hasOwnProperty(n)}catch
|
|
9
|
+
import{$createCodeHighlightNode as e,DEFAULT_CODE_LANGUAGE as t,$plainifyCodeContent as n,$isCodeNode as r,$isCodeHighlightNode as i,CodeNode as o,CodeHighlightNode as s,registerCodeIndentation as a,CodeExtension as c,CodeIndentExtension as l}from"@lexical/code-core";import{effect as p}from"@lexical/extension/signals";import{namedSignals as g}from"@lexical/extension/namedSignals";import{tokenizeRawText as u,$createTabNode as f,$createLineBreakNode as d,$createTextNode as m,$isLineBreakNode as h,$onUpdate as y,$getNodeByKey as j,$getSelection as x,$isRangeSelection as b,$isTextNode as k,$isTabNode as w,TextNode as v,mergeRegister as S}from"lexical";import"prismjs";import"prismjs/components/prism-clike.js";import"prismjs/components/prism-javascript.js";import"prismjs/components/prism-markup.js";import"prismjs/components/prism-markdown.js";import"prismjs/components/prism-c.js";import"prismjs/components/prism-css.js";import"prismjs/components/prism-objectivec.js";import"prismjs/components/prism-sql.js";import"prismjs/components/prism-powershell.js";import"prismjs/components/prism-python.js";import"prismjs/components/prism-rust.js";import"prismjs/components/prism-swift.js";import"prismjs/components/prism-typescript.js";import"prismjs/components/prism-java.js";import"prismjs/components/prism-cpp.js";!function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(t).forEach(function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),"diff"===n&&i.push("bold"),e.languages.diff[n]={pattern:RegExp("^(?:["+r+"].*(?:\r\n?|\n|(?![\\s\\S])))+","m"),alias:i,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(n)[0]}}}}),Object.defineProperty(e.languages.diff,"PREFIXES",{value:t})}(Prism),Prism.languages.go=Prism.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),Prism.languages.insertBefore("go","string",{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete Prism.languages.go["class-name"];const _=globalThis.Prism||window.Prism,C={c:"C",clike:"C-like",cpp:"C++",css:"CSS",go:"Go",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},P={cpp:"cpp",golang:"go",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function T(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function L(e){return T(P,e)||e}function A(e){const t=L(e);return T(C,t)||t}const z=()=>Object.keys(_.languages).filter(e=>"function"!=typeof _.languages[e]).sort();function H(){const e=[];for(const[t,n]of Object.entries(C))e.push([t,n]);return e}function I(){return[]}function O(e){const t=function(e){const t=/^diff-([\w-]+)/i.exec(e);return t?t[1]:null}(e),n=t||e;try{return!!n&&_.languages.hasOwnProperty(n)}catch{return!1}}async function E(e,t,n){}function N(e){return"string"==typeof e?e:Array.isArray(e)?e.map(N).join(""):N(e.content)}function $(e,t){const n=/^diff-([\w-]+)/i.exec(t),r=e.getTextContent();let i=_.tokenize(r,_.languages[n?"diff":t]);return n&&(i=function(e,t){const n=t,r=_.languages[n],i={tokens:e},o=_.languages.diff.PREFIXES;for(const e of i.tokens){if("string"==typeof e||!(e.type in o)||!Array.isArray(e.content))continue;const t=e.type;let n=0;const i=()=>(n++,new _.Token("prefix",o[t],t.replace(/^(\w+).*/,"$1"))),s=e.content.filter(e=>"string"==typeof e||"prefix"!==e.type),a=e.content.length-s.length,c=_.tokenize(N(s),r);c.unshift(i());const l=/\r\n|\n/g,p=e=>{const t=[];l.lastIndex=0;let r,o=0;for(;n<a&&(r=l.exec(e));){const n=r.index+r[0].length;t.push(e.slice(o,n)),o=n,t.push(i())}if(0!==t.length)return o<e.length&&t.push(e.slice(o)),t},g=e=>{for(let t=0;t<e.length&&n<a;t++){const n=e[t];if("string"==typeof n){const r=p(n);r&&(e.splice(t,1,...r),t+=r.length-1)}else if("string"==typeof n.content){const e=p(n.content);e&&(n.content=e)}else Array.isArray(n.content)?g(n.content):g([n.content])}};g(c),n<a&&c.push(i()),e.content=c}return i.tokens}(i,n[1])),R(i)}function R(t,n){const r=[];for(const i of t)if("string"==typeof i)u(i,{linebreak:()=>r.push(d()),tab:()=>r.push(f()),text:t=>r.push(e(t,n))});else{const{content:e,alias:t}=i;"string"==typeof e?r.push(...R([e],"prefix"===i.type&&"string"==typeof t?t:i.type)):Array.isArray(e)&&r.push(...R(e,"unchanged"===i.type?void 0:i.type))}return r}const M={$tokenize(e,t){const r=t||this.defaultLanguage;return null===r?n(e.getTextContent()):$(e,r)},defaultLanguage:t,tokenize(e,t){const n=this.defaultLanguage;return _.tokenize(e,_.languages[t||""]||(null===n?void 0:_.languages[n]))}};function F(e,t,n,o){const s=o.getParent();r(s)?K(0,t,n,s):i(o)&&o.replace(m(o.__text))}function B(e,t){const n=t.getElementByKey(e.getKey());if(null===n)return;const r=e.getChildren(),i=r.length;if(i===n.__cachedChildrenLength)return;n.__cachedChildrenLength=i;let o="1",s=1;for(let e=0;e<i;e++)h(r[e])&&(o+="\n"+ ++s);n.setAttribute("data-gutter",o)}function K(e,t,n,i){const{nodesCurrentlyHighlighting:o}=n,s=i.getKey();void 0===i.getLanguage()&&null!==t.defaultLanguage&&i.setLanguage(t.defaultLanguage);const a=i.getLanguage()||t.defaultLanguage;if(a){if(!O(a))return i.getIsSyntaxHighlightSupported()&&i.setIsSyntaxHighlightSupported(!1),void E();i.getIsSyntaxHighlightSupported()||i.setIsSyntaxHighlightSupported(!0)}else i.getIsSyntaxHighlightSupported()&&i.setIsSyntaxHighlightSupported(!1);o.has(s)||(o.add(s),n.didTransform||(n.didTransform=!0,y(()=>{n.didTransform=!1,o.clear()})),function(e,t){const n=j(e);if(!r(n)||!n.isAttached())return;const i=x();if(!b(i))return void t();const o=i.anchor,s=o.getNode();if(s!==n&&!n.isParentOf(s))return void t();const a=o.offset,c="element"===o.type&&h(n.getChildAtIndex(o.offset-1));let l=0;if(c||(l=a+s.getPreviousSiblings().reduce((e,t)=>e+t.getTextContentSize(),0)),!t())return;if(c)return void o.getNode().select(a,a);const p=n.getChildren();for(let e=0;e<p.length;e++){const t=p[e];if(k(t)){const e=t.getTextContentSize();if(e>=l)return void t.select(l,l);l-=e}else if(h(t)){if(0===l)return void n.select(e,e);l-=1}}n.select(p.length,p.length)}(s,()=>{const e=j(s);if(!r(e)||!e.isAttached())return!1;const n=e.getLanguage()||t.defaultLanguage,o=t.$tokenize(e,n??void 0),a=function(e,t){let n=0;for(;n<e.length&&X(e[n],t[n]);)n++;const r=e.length,i=t.length,o=Math.min(r,i)-n;let s=0;for(;s<o;)if(s++,!X(e[r-s],t[i-s])){s--;break}const a=r-s;return{from:n,nodesForReplacement:t.slice(n,i-s),to:a}}(e.getChildren(),o),{from:c,to:l,nodesForReplacement:p}=a;return!(c===l&&!p.length||(i.splice(c,l-c,p),0))}))}function X(e,t){return i(e)&&i(t)&&e.__text===t.__text&&e.__highlightType===t.__highlightType||w(e)&&w(t)||h(e)&&h(t)}function q(e,t){const n=[];!0!==e._headless&&n.push(e.registerMutationListener(o,t=>{e.read("latest",()=>{for(const[n,r]of t)if("destroyed"!==r){const t=j(n);null!==t&&B(t,e)}})},{skipInitialization:!1}));const r={didTransform:!1,nodesCurrentlyHighlighting:new Set};return n.push(e.registerNodeTransform(o,K.bind(null,e,t,r)),e.registerNodeTransform(v,F.bind(null,e,t,r)),e.registerNodeTransform(s,F.bind(null,e,t,r))),S(...n)}function J(e,t=M){if(!e.hasNodes([o,s]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return S(q(e,t),a(e))}const G={build:(e,t)=>g(t),config:{disabled:!1,tokenizer:M},dependencies:[c,l],name:"@lexical/code-prism",register:(e,t,n)=>{const r=n.getOutput();return p(()=>{if(!r.disabled.value)return q(e,r.tokenizer.value)})}};export{C as CODE_LANGUAGE_FRIENDLY_NAME_MAP,P as CODE_LANGUAGE_MAP,G as CodePrismExtension,M as PrismTokenizer,H as getCodeLanguageOptions,z as getCodeLanguages,I as getCodeThemeOptions,A as getLanguageFriendlyName,O as isCodeLanguageLoaded,E as loadCodeLanguage,L as normalizeCodeLanguage,J as registerCodeHighlighting};
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.51.0",
|
|
11
|
+
"version": "0.51.1-nightly.20260921.0",
|
|
12
12
|
"main": "./dist/LexicalCodePrism.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/code-core": "0.51.0",
|
|
16
|
-
"@lexical/extension": "0.51.0",
|
|
17
|
-
"lexical": "0.51.0",
|
|
15
|
+
"@lexical/code-core": "0.51.1-nightly.20260921.0",
|
|
16
|
+
"@lexical/extension": "0.51.1-nightly.20260921.0",
|
|
17
|
+
"lexical": "0.51.1-nightly.20260921.0",
|
|
18
18
|
"prismjs": "^1.30.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|