sugar-high 0.8.2 → 0.8.3
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.js +17 -15
- package/package.json +4 -7
package/lib/index.js
CHANGED
|
@@ -481,13 +481,6 @@ function tokenize(code, options) {
|
|
|
481
481
|
}
|
|
482
482
|
continue
|
|
483
483
|
}
|
|
484
|
-
|
|
485
|
-
// if (curr === ' ' || isSign(curr)) {
|
|
486
|
-
// append()
|
|
487
|
-
// current = curr
|
|
488
|
-
// append()
|
|
489
|
-
// continue
|
|
490
|
-
// }
|
|
491
484
|
}
|
|
492
485
|
}
|
|
493
486
|
|
|
@@ -640,7 +633,7 @@ function tokenize(code, options) {
|
|
|
640
633
|
|
|
641
634
|
/**
|
|
642
635
|
* @param {Array<[number, string]>} tokens
|
|
643
|
-
* @return {Array<any>}
|
|
636
|
+
* @return {Array<{type: string, tagName: string, children: any[], properties: Record<string, string>}>}
|
|
644
637
|
*/
|
|
645
638
|
function generate(tokens) {
|
|
646
639
|
const lines = []
|
|
@@ -671,12 +664,12 @@ function generate(tokens) {
|
|
|
671
664
|
type: 'element',
|
|
672
665
|
tagName: 'span',
|
|
673
666
|
children: [{
|
|
674
|
-
type
|
|
667
|
+
type, // token type
|
|
675
668
|
value: value, // to encode
|
|
676
669
|
}],
|
|
677
670
|
properties: {
|
|
678
671
|
className: `sh__token--${TokenTypes[type]}`,
|
|
679
|
-
style:
|
|
672
|
+
style: { color: `var(--sh-${TokenTypes[type]})` },
|
|
680
673
|
},
|
|
681
674
|
}
|
|
682
675
|
))
|
|
@@ -715,6 +708,19 @@ function generate(tokens) {
|
|
|
715
708
|
return lines
|
|
716
709
|
}
|
|
717
710
|
|
|
711
|
+
/** @param { className: string, style?: Record<string, string> } */
|
|
712
|
+
const propsToString = (props) => {
|
|
713
|
+
let str = `class="${props.className}"`
|
|
714
|
+
|
|
715
|
+
if (props.style) {
|
|
716
|
+
const style = Object.entries(props.style)
|
|
717
|
+
.map(([key, value]) => `${key}:${value}`)
|
|
718
|
+
.join(';')
|
|
719
|
+
str += ` style="${style}"`
|
|
720
|
+
}
|
|
721
|
+
return str
|
|
722
|
+
}
|
|
723
|
+
|
|
718
724
|
function toHtml(lines) {
|
|
719
725
|
return lines
|
|
720
726
|
.map(line => {
|
|
@@ -722,11 +728,7 @@ function toHtml(lines) {
|
|
|
722
728
|
const tokens = line.children
|
|
723
729
|
.map(child => {
|
|
724
730
|
const { tagName, children, properties } = child
|
|
725
|
-
return `<${tagName}
|
|
726
|
-
properties.className
|
|
727
|
-
}" style="${
|
|
728
|
-
properties.style
|
|
729
|
-
}">${encode(children[0].value)}</${tagName}>`
|
|
731
|
+
return `<${tagName} ${propsToString(properties)}>${encode(children[0].value)}</${tagName}>`
|
|
730
732
|
})
|
|
731
733
|
.join('')
|
|
732
734
|
return `<${lineTag} class="${line.properties.className}">${tokens}</${lineTag}>`
|
package/package.json
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sugar-high",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
|
-
"
|
|
7
|
-
"types": "./lib/index.d.ts",
|
|
8
|
-
"default": "./lib/index.js"
|
|
9
|
-
},
|
|
6
|
+
"main": "./lib/index.js",
|
|
10
7
|
"description": "Super lightweight JSX syntax highlighter",
|
|
11
8
|
"files": [
|
|
12
9
|
"lib"
|
|
13
10
|
],
|
|
14
11
|
"license": "MIT",
|
|
15
12
|
"scripts": {
|
|
16
|
-
"test": "vitest
|
|
13
|
+
"test": "vitest",
|
|
17
14
|
"dev": "next dev docs",
|
|
18
15
|
"build": "next build docs"
|
|
19
16
|
},
|
|
20
17
|
"devDependencies": {
|
|
21
18
|
"@types/node": "22.10.7",
|
|
22
19
|
"@types/react": "19.0.7",
|
|
23
|
-
"codice": "^0.
|
|
20
|
+
"codice": "^0.5.0",
|
|
24
21
|
"next": "15.1.5",
|
|
25
22
|
"react": "^19.0.0",
|
|
26
23
|
"react-dom": "^19.0.0",
|