ts-highlight 2.0.0 → 2.3.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.
- package/README.md +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -32,8 +32,8 @@ const cssClasses: HiglightCSSClasses = {
|
|
|
32
32
|
keyword: 'keyword',
|
|
33
33
|
|
|
34
34
|
bigintChar: 'bigint-class', // class of bigint character (`10n` - `n` is `bigintChar`)
|
|
35
|
-
stringLiteral: 'string',
|
|
36
35
|
|
|
36
|
+
string: 'string',
|
|
37
37
|
whitespace: 'whitespace', // even whitespace has its own class
|
|
38
38
|
|
|
39
39
|
...
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ type HighlightCSSClasses = Partial<{
|
|
|
64
64
|
}>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
+
*
|
|
67
68
|
*
|
|
68
69
|
* Transforms received `source` string to HTML with higlighted source code.
|
|
69
70
|
*
|
|
@@ -75,7 +76,8 @@ type HighlightCSSClasses = Partial<{
|
|
|
75
76
|
* @returns {string} string with HTML of highlighted code.
|
|
76
77
|
*
|
|
77
78
|
* @example
|
|
78
|
-
*
|
|
79
|
+
*
|
|
80
|
+
* ```typescripts
|
|
79
81
|
* const cssClasses: HighlightCSSClasses = {
|
|
80
82
|
* pre: 'pre-element-class second-class',
|
|
81
83
|
* code: 'my-code-element-class',
|
|
@@ -104,7 +106,7 @@ type HighlightCSSClasses = Partial<{
|
|
|
104
106
|
* </pre>
|
|
105
107
|
* ```
|
|
106
108
|
*/
|
|
107
|
-
declare const highlight: (source: string, cssClasses
|
|
109
|
+
declare const highlight: (source: string, cssClasses?: HighlightCSSClasses) => string;
|
|
108
110
|
|
|
109
111
|
export { highlight };
|
|
110
112
|
export type { HighlightCSSClasses };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new Set(["=","+","-","*","/","%","~","^",".",":","|","&","?","!","<",">","{","}","[","]","(",")",";",","]),t=new Set(["==","!=","<=",">=","++","--","**","*=","/=","%=","^=","&=","|=","&&","||","??"]),n=new Set(["===","!==","**=","<<=",">>=",">>>","&&=","||=","??="]),
|
|
1
|
+
const e=new Set(["=","+","-","*","/","%","~","^",".",":","|","&","?","!","<",">","{","}","[","]","(",")",";",","]),t=new Set(["==","!=","<=",">=","++","--","**","*=","/=","%=","^=","&=","|=","&&","||","??"]),n=new Set(["===","!==","**=","<<=",">>=",">>>","&&=","||=","??="]),o={NaN:"NaNLiteral",false:"BooleanLiteral",true:"BooleanLiteral",null:"NullLiteral",undefined:"UndefinedLiteral",abstract:"Keyword",class:"Keyword",const:"Keyword",declare:"Keyword",enum:"Keyword",function:"Keyword",implements:"Keyword",in:"Keyword",instanceof:"Keyword",interface:"Keyword",keyof:"Keyword",let:"Keyword",new:"Keyword",this:"Keyword",type:"Keyword",typeof:"Keyword",var:"Keyword",void:"Keyword",debugger:"Keyword",as:"Instruction",assert:"Instruction",asserts:"Instruction",async:"Instruction",await:"Instruction",break:"Instruction",catch:"Instruction",continue:"Instruction",default:"Instruction",delete:"Instruction",do:"Instruction",export:"Instruction",finally:"Instruction",for:"Instruction",from:"Instruction",import:"Instruction",is:"Instruction",package:"Instruction",return:"Instruction",throw:"Instruction",try:"Instruction",while:"Instruction",with:"Instruction",yield:"Instruction"},r=/^[a-zA-Zа-яА-Я_$]$/,i=/^[a-zA-Zа-яА-Я_$0-9]$/,s=/^[0-9]$/,a='<span class="',l="</span>",c=(c,u)=>((e,t)=>{const n=e.length;let o='<pre class="'+t.pre+'"><code class="'+t.code+'"><div class="'+t.line+'">',r=0;for(;r<n;){const i=e[r];"WhiteSpace"!==i.type?"LineDivision"!==i.type?"Operator"!==i.type?"Identifier"!==i.type?"Keyword"!==i.type?"Instruction"!==i.type?"StringLiteral"!==i.type?"NumberLiteral"!==i.type?"BooleanLiteral"!==i.type?"NaNLiteral"!==i.type?"UndefinedLiteral"!==i.type?"NullLiteral"!==i.type?("Comment"!==i.type||(o+=a+t.token+" "+t.comment+'">'+i.value+l),r++):(o+=a+t.token+" "+t.null+'">'+i.value+l,r++):(o+=a+t.token+" "+t.undefined+'">'+i.value+l,r++):(o+=a+t.token+" "+t.NaN+'">'+i.value+l,r++):(o+=a+t.token+" "+t.boolean+'">'+i.value+l,r++):(o+=a+t.token+" "+t.number+'">'+i.value,r++,"n"===e[r].value&&(o+=l+a+t.token+" "+t.bigintChar+'">'+e[r].value,r++),o+=l):(o+=a+t.token+" "+t.string+'">'+i.value+l,r++):(o+=a+t.token+" "+t.instruction+'">'+i.value+l,r++):(o+=a+t.token+" "+t.keyword+'">'+i.value+l,r++):(o+=a+t.token+" "+t.mutableIdentifier+'">'+i.value+l,r++):(o+=a+t.token+" "+t.operator+'">'+i.value+l,r++):(o+=" </div>",o+='<div class="'+t.line+'">',r===n-1&&(o+=" </div>"),r++):(o+=a+t.token+" "+t.whitespace+'">'+i.value+l,r++)}return o+="</div></code></pre>",o})((a=>{const l=[],c=a.length;let u=0;e:for(;u<c;){if(" "===a[u]||"\t"===a[u]){const e=u;for(u++;u<c&&(" "===a[u]||"\t"===a[u]);)u++;l[l.length]={type:"WhiteSpace",value:a.slice(e,u),start:e,end:u};continue e}if("\n"===a[u]||"\r"===a[u]){const e=u;"\r"===a[u]&&u++,u++,l[l.length]={type:"LineDivision",value:"",start:e,end:u};continue e}if(r.test(a[u])){const e=u;for(u++;u<c&&i.test(a[u]);)u++;const t=a.slice(e,u);l[l.length]={type:o[t]??"Identifier",value:t,start:e,end:u};continue e}if("'"===a[u]||'"'===a[u]||"`"===a[u]){const e=u,t=a[u];for(u++;u<c&&a[u]!==t;)u++;u++,l[l.length]={type:"StringLiteral",value:a.slice(e,u),start:e,end:u};continue e}if(s.test(a[u])){const e=u;for(;u<c&&s.test(a[u]);)u++;l[l.length]={type:"NumberLiteral",value:a.slice(e,u),start:e,end:u};continue e}if("/"===a[u]){const e=u;if(u++,"/"===a[u]){for(u++;u<c&&"\r"!==a[u]&&"\n"!==a[u];)u++;"\r"===a[u]&&(u+=2),l[l.length]={type:"Comment",value:a.slice(e,u),start:e,end:u},l[l.length]={type:"LineDivision",value:"\n",start:e,end:u};continue e}if("*"===a[u]){u++;let t=e;for(;u<c&&("*"!==a[u]||"/"!==a[u+1]);)"\n"!==a[u]&&"\r"!==a[u]||(l[l.length]={type:"Comment",value:a.slice(t,u),start:e,end:u},l[l.length]={type:"LineDivision",value:"\n",start:u,end:u+1},"\r"===a[u]&&u++,u++,t=u),u++;u+=2,l[l.length]={type:"Comment",value:a.slice(t,u),start:e,end:u};continue e}}if(a[u]+a[u+1]+a[u+2]+a[u+3]===">>>="){const e=u;u+=4,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(n.has(a[u]+a[u+1]+a[u+2])){const e=u;u+=3,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(t.has(a[u]+a[u+1])){const e=u;u+=2,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}if(e.has(a[u])){const e=u;u++,l[l.length]={type:"Operator",value:a.slice(e,u),start:e,end:u};continue e}u++}return l})(c),u||{});export{c as highlight};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-highlight",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"module": "./dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -49,8 +49,7 @@
|
|
|
49
49
|
"rollup": "^4.54.0",
|
|
50
50
|
"rollup-plugin-dts": "^6.3.0",
|
|
51
51
|
"rollup-plugin-postcss": "^4.0.2",
|
|
52
|
-
"tslib": "^2.8.1"
|
|
53
|
-
"typescript-plugin-css-modules": "^5.2.0"
|
|
52
|
+
"tslib": "^2.8.1"
|
|
54
53
|
},
|
|
55
54
|
"peerDependencies": {
|
|
56
55
|
"typescript": "^5"
|