sugar-high 0.8.0 → 0.8.1
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/lib/index.d.ts +2 -1
- package/lib/index.js +13 -4
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type HighlightOptions = {
|
|
2
2
|
keywords?: Set<string>
|
|
3
|
-
onCommentStart?: (curr: string, next: string) => boolean
|
|
3
|
+
onCommentStart?: (curr: string, next: string) => number | boolean
|
|
4
|
+
onCommentEnd?: (curr: string, prev: string) => number | boolean
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
export function highlight(code: string, options?: HighlightOptions): string
|
package/lib/index.js
CHANGED
|
@@ -79,6 +79,7 @@ const Signs = new Set([
|
|
|
79
79
|
const DefaultOptions = {
|
|
80
80
|
keywords: Keywords_Js,
|
|
81
81
|
onCommentStart: isCommentStart_Js,
|
|
82
|
+
onCommentEnd: isCommentEnd_Js,
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/**
|
|
@@ -184,6 +185,10 @@ function isCommentStart_Js(curr, next) {
|
|
|
184
185
|
return str === '//' || str === '/*'
|
|
185
186
|
}
|
|
186
187
|
|
|
188
|
+
function isCommentEnd_Js(prev, curr) {
|
|
189
|
+
return curr === '\n' || (prev + curr) === '*/'
|
|
190
|
+
}
|
|
191
|
+
|
|
187
192
|
function isRegexStart(str) {
|
|
188
193
|
return str[0] === '/' && !isCommentStart_Js(str[0], str[1])
|
|
189
194
|
}
|
|
@@ -197,6 +202,7 @@ function tokenize(code, options) {
|
|
|
197
202
|
const {
|
|
198
203
|
keywords,
|
|
199
204
|
onCommentStart,
|
|
205
|
+
onCommentEnd,
|
|
200
206
|
} = { ...DefaultOptions, ...options }
|
|
201
207
|
|
|
202
208
|
let current = ''
|
|
@@ -549,10 +555,13 @@ function tokenize(code, options) {
|
|
|
549
555
|
} else if (onCommentStart(curr, next)) {
|
|
550
556
|
append()
|
|
551
557
|
const start = i
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
558
|
+
const commentType = onCommentStart(curr, next)
|
|
559
|
+
|
|
560
|
+
// just match the comment, commentType === true
|
|
561
|
+
// inline comment, commentType === 1
|
|
562
|
+
// block comment, commentType === 2
|
|
563
|
+
if (commentType) {
|
|
564
|
+
for (; i < code.length && !onCommentEnd(code[i - 1], code[i]); i++);
|
|
556
565
|
}
|
|
557
566
|
current = code.slice(start, i + 1)
|
|
558
567
|
append(T_COMMENT)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sugar-high",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"codice": "^0.2.0",
|
|
22
|
-
"next": "15.
|
|
23
|
-
"react": "^
|
|
24
|
-
"react-dom": "^
|
|
22
|
+
"next": "15.1.3",
|
|
23
|
+
"react": "^19.0.0",
|
|
24
|
+
"react-dom": "^19.0.0",
|
|
25
25
|
"sugar-high": "link:./",
|
|
26
26
|
"vitest": "^2.1.3"
|
|
27
27
|
},
|