sugar-high 0.8.1 → 0.8.2
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 +6 -0
- package/lib/index.js +23 -5
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -96,6 +96,12 @@ You can use `.sh__token--<token type>` to customize the output node of each toke
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
### Use With Remark.js
|
|
100
|
+
|
|
101
|
+
[Remark.js](https://remark.js.org/) is a powerful markdown processor, you can use the [sugar-high remark plugin](https://remark-sugar-high.vercel.app/) with remark.js to highlight code blocks in markdown.
|
|
102
|
+
|
|
103
|
+
Check out the [documentation](https://remark-sugar-high.vercel.app/) for more details.
|
|
104
|
+
|
|
99
105
|
### LICENSE
|
|
100
106
|
|
|
101
107
|
MIT
|
package/lib/index.js
CHANGED
|
@@ -180,13 +180,18 @@ function isStringQuotation(chr) {
|
|
|
180
180
|
return isSingleQuotes(chr) || isStrTemplateChr(chr)
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/** @returns {0|1|2} */
|
|
183
184
|
function isCommentStart_Js(curr, next) {
|
|
184
185
|
const str = curr + next
|
|
185
|
-
|
|
186
|
+
if (str === '/*') return 2
|
|
187
|
+
return str === '//' ? 1 : 0
|
|
186
188
|
}
|
|
187
189
|
|
|
190
|
+
/** @returns {0|1|2} */
|
|
188
191
|
function isCommentEnd_Js(prev, curr) {
|
|
189
|
-
return
|
|
192
|
+
return (prev + curr) === '*/'
|
|
193
|
+
? 2
|
|
194
|
+
: curr === '\n' ? 1 : 0
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
function isRegexStart(str) {
|
|
@@ -470,9 +475,19 @@ function tokenize(code, options) {
|
|
|
470
475
|
if (isIdentifier(prop)) {
|
|
471
476
|
current = prop
|
|
472
477
|
append(T_PROPERTY)
|
|
478
|
+
} else if (prop === ' ') {
|
|
479
|
+
current = prop
|
|
480
|
+
append(T_SPACE)
|
|
473
481
|
}
|
|
474
482
|
continue
|
|
475
483
|
}
|
|
484
|
+
|
|
485
|
+
// if (curr === ' ' || isSign(curr)) {
|
|
486
|
+
// append()
|
|
487
|
+
// current = curr
|
|
488
|
+
// append()
|
|
489
|
+
// continue
|
|
490
|
+
// }
|
|
476
491
|
}
|
|
477
492
|
}
|
|
478
493
|
|
|
@@ -555,13 +570,16 @@ function tokenize(code, options) {
|
|
|
555
570
|
} else if (onCommentStart(curr, next)) {
|
|
556
571
|
append()
|
|
557
572
|
const start = i
|
|
558
|
-
const
|
|
573
|
+
const startCommentType = onCommentStart(curr, next)
|
|
559
574
|
|
|
560
575
|
// just match the comment, commentType === true
|
|
561
576
|
// inline comment, commentType === 1
|
|
562
577
|
// block comment, commentType === 2
|
|
563
|
-
if (
|
|
564
|
-
for (; i < code.length
|
|
578
|
+
if (startCommentType) {
|
|
579
|
+
for (; i < code.length; i++) {
|
|
580
|
+
const endCommentType = onCommentEnd(code[i - 1], code[i])
|
|
581
|
+
if (endCommentType == startCommentType) break
|
|
582
|
+
}
|
|
565
583
|
}
|
|
566
584
|
current = code.slice(start, i + 1)
|
|
567
585
|
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.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
"build": "next build docs"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"@types/node": "22.10.7",
|
|
22
|
+
"@types/react": "19.0.7",
|
|
23
|
+
"codice": "^0.4.2",
|
|
24
|
+
"next": "15.1.5",
|
|
23
25
|
"react": "^19.0.0",
|
|
24
26
|
"react-dom": "^19.0.0",
|
|
25
27
|
"sugar-high": "link:./",
|
|
26
|
-
"
|
|
28
|
+
"typescript": "5.7.3",
|
|
29
|
+
"vitest": "^3.0.2"
|
|
27
30
|
},
|
|
28
31
|
"packageManager": "pnpm@8.7.1"
|
|
29
32
|
}
|