sugar-high 0.8.0 → 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 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.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
  /**
@@ -179,9 +180,18 @@ function isStringQuotation(chr) {
179
180
  return isSingleQuotes(chr) || isStrTemplateChr(chr)
180
181
  }
181
182
 
183
+ /** @returns {0|1|2} */
182
184
  function isCommentStart_Js(curr, next) {
183
185
  const str = curr + next
184
- return str === '//' || str === '/*'
186
+ if (str === '/*') return 2
187
+ return str === '//' ? 1 : 0
188
+ }
189
+
190
+ /** @returns {0|1|2} */
191
+ function isCommentEnd_Js(prev, curr) {
192
+ return (prev + curr) === '*/'
193
+ ? 2
194
+ : curr === '\n' ? 1 : 0
185
195
  }
186
196
 
187
197
  function isRegexStart(str) {
@@ -197,6 +207,7 @@ function tokenize(code, options) {
197
207
  const {
198
208
  keywords,
199
209
  onCommentStart,
210
+ onCommentEnd,
200
211
  } = { ...DefaultOptions, ...options }
201
212
 
202
213
  let current = ''
@@ -464,9 +475,19 @@ function tokenize(code, options) {
464
475
  if (isIdentifier(prop)) {
465
476
  current = prop
466
477
  append(T_PROPERTY)
478
+ } else if (prop === ' ') {
479
+ current = prop
480
+ append(T_SPACE)
467
481
  }
468
482
  continue
469
483
  }
484
+
485
+ // if (curr === ' ' || isSign(curr)) {
486
+ // append()
487
+ // current = curr
488
+ // append()
489
+ // continue
490
+ // }
470
491
  }
471
492
  }
472
493
 
@@ -549,10 +570,16 @@ function tokenize(code, options) {
549
570
  } else if (onCommentStart(curr, next)) {
550
571
  append()
551
572
  const start = i
552
- if (next === '/') {
553
- for (; i < code.length && code[i] !== '\n'; i++);
554
- } else {
555
- for (; i < code.length && code[i - 1] + code[i] !== '*/'; i++);
573
+ const startCommentType = onCommentStart(curr, next)
574
+
575
+ // just match the comment, commentType === true
576
+ // inline comment, commentType === 1
577
+ // block comment, commentType === 2
578
+ if (startCommentType) {
579
+ for (; i < code.length; i++) {
580
+ const endCommentType = onCommentEnd(code[i - 1], code[i])
581
+ if (endCommentType == startCommentType) break
582
+ }
556
583
  }
557
584
  current = code.slice(start, i + 1)
558
585
  append(T_COMMENT)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.8.0",
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
- "codice": "^0.2.0",
22
- "next": "15.0.1",
23
- "react": "^18.3.1",
24
- "react-dom": "^18.3.1",
21
+ "@types/node": "22.10.7",
22
+ "@types/react": "19.0.7",
23
+ "codice": "^0.4.2",
24
+ "next": "15.1.5",
25
+ "react": "^19.0.0",
26
+ "react-dom": "^19.0.0",
25
27
  "sugar-high": "link:./",
26
- "vitest": "^2.1.3"
28
+ "typescript": "5.7.3",
29
+ "vitest": "^3.0.2"
27
30
  },
28
31
  "packageManager": "pnpm@8.7.1"
29
32
  }