sugar-high 0.8.2 → 0.8.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/lib/index.js +23 -20
- package/package.json +7 -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 = []
|
|
@@ -666,20 +659,21 @@ function generate(tokens) {
|
|
|
666
659
|
/** @type {Array<any>} */
|
|
667
660
|
const lineTokens = (
|
|
668
661
|
tokens
|
|
669
|
-
.map(([type, value]) =>
|
|
670
|
-
|
|
662
|
+
.map(([type, value]) => {
|
|
663
|
+
const tokenType = TokenTypes[type]
|
|
664
|
+
return {
|
|
671
665
|
type: 'element',
|
|
672
666
|
tagName: 'span',
|
|
673
667
|
children: [{
|
|
674
|
-
type: 'text',
|
|
675
|
-
value
|
|
668
|
+
type: 'text', // text node
|
|
669
|
+
value, // to encode
|
|
676
670
|
}],
|
|
677
671
|
properties: {
|
|
678
|
-
className: `sh__token--${
|
|
679
|
-
style:
|
|
672
|
+
className: `sh__token--${tokenType}`,
|
|
673
|
+
style: { color: `var(--sh-${tokenType})` },
|
|
680
674
|
},
|
|
681
675
|
}
|
|
682
|
-
)
|
|
676
|
+
})
|
|
683
677
|
)
|
|
684
678
|
lines.push(createLine(lineTokens))
|
|
685
679
|
}
|
|
@@ -715,6 +709,19 @@ function generate(tokens) {
|
|
|
715
709
|
return lines
|
|
716
710
|
}
|
|
717
711
|
|
|
712
|
+
/** @param { className: string, style?: Record<string, string> } */
|
|
713
|
+
const propsToString = (props) => {
|
|
714
|
+
let str = `class="${props.className}"`
|
|
715
|
+
|
|
716
|
+
if (props.style) {
|
|
717
|
+
const style = Object.entries(props.style)
|
|
718
|
+
.map(([key, value]) => `${key}:${value}`)
|
|
719
|
+
.join(';')
|
|
720
|
+
str += ` style="${style}"`
|
|
721
|
+
}
|
|
722
|
+
return str
|
|
723
|
+
}
|
|
724
|
+
|
|
718
725
|
function toHtml(lines) {
|
|
719
726
|
return lines
|
|
720
727
|
.map(line => {
|
|
@@ -722,11 +729,7 @@ function toHtml(lines) {
|
|
|
722
729
|
const tokens = line.children
|
|
723
730
|
.map(child => {
|
|
724
731
|
const { tagName, children, properties } = child
|
|
725
|
-
return `<${tagName}
|
|
726
|
-
properties.className
|
|
727
|
-
}" style="${
|
|
728
|
-
properties.style
|
|
729
|
-
}">${encode(children[0].value)}</${tagName}>`
|
|
732
|
+
return `<${tagName} ${propsToString(properties)}>${encode(children[0].value)}</${tagName}>`
|
|
730
733
|
})
|
|
731
734
|
.join('')
|
|
732
735
|
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.4",
|
|
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": "^1.0.0-beta.0",
|
|
24
21
|
"next": "15.1.5",
|
|
25
22
|
"react": "^19.0.0",
|
|
26
23
|
"react-dom": "^19.0.0",
|
|
@@ -28,5 +25,8 @@
|
|
|
28
25
|
"typescript": "5.7.3",
|
|
29
26
|
"vitest": "^3.0.2"
|
|
30
27
|
},
|
|
28
|
+
"resolutions": {
|
|
29
|
+
"sugar-high": "link:./"
|
|
30
|
+
},
|
|
31
31
|
"packageManager": "pnpm@8.7.1"
|
|
32
32
|
}
|