sugar-high 0.9.2 → 0.9.4
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 +2 -3
- package/lib/index.js +25 -21
- package/package.json +8 -19
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Sugar High
|
|
2
2
|
|
|
3
3
|
[![Build][build-badge]][build]
|
|
4
|
-
[![Coverage][coverage-badge]][coverage]
|
|
5
4
|
|
|
6
5
|
### Introduction
|
|
7
6
|
|
|
@@ -98,9 +97,9 @@ You can use `.sh__token--<token type>` to customize the output node of each toke
|
|
|
98
97
|
|
|
99
98
|
### Use With Remark.js
|
|
100
99
|
|
|
101
|
-
[Remark.js](https://remark.js.org/) is a powerful markdown processor, you can use the [sugar-high remark plugin](https://
|
|
100
|
+
[Remark.js](https://remark.js.org/) is a powerful markdown processor, you can use the [sugar-high remark plugin](https://sugar-high.vercel.app/remark) with remark.js to highlight code blocks in markdown.
|
|
102
101
|
|
|
103
|
-
Check out the [
|
|
102
|
+
Check out the [readme](https://github.com/huozhi/sugar-high/tree/main/packages/remark-sugar-high) for more details.
|
|
104
103
|
|
|
105
104
|
### LICENSE
|
|
106
105
|
|
package/lib/index.js
CHANGED
|
@@ -275,7 +275,7 @@ function tokenize(code, options) {
|
|
|
275
275
|
if (isJsxLiterals) return T_JSX_LITERALS
|
|
276
276
|
|
|
277
277
|
// Determine strings first before other types
|
|
278
|
-
if (inStringQuotes()) {
|
|
278
|
+
if (inStringQuotes() || inStrTemplateLiterals()) {
|
|
279
279
|
return T_STRING
|
|
280
280
|
} else if (keywords.has(token)) {
|
|
281
281
|
return last[1] === '.' ? T_IDENTIFIER : T_KEYWORD
|
|
@@ -304,9 +304,6 @@ function tokenize(code, options) {
|
|
|
304
304
|
* @param {string} token_
|
|
305
305
|
*/
|
|
306
306
|
const append = (type_, token_) => {
|
|
307
|
-
if (type_ || token_) {
|
|
308
|
-
const nType = TokenTypes[type_]
|
|
309
|
-
}
|
|
310
307
|
if (token_) {
|
|
311
308
|
current = token_
|
|
312
309
|
}
|
|
@@ -329,9 +326,9 @@ function tokenize(code, options) {
|
|
|
329
326
|
const p_c = prev + curr // previous and current
|
|
330
327
|
const c_n = curr + next // current and next
|
|
331
328
|
|
|
332
|
-
// Determine string quotation outside of jsx literals.
|
|
333
|
-
// Inside jsx literals, string quotation is still part of it.
|
|
334
|
-
if (isSingleQuotes(curr) && !inJsxLiterals()) {
|
|
329
|
+
// Determine string quotation outside of jsx literals and template literals.
|
|
330
|
+
// Inside jsx literals or template literals, string quotation is still part of it.
|
|
331
|
+
if (isSingleQuotes(curr) && !inJsxLiterals() && !inStrTemplateLiterals()) {
|
|
335
332
|
append()
|
|
336
333
|
if (prev !== `\\`) {
|
|
337
334
|
if (__strQuote && curr === __strQuote) {
|
|
@@ -460,26 +457,26 @@ function tokenize(code, options) {
|
|
|
460
457
|
if (next === '-' && !inStringContent() && !inJsxLiterals()) {
|
|
461
458
|
if (current) {
|
|
462
459
|
append(T_PROPERTY, current + curr + next)
|
|
463
|
-
i
|
|
460
|
+
i++
|
|
464
461
|
continue
|
|
465
462
|
}
|
|
466
463
|
}
|
|
467
464
|
// `=` in property=<value>
|
|
468
465
|
if (next === '=' && !inStringContent()) {
|
|
469
466
|
// if current is not a space, ensure `prop` is a property
|
|
470
|
-
if (isSpaces(
|
|
471
|
-
|
|
472
|
-
current
|
|
467
|
+
if (!isSpaces(curr)) {
|
|
468
|
+
// If there're leading spaces, append them first
|
|
469
|
+
if (isSpaces(current)) {
|
|
470
|
+
append()
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Now check if the accumulated token is a property
|
|
474
|
+
const prop = current + curr
|
|
475
|
+
if (isIdentifier(prop)) {
|
|
476
|
+
append(T_PROPERTY, prop)
|
|
477
|
+
continue
|
|
478
|
+
}
|
|
473
479
|
}
|
|
474
|
-
const prop = current ? (current + curr) : curr
|
|
475
|
-
if (isIdentifier(prop)) {
|
|
476
|
-
current = prop
|
|
477
|
-
append(T_PROPERTY)
|
|
478
|
-
} else if (prop === ' ') {
|
|
479
|
-
current = prop
|
|
480
|
-
append(T_SPACE)
|
|
481
|
-
}
|
|
482
|
-
continue
|
|
483
480
|
}
|
|
484
481
|
}
|
|
485
482
|
}
|
|
@@ -602,6 +599,8 @@ function tokenize(code, options) {
|
|
|
602
599
|
} else if (
|
|
603
600
|
// it's jsx literals and is not a jsx bracket
|
|
604
601
|
(isJsxLiterals && !JSXBrackets.has(curr)) ||
|
|
602
|
+
// it's template literal content (including quotes)
|
|
603
|
+
inStrTemplateLiterals() ||
|
|
605
604
|
// same type char as previous one in current token
|
|
606
605
|
((isWord(curr) === isWord(current[current.length - 1]) || __jsxChild()) && !Signs.has(curr))
|
|
607
606
|
) {
|
|
@@ -740,7 +739,12 @@ function toHtml(lines) {
|
|
|
740
739
|
/**
|
|
741
740
|
*
|
|
742
741
|
* @param {string} code
|
|
743
|
-
* @param {
|
|
742
|
+
* @param {
|
|
743
|
+
* {
|
|
744
|
+
* keywords: Set<string>
|
|
745
|
+
* onCommentStart?: (curr: string, next: string) => number | boolean
|
|
746
|
+
* onCommentEnd?: (curr: string, prev: string) => number | boolean
|
|
747
|
+
* } | undefined} options
|
|
744
748
|
* @returns {string}
|
|
745
749
|
*/
|
|
746
750
|
function highlight(code, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sugar-high",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -19,25 +19,14 @@
|
|
|
19
19
|
"lib"
|
|
20
20
|
],
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "vitest",
|
|
24
|
-
"dev": "next dev docs",
|
|
25
|
-
"build": "next build docs"
|
|
26
|
-
},
|
|
27
22
|
"devDependencies": {
|
|
28
|
-
"@types/node": "22.
|
|
29
|
-
"@types/react": "19.0.7",
|
|
30
|
-
"codice": "^1.0.0",
|
|
31
|
-
"dom-to-image": "^2.6.0",
|
|
32
|
-
"next": "15.1.5",
|
|
33
|
-
"react": "^19.0.0",
|
|
34
|
-
"react-dom": "^19.0.0",
|
|
35
|
-
"sugar-high": "link:./",
|
|
23
|
+
"@types/node": "22.12.0",
|
|
36
24
|
"typescript": "5.7.3",
|
|
37
25
|
"vitest": "^3.0.2"
|
|
38
26
|
},
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
27
|
+
"packageManager": "pnpm@8.7.1",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"build": "echo 'package requires no build'"
|
|
31
|
+
}
|
|
32
|
+
}
|