sugar-high 0.4.7 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +10 -0
  2. package/lib/index.mjs +15 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -71,6 +71,16 @@ pre code {
71
71
  }
72
72
  ```
73
73
 
74
+ #### CSS Class Names
75
+
76
+ You can use `.sh__token--<token type>` to customize the output node of each token.
77
+
78
+ ```css
79
+ .sh__token--keyword {
80
+ background: #f47067;
81
+ }
82
+ ```
83
+
74
84
  ### LICENSE
75
85
 
76
86
  MIT
package/lib/index.mjs CHANGED
@@ -76,7 +76,7 @@ const signs = new Set([
76
76
  ...jsxBrackets,
77
77
  ])
78
78
 
79
- export const types = [
79
+ const types = [
80
80
  'identifier',
81
81
  'keyword',
82
82
  'string',
@@ -174,7 +174,7 @@ function isRegexStart(str) {
174
174
  * @param {string} code
175
175
  * @return {Array<[number, string]>}
176
176
  */
177
- export function tokenize(code) {
177
+ function tokenize(code) {
178
178
  let current = ''
179
179
  let type = -1
180
180
  /** @type {[number | null, string | null]} */
@@ -514,7 +514,7 @@ function generate(tokens) {
514
514
  function flushLine(tokens) {
515
515
  linesHtml.push(createLine(
516
516
  tokens.map(([type, value]) => (
517
- `<span style="color: var(--sh-${types[type]})">${encode(value)}</span>`
517
+ `<span class="sh__token--${types[type]}" style="color: var(--sh-${types[type]})">${encode(value)}</span>`
518
518
  ))
519
519
  .join('')
520
520
  ))
@@ -555,8 +555,19 @@ function generate(tokens) {
555
555
  * @param {string} code
556
556
  * @returns {string}
557
557
  */
558
- export function highlight(code) {
558
+ function highlight(code) {
559
559
  const tokens = tokenize(code)
560
560
  const output = generate(tokens).join('\n')
561
561
  return output
562
+ }
563
+
564
+ // namespace
565
+ const SugarHigh = {
566
+ TokenTypes: types,
567
+ }
568
+
569
+ export {
570
+ highlight,
571
+ tokenize,
572
+ SugarHigh,
562
573
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "0.4.7",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.mjs",
6
6
  "description": "Super lightweight JSX syntax highlighter",