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.
- package/README.md +10 -0
- package/lib/index.mjs +15 -4
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/index.mjs
CHANGED
|
@@ -76,7 +76,7 @@ const signs = new Set([
|
|
|
76
76
|
...jsxBrackets,
|
|
77
77
|
])
|
|
78
78
|
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|