svelte-highlight 7.19.0 → 7.20.1
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/LineNumbers.svelte +11 -11
- package/Typewriter.svelte +6 -10
- package/css-walk.js +97 -0
- package/engine.d.ts +4 -1
- package/engine.js +36 -11
- package/highlight-theme.js +6 -86
- package/incremental-tokenize.js +55 -54
- package/languages/agda.d.ts +2 -0
- package/languages/agda.js +99 -0
- package/languages/all.js +24 -0
- package/languages/cel.d.ts +2 -0
- package/languages/cel.js +103 -0
- package/languages/datalog.d.ts +2 -0
- package/languages/datalog.js +97 -0
- package/languages/fennel.d.ts +2 -0
- package/languages/fennel.js +99 -0
- package/languages/idris.d.ts +2 -0
- package/languages/idris.js +97 -0
- package/languages/index.d.ts +24 -0
- package/languages/index.js +12 -0
- package/languages/jmespath.d.ts +2 -0
- package/languages/jmespath.js +95 -0
- package/languages/jsonata.d.ts +2 -0
- package/languages/jsonata.js +79 -0
- package/languages/lean.d.ts +2 -0
- package/languages/lean.js +117 -0
- package/languages/purescript.d.ts +2 -0
- package/languages/purescript.js +102 -0
- package/languages/racket.d.ts +2 -0
- package/languages/racket.js +147 -0
- package/languages/splunk.d.ts +2 -0
- package/languages/splunk.js +133 -0
- package/languages/vrl.d.ts +2 -0
- package/languages/vrl.js +130 -0
- package/package.json +1 -1
- package/preprocessor.js +13 -9
- package/scoped.js +7 -90
- package/split-lines.js +16 -15
- package/theme-style.js +5 -6
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export const racket =
|
|
2
|
+
/** @type {import("./index.d.ts").LanguageType<"racket">} */ ({
|
|
3
|
+
name: "racket",
|
|
4
|
+
aliases: ["racket", "rkt"],
|
|
5
|
+
register: {
|
|
6
|
+
name: "racket",
|
|
7
|
+
caseInsensitive: false,
|
|
8
|
+
unicode: false,
|
|
9
|
+
disableAutodetect: false,
|
|
10
|
+
states: [
|
|
11
|
+
{
|
|
12
|
+
rules: [1, 2, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15],
|
|
13
|
+
keywords: {
|
|
14
|
+
define: ["keyword", 1],
|
|
15
|
+
"define/contract": ["keyword", 1],
|
|
16
|
+
"define-syntax": ["keyword", 1],
|
|
17
|
+
"syntax-rules": ["keyword", 1],
|
|
18
|
+
lambda: ["keyword", 1],
|
|
19
|
+
let: ["keyword", 1],
|
|
20
|
+
"let*": ["keyword", 1],
|
|
21
|
+
letrec: ["keyword", 1],
|
|
22
|
+
"letrec*": ["keyword", 1],
|
|
23
|
+
if: ["keyword", 0],
|
|
24
|
+
cond: ["keyword", 1],
|
|
25
|
+
case: ["keyword", 1],
|
|
26
|
+
when: ["keyword", 1],
|
|
27
|
+
unless: ["keyword", 1],
|
|
28
|
+
begin: ["keyword", 1],
|
|
29
|
+
begin0: ["keyword", 1],
|
|
30
|
+
"set!": ["keyword", 1],
|
|
31
|
+
and: ["keyword", 0],
|
|
32
|
+
or: ["keyword", 0],
|
|
33
|
+
not: ["keyword", 0],
|
|
34
|
+
quote: ["keyword", 1],
|
|
35
|
+
quasiquote: ["keyword", 1],
|
|
36
|
+
unquote: ["keyword", 1],
|
|
37
|
+
"unquote-splicing": ["keyword", 1],
|
|
38
|
+
require: ["keyword", 1],
|
|
39
|
+
provide: ["keyword", 1],
|
|
40
|
+
module: ["keyword", 1],
|
|
41
|
+
"module+": ["keyword", 1],
|
|
42
|
+
struct: ["keyword", 1],
|
|
43
|
+
match: ["keyword", 1],
|
|
44
|
+
for: ["keyword", 0],
|
|
45
|
+
"for/list": ["keyword", 1],
|
|
46
|
+
"for/vector": ["keyword", 1],
|
|
47
|
+
"for/fold": ["keyword", 1],
|
|
48
|
+
"for/sum": ["keyword", 1],
|
|
49
|
+
class: ["keyword", 1],
|
|
50
|
+
"new": ["keyword", 1],
|
|
51
|
+
send: ["keyword", 1],
|
|
52
|
+
"with-handlers": ["keyword", 1],
|
|
53
|
+
parameterize: ["keyword", 1],
|
|
54
|
+
"call/cc": ["keyword", 1],
|
|
55
|
+
"call-with-values": ["keyword", 1],
|
|
56
|
+
"dynamic-wind": ["keyword", 1],
|
|
57
|
+
delay: ["keyword", 1],
|
|
58
|
+
force: ["keyword", 1],
|
|
59
|
+
},
|
|
60
|
+
keywordPattern: "[^\\s()\\[\\]{}\"'`,;#]+",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
relevance: 10,
|
|
64
|
+
rules: [],
|
|
65
|
+
scope: "meta",
|
|
66
|
+
begin: "^#lang\\s+\\S+",
|
|
67
|
+
end: "\\B|\\b",
|
|
68
|
+
},
|
|
69
|
+
{ rules: [3, 4], scope: "comment", begin: ";", end: "$" },
|
|
70
|
+
{
|
|
71
|
+
relevance: 0,
|
|
72
|
+
rules: [],
|
|
73
|
+
scope: "doctag",
|
|
74
|
+
begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
|
|
75
|
+
end: "(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):",
|
|
76
|
+
excludeBegin: true,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
rules: [],
|
|
80
|
+
begin:
|
|
81
|
+
"[ ]+((?:I|a|is|so|us|to|at|if|in|it|on|[A-Za-z]+['](d|ve|re|ll|t|s|n)|[A-Za-z]+[-][a-z]+|[A-Za-z][a-z]{2,})[.]?[:]?([.][ ]|[ ])){3}",
|
|
82
|
+
end: "\\B|\\b",
|
|
83
|
+
},
|
|
84
|
+
{ rules: [5], scope: "comment", begin: "#\\|", end: "\\|#" },
|
|
85
|
+
{
|
|
86
|
+
relevance: 0,
|
|
87
|
+
rules: [],
|
|
88
|
+
scope: "comment",
|
|
89
|
+
begin: "#;",
|
|
90
|
+
end: "\\B|\\b",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
relevance: 0,
|
|
94
|
+
rules: [],
|
|
95
|
+
scope: "literal",
|
|
96
|
+
begin: "#(?:true|false|[tf])\\b",
|
|
97
|
+
end: "\\B|\\b",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
relevance: 0,
|
|
101
|
+
rules: [],
|
|
102
|
+
scope: "string",
|
|
103
|
+
begin: "#\\\\(?:[a-zA-Z][a-zA-Z0-9-]*|.)",
|
|
104
|
+
end: "\\B|\\b",
|
|
105
|
+
},
|
|
106
|
+
{ rules: [10], scope: "string", begin: '"', end: '"' },
|
|
107
|
+
{ relevance: 0, rules: [], begin: "\\\\[\\s\\S]", end: "\\B|\\b" },
|
|
108
|
+
{
|
|
109
|
+
relevance: 0,
|
|
110
|
+
rules: [],
|
|
111
|
+
scope: "number",
|
|
112
|
+
begin: "#[xX][0-9a-fA-F]+",
|
|
113
|
+
end: "\\B|\\b",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
relevance: 0,
|
|
117
|
+
rules: [],
|
|
118
|
+
scope: "number",
|
|
119
|
+
begin: "#[oO][0-7]+",
|
|
120
|
+
end: "\\B|\\b",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
relevance: 0,
|
|
124
|
+
rules: [],
|
|
125
|
+
scope: "number",
|
|
126
|
+
begin: "#[bB][01]+",
|
|
127
|
+
end: "\\B|\\b",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
relevance: 0,
|
|
131
|
+
rules: [],
|
|
132
|
+
scope: "number",
|
|
133
|
+
begin: "\\b\\d+\\/\\d+\\b",
|
|
134
|
+
end: "\\B|\\b",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
relevance: 0,
|
|
138
|
+
rules: [],
|
|
139
|
+
scope: "number",
|
|
140
|
+
begin: "[+-]?\\b\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?\\b",
|
|
141
|
+
end: "\\B|\\b",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
aliases: ["racket", "rkt"],
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
export default racket;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export const splunk =
|
|
2
|
+
/** @type {import("./index.d.ts").LanguageType<"splunk">} */ ({
|
|
3
|
+
name: "splunk",
|
|
4
|
+
aliases: ["splunk", "spl"],
|
|
5
|
+
register: {
|
|
6
|
+
name: "splunk",
|
|
7
|
+
caseInsensitive: false,
|
|
8
|
+
unicode: false,
|
|
9
|
+
disableAutodetect: false,
|
|
10
|
+
states: [
|
|
11
|
+
{
|
|
12
|
+
rules: [1, 4, 6, 7, 8, 9],
|
|
13
|
+
keywords: {
|
|
14
|
+
search: ["keyword", 1],
|
|
15
|
+
stats: ["keyword", 1],
|
|
16
|
+
eval: ["keyword", 1],
|
|
17
|
+
where: ["keyword", 1],
|
|
18
|
+
rex: ["keyword", 1],
|
|
19
|
+
table: ["keyword", 1],
|
|
20
|
+
sort: ["keyword", 1],
|
|
21
|
+
head: ["keyword", 1],
|
|
22
|
+
tail: ["keyword", 1],
|
|
23
|
+
rename: ["keyword", 1],
|
|
24
|
+
fields: ["keyword", 1],
|
|
25
|
+
dedup: ["keyword", 1],
|
|
26
|
+
lookup: ["keyword", 1],
|
|
27
|
+
join: ["keyword", 1],
|
|
28
|
+
append: ["keyword", 1],
|
|
29
|
+
union: ["keyword", 1],
|
|
30
|
+
transaction: ["keyword", 1],
|
|
31
|
+
timechart: ["keyword", 1],
|
|
32
|
+
chart: ["keyword", 1],
|
|
33
|
+
top: ["keyword", 1],
|
|
34
|
+
rare: ["keyword", 1],
|
|
35
|
+
fillnull: ["keyword", 1],
|
|
36
|
+
convert: ["keyword", 1],
|
|
37
|
+
bin: ["keyword", 1],
|
|
38
|
+
eventstats: ["keyword", 1],
|
|
39
|
+
streamstats: ["keyword", 1],
|
|
40
|
+
regex: ["keyword", 1],
|
|
41
|
+
fieldsummary: ["keyword", 1],
|
|
42
|
+
inputlookup: ["keyword", 1],
|
|
43
|
+
outputlookup: ["keyword", 1],
|
|
44
|
+
makeresults: ["keyword", 1],
|
|
45
|
+
collect: ["keyword", 1],
|
|
46
|
+
multisearch: ["keyword", 1],
|
|
47
|
+
AND: ["keyword", 0],
|
|
48
|
+
OR: ["keyword", 0],
|
|
49
|
+
NOT: ["keyword", 0],
|
|
50
|
+
XOR: ["keyword", 1],
|
|
51
|
+
by: ["keyword", 1],
|
|
52
|
+
count: ["built_in", 1],
|
|
53
|
+
sum: ["built_in", 1],
|
|
54
|
+
avg: ["built_in", 1],
|
|
55
|
+
min: ["built_in", 1],
|
|
56
|
+
max: ["built_in", 1],
|
|
57
|
+
values: ["built_in", 1],
|
|
58
|
+
list: ["built_in", 0],
|
|
59
|
+
distinct_count: ["built_in", 1],
|
|
60
|
+
earliest: ["built_in", 1],
|
|
61
|
+
latest: ["built_in", 1],
|
|
62
|
+
now: ["built_in", 1],
|
|
63
|
+
strftime: ["built_in", 1],
|
|
64
|
+
strptime: ["built_in", 1],
|
|
65
|
+
if: ["built_in", 0],
|
|
66
|
+
case: ["built_in", 1],
|
|
67
|
+
coalesce: ["built_in", 1],
|
|
68
|
+
len: ["built_in", 1],
|
|
69
|
+
substr: ["built_in", 1],
|
|
70
|
+
upper: ["built_in", 1],
|
|
71
|
+
lower: ["built_in", 1],
|
|
72
|
+
trim: ["built_in", 1],
|
|
73
|
+
replace: ["built_in", 1],
|
|
74
|
+
split: ["built_in", 1],
|
|
75
|
+
mvindex: ["built_in", 1],
|
|
76
|
+
mvcount: ["built_in", 1],
|
|
77
|
+
tostring: ["built_in", 1],
|
|
78
|
+
tonumber: ["built_in", 1],
|
|
79
|
+
round: ["built_in", 1],
|
|
80
|
+
abs: ["built_in", 1],
|
|
81
|
+
},
|
|
82
|
+
keywordPattern: "\\w+",
|
|
83
|
+
},
|
|
84
|
+
{ rules: [2, 3], scope: "comment", begin: "#", end: "$" },
|
|
85
|
+
{
|
|
86
|
+
relevance: 0,
|
|
87
|
+
rules: [],
|
|
88
|
+
scope: "doctag",
|
|
89
|
+
begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
|
|
90
|
+
end: "(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):",
|
|
91
|
+
excludeBegin: true,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
rules: [],
|
|
95
|
+
begin:
|
|
96
|
+
"[ ]+((?:I|a|is|so|us|to|at|if|in|it|on|[A-Za-z]+['](d|ve|re|ll|t|s|n)|[A-Za-z]+[-][a-z]+|[A-Za-z][a-z]{2,})[.]?[:]?([.][ ]|[ ])){3}",
|
|
97
|
+
end: "\\B|\\b",
|
|
98
|
+
},
|
|
99
|
+
{ rules: [5], scope: "string", begin: '"', end: '"' },
|
|
100
|
+
{ relevance: 0, rules: [], begin: "\\\\[\\s\\S]", end: "\\B|\\b" },
|
|
101
|
+
{
|
|
102
|
+
relevance: 0,
|
|
103
|
+
rules: [],
|
|
104
|
+
scope: "operator",
|
|
105
|
+
begin: "\\|",
|
|
106
|
+
end: "\\B|\\b",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
relevance: 0,
|
|
110
|
+
rules: [],
|
|
111
|
+
scope: "attr",
|
|
112
|
+
begin: "\\b[a-zA-Z_][\\w.]*(?==)",
|
|
113
|
+
end: "\\B|\\b",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
relevance: 0,
|
|
117
|
+
rules: [],
|
|
118
|
+
scope: "operator",
|
|
119
|
+
begin: ">=|<=|!=|=|>|<",
|
|
120
|
+
end: "\\B|\\b",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
relevance: 0,
|
|
124
|
+
rules: [],
|
|
125
|
+
scope: "number",
|
|
126
|
+
begin: "-?\\b\\d+(?:\\.\\d+)?\\b",
|
|
127
|
+
end: "\\B|\\b",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
aliases: ["splunk", "spl"],
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
export default splunk;
|
package/languages/vrl.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export const vrl = /** @type {import("./index.d.ts").LanguageType<"vrl">} */ ({
|
|
2
|
+
name: "vrl",
|
|
3
|
+
aliases: ["vrl"],
|
|
4
|
+
register: {
|
|
5
|
+
name: "vrl",
|
|
6
|
+
caseInsensitive: false,
|
|
7
|
+
unicode: false,
|
|
8
|
+
disableAutodetect: false,
|
|
9
|
+
states: [
|
|
10
|
+
{
|
|
11
|
+
rules: [1, 4, 6, 7, 8, 9, 10, 11],
|
|
12
|
+
keywords: {
|
|
13
|
+
if: ["keyword", 0],
|
|
14
|
+
else: ["keyword", 1],
|
|
15
|
+
for: ["keyword", 0],
|
|
16
|
+
while: ["keyword", 1],
|
|
17
|
+
abort: ["keyword", 1],
|
|
18
|
+
true: ["literal", 1],
|
|
19
|
+
false: ["literal", 1],
|
|
20
|
+
null: ["literal", 1],
|
|
21
|
+
parse_json: ["built_in", 1],
|
|
22
|
+
parse_syslog: ["built_in", 1],
|
|
23
|
+
parse_key_value: ["built_in", 1],
|
|
24
|
+
parse_regex: ["built_in", 1],
|
|
25
|
+
parse_timestamp: ["built_in", 1],
|
|
26
|
+
parse_duration: ["built_in", 1],
|
|
27
|
+
to_int: ["built_in", 1],
|
|
28
|
+
to_float: ["built_in", 1],
|
|
29
|
+
to_string: ["built_in", 1],
|
|
30
|
+
to_bool: ["built_in", 1],
|
|
31
|
+
to_timestamp: ["built_in", 1],
|
|
32
|
+
exists: ["built_in", 1],
|
|
33
|
+
del: ["built_in", 1],
|
|
34
|
+
contains: ["built_in", 1],
|
|
35
|
+
upcase: ["built_in", 1],
|
|
36
|
+
downcase: ["built_in", 1],
|
|
37
|
+
split: ["built_in", 1],
|
|
38
|
+
join: ["built_in", 1],
|
|
39
|
+
replace: ["built_in", 1],
|
|
40
|
+
slice: ["built_in", 1],
|
|
41
|
+
length: ["built_in", 1],
|
|
42
|
+
now: ["built_in", 1],
|
|
43
|
+
format_timestamp: ["built_in", 1],
|
|
44
|
+
round: ["built_in", 1],
|
|
45
|
+
floor: ["built_in", 1],
|
|
46
|
+
ceil: ["built_in", 1],
|
|
47
|
+
md5: ["built_in", 1],
|
|
48
|
+
sha1: ["built_in", 1],
|
|
49
|
+
sha256: ["built_in", 1],
|
|
50
|
+
encode_json: ["built_in", 1],
|
|
51
|
+
decode_base64: ["built_in", 1],
|
|
52
|
+
encode_base64: ["built_in", 1],
|
|
53
|
+
get_env_var: ["built_in", 1],
|
|
54
|
+
uuid_v4: ["built_in", 1],
|
|
55
|
+
ip_cidr_contains: ["built_in", 1],
|
|
56
|
+
array: ["built_in", 1],
|
|
57
|
+
object: ["built_in", 1],
|
|
58
|
+
string: ["built_in", 1],
|
|
59
|
+
float: ["built_in", 1],
|
|
60
|
+
integer: ["built_in", 1],
|
|
61
|
+
boolean: ["built_in", 1],
|
|
62
|
+
timestamp: ["built_in", 1],
|
|
63
|
+
assert: ["built_in", 1],
|
|
64
|
+
},
|
|
65
|
+
keywordPattern: "\\w+",
|
|
66
|
+
},
|
|
67
|
+
{ rules: [2, 3], scope: "comment", begin: "#", end: "$" },
|
|
68
|
+
{
|
|
69
|
+
relevance: 0,
|
|
70
|
+
rules: [],
|
|
71
|
+
scope: "doctag",
|
|
72
|
+
begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
|
|
73
|
+
end: "(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):",
|
|
74
|
+
excludeBegin: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
rules: [],
|
|
78
|
+
begin:
|
|
79
|
+
"[ ]+((?:I|a|is|so|us|to|at|if|in|it|on|[A-Za-z]+['](d|ve|re|ll|t|s|n)|[A-Za-z]+[-][a-z]+|[A-Za-z][a-z]{2,})[.]?[:]?([.][ ]|[ ])){3}",
|
|
80
|
+
end: "\\B|\\b",
|
|
81
|
+
},
|
|
82
|
+
{ rules: [5], scope: "string", begin: '"', end: '"' },
|
|
83
|
+
{ relevance: 0, rules: [], begin: "\\\\[\\s\\S]", end: "\\B|\\b" },
|
|
84
|
+
{
|
|
85
|
+
relevance: 5,
|
|
86
|
+
rules: [],
|
|
87
|
+
begin: "(\\b[a-zA-Z_]\\w*)(!)",
|
|
88
|
+
end: "\\B|\\b",
|
|
89
|
+
captureScopes: { 1: "built_in", 2: "operator" },
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
relevance: 5,
|
|
93
|
+
rules: [],
|
|
94
|
+
scope: "operator",
|
|
95
|
+
begin: "\\?\\?",
|
|
96
|
+
end: "\\B|\\b",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
relevance: 0,
|
|
100
|
+
rules: [],
|
|
101
|
+
scope: "property",
|
|
102
|
+
begin: "\\.[a-zA-Z_]\\w*",
|
|
103
|
+
end: "\\B|\\b",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
relevance: 0,
|
|
107
|
+
rules: [],
|
|
108
|
+
scope: "property",
|
|
109
|
+
begin: "\\.",
|
|
110
|
+
end: "\\B|\\b",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
relevance: 0,
|
|
114
|
+
rules: [],
|
|
115
|
+
scope: "operator",
|
|
116
|
+
begin: "!",
|
|
117
|
+
end: "\\B|\\b",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
relevance: 0,
|
|
121
|
+
rules: [],
|
|
122
|
+
scope: "number",
|
|
123
|
+
begin: "-?\\b\\d+(?:\\.\\d+)?\\b",
|
|
124
|
+
end: "\\B|\\b",
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
aliases: ["vrl"],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
export default vrl;
|
package/package.json
CHANGED
package/preprocessor.js
CHANGED
|
@@ -103,14 +103,23 @@ function getStaticStringExpression(expression) {
|
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
/**
|
|
107
|
-
|
|
106
|
+
/**
|
|
107
|
+
* The attribute's sole value node; `null` for boolean attributes and for
|
|
108
|
+
* values mixing several parts (`class="a {b}"`).
|
|
109
|
+
* @param {import("svelte/compiler").AST.Attribute} attribute
|
|
110
|
+
*/
|
|
111
|
+
function getSingleAttributeValue(attribute) {
|
|
108
112
|
if (attribute.value === true) return null;
|
|
109
113
|
const values = Array.isArray(attribute.value)
|
|
110
114
|
? attribute.value
|
|
111
115
|
: [attribute.value];
|
|
112
116
|
if (values.length !== 1) return null;
|
|
113
|
-
|
|
117
|
+
return values[0] ?? null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @param {import("svelte/compiler").AST.Attribute} attribute */
|
|
121
|
+
function getStaticStringAttribute(attribute) {
|
|
122
|
+
const value = getSingleAttributeValue(attribute);
|
|
114
123
|
if (!value) return null;
|
|
115
124
|
if (value.type === "Text") return value.data;
|
|
116
125
|
if (value.type === "ExpressionTag")
|
|
@@ -120,12 +129,7 @@ function getStaticStringAttribute(attribute) {
|
|
|
120
129
|
|
|
121
130
|
/** @param {import("svelte/compiler").AST.Attribute} attribute */
|
|
122
131
|
function getIdentifierAttribute(attribute) {
|
|
123
|
-
|
|
124
|
-
const values = Array.isArray(attribute.value)
|
|
125
|
-
? attribute.value
|
|
126
|
-
: [attribute.value];
|
|
127
|
-
if (values.length !== 1) return null;
|
|
128
|
-
const [value] = values;
|
|
132
|
+
const value = getSingleAttributeValue(attribute);
|
|
129
133
|
if (
|
|
130
134
|
value?.type !== "ExpressionTag" ||
|
|
131
135
|
value.expression.type !== "Identifier"
|
package/scoped.js
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* Used by HighlightStyle and the docs styles build.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
findBlockEnd,
|
|
8
|
+
findStringEnd,
|
|
9
|
+
STYLE_TAG,
|
|
10
|
+
splitTopLevel,
|
|
11
|
+
} from "./css-walk.js";
|
|
12
|
+
|
|
6
13
|
// @media, @supports, etc.: recurse into the block body.
|
|
7
14
|
const GROUP_AT_RULES = new Set([
|
|
8
15
|
"media",
|
|
@@ -13,99 +20,9 @@ const GROUP_AT_RULES = new Set([
|
|
|
13
20
|
"scope",
|
|
14
21
|
]);
|
|
15
22
|
|
|
16
|
-
const STYLE_TAG = /^(\s*<style>)([\s\S]*?)(<\/style>\s*)$/;
|
|
17
23
|
const AT_RULE_NAME = /^@([a-zA-Z-]+)/;
|
|
18
24
|
const WHITESPACE = /\s/;
|
|
19
25
|
|
|
20
|
-
/**
|
|
21
|
-
* @param {string} css
|
|
22
|
-
* @param {number} start
|
|
23
|
-
*/
|
|
24
|
-
function findStringEnd(css, start) {
|
|
25
|
-
const quote = css[start];
|
|
26
|
-
let i = start + 1;
|
|
27
|
-
while (i < css.length) {
|
|
28
|
-
const ch = css[i];
|
|
29
|
-
if (ch === "\\") {
|
|
30
|
-
i += 2;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (ch === quote) return i + 1;
|
|
34
|
-
i += 1;
|
|
35
|
-
}
|
|
36
|
-
return css.length;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Index after the `}` that closes the block starting at `start`.
|
|
41
|
-
* @param {string} css
|
|
42
|
-
* @param {number} start
|
|
43
|
-
*/
|
|
44
|
-
function findBlockEnd(css, start) {
|
|
45
|
-
let depth = 1;
|
|
46
|
-
let i = start;
|
|
47
|
-
while (i < css.length) {
|
|
48
|
-
const ch = css[i];
|
|
49
|
-
if (ch === "/" && css[i + 1] === "*") {
|
|
50
|
-
const end = css.indexOf("*/", i + 2);
|
|
51
|
-
i = end === -1 ? css.length : end + 2;
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (ch === '"' || ch === "'") {
|
|
55
|
-
i = findStringEnd(css, i);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (ch === "{") {
|
|
59
|
-
depth += 1;
|
|
60
|
-
} else if (ch === "}") {
|
|
61
|
-
depth -= 1;
|
|
62
|
-
if (depth === 0) return i;
|
|
63
|
-
}
|
|
64
|
-
i += 1;
|
|
65
|
-
}
|
|
66
|
-
return css.length;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Split on `delim`, skipping nested `()`, `[]`, strings, and comments.
|
|
71
|
-
* @param {string} str
|
|
72
|
-
* @param {string} delim
|
|
73
|
-
*/
|
|
74
|
-
function splitTopLevel(str, delim) {
|
|
75
|
-
const parts = [];
|
|
76
|
-
let depth = 0;
|
|
77
|
-
let current = "";
|
|
78
|
-
let i = 0;
|
|
79
|
-
while (i < str.length) {
|
|
80
|
-
const ch = str[i];
|
|
81
|
-
if (ch === "/" && str[i + 1] === "*") {
|
|
82
|
-
const end = str.indexOf("*/", i + 2);
|
|
83
|
-
const stop = end === -1 ? str.length : end + 2;
|
|
84
|
-
current += str.slice(i, stop);
|
|
85
|
-
i = stop;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (ch === '"' || ch === "'") {
|
|
89
|
-
const stop = findStringEnd(str, i);
|
|
90
|
-
current += str.slice(i, stop);
|
|
91
|
-
i = stop;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (ch === "(" || ch === "[") depth += 1;
|
|
95
|
-
else if (ch === ")" || ch === "]") depth -= 1;
|
|
96
|
-
|
|
97
|
-
if (ch === delim && depth === 0) {
|
|
98
|
-
parts.push(current);
|
|
99
|
-
current = "";
|
|
100
|
-
} else {
|
|
101
|
-
current += ch;
|
|
102
|
-
}
|
|
103
|
-
i += 1;
|
|
104
|
-
}
|
|
105
|
-
parts.push(current);
|
|
106
|
-
return parts;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
26
|
/**
|
|
110
27
|
* @param {string} selector
|
|
111
28
|
* @returns {[string, string, string]} `[leading, core, trailing]`
|
package/split-lines.js
CHANGED
|
@@ -12,39 +12,40 @@ export function splitLines(html) {
|
|
|
12
12
|
/** @type {string[]} */
|
|
13
13
|
const stack = [];
|
|
14
14
|
let current = "";
|
|
15
|
+
// Text (tags included) is copied in runs delimited by newlines rather
|
|
16
|
+
// than character by character; only `<` and `\n` need inspecting.
|
|
17
|
+
let runStart = 0;
|
|
15
18
|
let i = 0;
|
|
16
19
|
|
|
17
20
|
while (i < html.length) {
|
|
18
|
-
const
|
|
21
|
+
const code = html.charCodeAt(i);
|
|
19
22
|
|
|
20
|
-
if (
|
|
23
|
+
if (code === LESS_THAN) {
|
|
21
24
|
const tagEnd = html.indexOf(">", i);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (tag.startsWith("</span")) {
|
|
25
|
+
if (html.startsWith("</span", i)) {
|
|
25
26
|
stack.pop();
|
|
26
|
-
} else if (
|
|
27
|
-
stack.push(
|
|
27
|
+
} else if (html.startsWith("<span", i)) {
|
|
28
|
+
stack.push(html.slice(i, tagEnd + 1));
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
current += tag;
|
|
31
30
|
i = tagEnd + 1;
|
|
32
31
|
continue;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
if (
|
|
36
|
-
current +=
|
|
34
|
+
if (code === NEWLINE) {
|
|
35
|
+
current += html.slice(runStart, i);
|
|
36
|
+
if (stack.length > 0) current += "</span>".repeat(stack.length);
|
|
37
37
|
lines.push(current);
|
|
38
38
|
current = stack.join("");
|
|
39
|
-
i
|
|
40
|
-
continue;
|
|
39
|
+
runStart = i + 1;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
current += char;
|
|
44
42
|
i++;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
lines.push(current);
|
|
45
|
+
lines.push(current + html.slice(runStart));
|
|
48
46
|
|
|
49
47
|
return lines;
|
|
50
48
|
}
|
|
49
|
+
|
|
50
|
+
const LESS_THAN = 60;
|
|
51
|
+
const NEWLINE = 10;
|
package/theme-style.js
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* for `HighlightStyle`'s object path (see `HighlightStyle.svelte`).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { PROP_SUFFIX } from "./theme-vars.js";
|
|
6
7
|
import { SHL_FALLBACKS } from "./themes/_shl-fallbacks.js";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"-text-decoration",
|
|
13
|
-
];
|
|
9
|
+
// `-bg`, `-font-style`, ...: every var suffix except color's empty one.
|
|
10
|
+
const NON_COLOR_SUFFIXES = Object.values(PROP_SUFFIX)
|
|
11
|
+
.filter((suffix) => suffix !== "")
|
|
12
|
+
.map((suffix) => `-${suffix}`);
|
|
14
13
|
|
|
15
14
|
/** @param {string} key */
|
|
16
15
|
function isColorKey(key) {
|