@scalar/highlight 0.3.0 → 0.4.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/CHANGELOG.md +49 -0
- package/README.md +52 -13
- package/dist/all.d.ts.map +1 -1
- package/dist/all.js +2 -0
- package/dist/compat/hast.d.ts.map +1 -1
- package/dist/compat/hast.js +4 -2
- package/dist/compat/hljs.d.ts.map +1 -1
- package/dist/compat/hljs.js +2 -1
- package/dist/compat/languages.d.ts.map +1 -1
- package/dist/compat/languages.js +2 -4
- package/dist/compat/syntax-highlight.d.ts.map +1 -1
- package/dist/compat/syntax-highlight.js +107 -29
- package/dist/core/compile.d.ts +9 -1
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +128 -10
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +8 -4
- package/dist/core/render.d.ts.map +1 -1
- package/dist/core/render.js +12 -6
- package/dist/core/tokenize.d.ts.map +1 -1
- package/dist/core/tokenize.js +161 -17
- package/dist/core/types.d.ts +74 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/langs/bash.d.ts.map +1 -1
- package/dist/langs/bash.js +60 -13
- package/dist/langs/csharp.d.ts.map +1 -1
- package/dist/langs/csharp.js +11 -5
- package/dist/langs/css.d.ts.map +1 -1
- package/dist/langs/css.js +84 -7
- package/dist/langs/go.d.ts.map +1 -1
- package/dist/langs/go.js +7 -1
- package/dist/langs/html.d.ts +0 -10
- package/dist/langs/html.d.ts.map +1 -1
- package/dist/langs/html.js +63 -24
- package/dist/langs/http.d.ts.map +1 -1
- package/dist/langs/http.js +25 -9
- package/dist/langs/javascript.d.ts.map +1 -1
- package/dist/langs/javascript.js +146 -30
- package/dist/langs/json.d.ts.map +1 -1
- package/dist/langs/json.js +7 -1
- package/dist/langs/julia.d.ts +4 -0
- package/dist/langs/julia.d.ts.map +1 -0
- package/dist/langs/julia.js +181 -0
- package/dist/langs/markdown.d.ts +9 -3
- package/dist/langs/markdown.d.ts.map +1 -1
- package/dist/langs/markdown.js +127 -6
- package/dist/langs/ocaml.d.ts.map +1 -1
- package/dist/langs/ocaml.js +16 -7
- package/dist/langs/php.d.ts.map +1 -1
- package/dist/langs/php.js +69 -19
- package/dist/langs/r.js +9 -9
- package/dist/langs/rust.d.ts.map +1 -1
- package/dist/langs/rust.js +19 -10
- package/dist/langs/sql.d.ts.map +1 -1
- package/dist/langs/sql.js +9 -3
- package/dist/langs/yaml.d.ts +0 -7
- package/dist/langs/yaml.d.ts.map +1 -1
- package/dist/langs/yaml.js +157 -28
- package/dist/lazy.d.ts +1 -0
- package/dist/lazy.d.ts.map +1 -1
- package/dist/lazy.js +6 -2
- package/package.json +3 -3
package/dist/core/types.d.ts
CHANGED
|
@@ -35,7 +35,31 @@ export type Rule = {
|
|
|
35
35
|
set?: string;
|
|
36
36
|
/** Pop `n` states (`true` means 1). */
|
|
37
37
|
pop?: number | true;
|
|
38
|
+
/**
|
|
39
|
+
* Remember the text of this capture group (1-based, within this rule's
|
|
40
|
+
* pattern) for the state that `push` or `set` enters.
|
|
41
|
+
*
|
|
42
|
+
* That state's rules can then match it again by writing `REMEMBERED`
|
|
43
|
+
* (`{{remembered}}`) in a pattern. It is the stand-in for a backreference
|
|
44
|
+
* across rules: a heredoc remembers its terminator, a raw string the run of
|
|
45
|
+
* quotes that opened it, a YAML block scalar the indentation of its key.
|
|
46
|
+
*
|
|
47
|
+
* A state entered without `remember` inherits the value of the state that
|
|
48
|
+
* pushed it, so helper states nested inside keep seeing it.
|
|
49
|
+
*/
|
|
50
|
+
remember?: number;
|
|
51
|
+
/**
|
|
52
|
+
* `'text'` (the default) remembers the group verbatim. `'indent'` remembers
|
|
53
|
+
* a run of spaces as wide as the group, which is what an indentation-based
|
|
54
|
+
* end rule wants: `- key: |` remembers the column of `key`, not `- `.
|
|
55
|
+
*/
|
|
56
|
+
rememberAs?: 'text' | 'indent';
|
|
38
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* The placeholder a pattern uses to match the remembered text again. The text
|
|
60
|
+
* is inserted escaped, so it matches literally.
|
|
61
|
+
*/
|
|
62
|
+
export declare const REMEMBERED = "{{remembered}}";
|
|
39
63
|
/** Splices another state's rules in at this position, keeping priority order. */
|
|
40
64
|
export type Include = {
|
|
41
65
|
include: string;
|
|
@@ -46,6 +70,34 @@ export type State = {
|
|
|
46
70
|
default?: ScopeName;
|
|
47
71
|
/** Compile this state's patterns case-insensitively. */
|
|
48
72
|
ignoreCase?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Highlight the body of this state with another registered language.
|
|
75
|
+
*
|
|
76
|
+
* When the state is entered, the text up to the first match of `until` (or
|
|
77
|
+
* the end of the input) is tokenized with `language`, then the state pops.
|
|
78
|
+
* `until` is not consumed, so the state below sees it: a `<script>` body
|
|
79
|
+
* ends where `</script>` starts, and the HTML grammar scopes the tag.
|
|
80
|
+
*
|
|
81
|
+
* The language is looked up in the registry when the state is entered, so
|
|
82
|
+
* embedding costs nothing until that language is registered. Without it,
|
|
83
|
+
* the body is emitted with this state's `default` scope.
|
|
84
|
+
*
|
|
85
|
+
* `language` can be `REMEMBERED` (`{{remembered}}`) to use the text the rule
|
|
86
|
+
* that entered the state remembered: a Markdown fence remembers its info
|
|
87
|
+
* string and embeds whatever language it names.
|
|
88
|
+
*
|
|
89
|
+
* `holes` marks regions inside the body that belong to this grammar rather
|
|
90
|
+
* than the embedded one, such as `<?= $x ?>` inside a PHP template's
|
|
91
|
+
* `<script>`. The embedded language reads the body with each hole masked,
|
|
92
|
+
* so its state carries across (a hole inside a JavaScript string leaves the
|
|
93
|
+
* rest of the string a string), and each hole is tokenized with this
|
|
94
|
+
* grammar from its root.
|
|
95
|
+
*/
|
|
96
|
+
embed?: {
|
|
97
|
+
language: string;
|
|
98
|
+
until: string;
|
|
99
|
+
holes?: string;
|
|
100
|
+
};
|
|
49
101
|
rules: StateRule[];
|
|
50
102
|
};
|
|
51
103
|
export type Grammar = {
|
|
@@ -83,12 +135,34 @@ export type CompiledRule = {
|
|
|
83
135
|
push: string | null;
|
|
84
136
|
set: string | null;
|
|
85
137
|
pop: number;
|
|
138
|
+
/** Capture group to remember, as an offset from `group`; `0` for none. */
|
|
139
|
+
remember: number;
|
|
140
|
+
rememberIndent: boolean;
|
|
86
141
|
};
|
|
87
142
|
export type CompiledState = {
|
|
88
143
|
name: string;
|
|
89
144
|
re: RegExp;
|
|
90
145
|
rules: CompiledRule[];
|
|
91
146
|
default: ScopeName | null;
|
|
147
|
+
/**
|
|
148
|
+
* Set when a rule uses `REMEMBERED`: the merged regex then depends on the
|
|
149
|
+
* remembered text and is built per value, from these sources.
|
|
150
|
+
*/
|
|
151
|
+
dynamic: {
|
|
152
|
+
source: string;
|
|
153
|
+
flags: string;
|
|
154
|
+
/** Per-rule sticky sources for capture offsets, `null` where unused. */
|
|
155
|
+
own: (string | null)[];
|
|
156
|
+
cache: Map<string, {
|
|
157
|
+
re: RegExp;
|
|
158
|
+
own: (RegExp | null)[];
|
|
159
|
+
}>;
|
|
160
|
+
} | null;
|
|
161
|
+
embed: {
|
|
162
|
+
language: string;
|
|
163
|
+
boundary: RegExp;
|
|
164
|
+
holes: RegExp | null;
|
|
165
|
+
} | null;
|
|
92
166
|
};
|
|
93
167
|
export type CompiledGrammar = {
|
|
94
168
|
name: string;
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,MAAM,MAAM,IAAI,GAAG;IACjB;;;;;;OAMG;IACH,KAAK,E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AAA;IACnB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,OAAO,EAAE,SAAS,GAAG,IAAI,CAAA;IACzB;;;OAGG;IACH,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;QACb,wEAAwE;QACxE,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;QACtB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;SAAE,CAAC,CAAA;KAC3D,GAAG,IAAI,CAAA;IACR,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAA;CAC3E,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IACrC,IAAI,EAAE,aAAa,CAAA;CACpB,CAAA"}
|
package/dist/core/types.js
CHANGED
|
@@ -7,4 +7,8 @@
|
|
|
7
7
|
* a string state needs three rules (escape, interpolation, closing quote), not
|
|
8
8
|
* a rule for "string content".
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The placeholder a pattern uses to match the remembered text again. The text
|
|
12
|
+
* is inserted escaped, so it matches literally.
|
|
13
|
+
*/
|
|
14
|
+
export const REMEMBERED = '{{remembered}}';
|
package/dist/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ export type { Scope } from './core/scopes.js';
|
|
|
16
16
|
export { SCOPES, SCOPE_NAMES, scopeChain, scopeClass } from './core/scopes.js';
|
|
17
17
|
export { tokenize as tokenizeStream } from './core/tokenize.js';
|
|
18
18
|
export type { CompiledGrammar, Emit, Grammar, Include, Rule, ScopeName, State, StateRule, Token, } from './core/types.js';
|
|
19
|
+
export { REMEMBERED } from './core/types.js';
|
|
19
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAGhE,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEnE,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,eAAe,CAAA;AAE9D,yEAAyE;AACzE,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,EAAE,UAAU,aAAa,KAAG,MAEtF,CAAA;AAED,yDAAyD;AACzD,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,EAAE,UAAU,YAAY,KAAG,MAE1F,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,MAAM,aAAa,KAAG,KAAK,EAEjE,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAA;AACxB,YAAY,EA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AY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3E,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5D,YAAY,EACV,eAAe,EACf,IAAI,EACJ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,SAAS,EACT,KAAK,EACL,SAAS,EACT,KAAK,GACN,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -18,3 +18,4 @@ export { getLanguage, isRegistered, listLanguages, registerLanguage, resolveGram
|
|
|
18
18
|
export { DEFAULT_PREFIX, escapeAttribute, escapeHtml } from './core/render.js';
|
|
19
19
|
export { SCOPES, SCOPE_NAMES, scopeChain, scopeClass } from './core/scopes.js';
|
|
20
20
|
export { tokenize as tokenizeStream } from './core/tokenize.js';
|
|
21
|
+
export { REMEMBERED } from './core/types.js';
|
package/dist/langs/bash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../src/langs/bash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../src/langs/bash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAoB5C,QAAA,MAAM,IAAI,EAAE,OAqKX,CAAA;AAED,eAAe,IAAI,CAAA"}
|
package/dist/langs/bash.js
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* the way the shell does.
|
|
8
8
|
*/
|
|
9
9
|
const VAR = '\\$(?:[A-Za-z_]\\w*|[0-9!@#?*$-])';
|
|
10
|
+
/**
|
|
11
|
+
* Where a command name can stand: at the start of a line that does not
|
|
12
|
+
* continue the one before it, after a prompt, after a pipe, list operator or
|
|
13
|
+
* subshell opener, and after the keywords and wrappers that run a command.
|
|
14
|
+
*/
|
|
15
|
+
const BEFORE_COMMAND = '(?:^(?<!\\\\\\r?\\n)(?:[ \\t]*\\$(?=[ \\t]))?|[|&;(`{]|\\$\\(|\\b(?:then|do|else|elif|sudo|time|exec|xargs|nohup|env)\\b|!)';
|
|
10
16
|
const bash = {
|
|
11
17
|
name: 'bash',
|
|
12
18
|
aliases: ['sh', 'shell', 'zsh', 'console'],
|
|
@@ -16,31 +22,58 @@ const bash = {
|
|
|
16
22
|
{ match: '^#!.*', scope: 'comment' },
|
|
17
23
|
{ match: '(?:^|[ \\t])#[^\\n]*', scope: 'comment' },
|
|
18
24
|
{ include: 'expansion' },
|
|
25
|
+
// An escaped character outside quotes is literal. It has to come
|
|
26
|
+
// before the quote rules: `'it'\\''s'` is how a single quote is written
|
|
27
|
+
// inside a single-quoted string — close, escaped quote, reopen — and
|
|
28
|
+
// reading that `\\'` as the start of a string inverts the rest of the
|
|
29
|
+
// line. snippetz writes it for every curl body with an apostrophe.
|
|
30
|
+
// A backslash before a newline is a line continuation, left unscoped.
|
|
31
|
+
{ match: '\\\\[^\\r\\n]', scope: 'string.escape' },
|
|
19
32
|
{ match: '"', scope: 'string', push: 'string-double' },
|
|
20
33
|
{ match: "'", scope: 'string', push: 'string-single' },
|
|
21
34
|
{ match: "\\$'", scope: 'string', push: 'string-ansi' },
|
|
22
35
|
{ match: '`', scope: 'string', push: 'backtick' },
|
|
23
36
|
// Heredocs: the body is scoped as a string up to a line holding only
|
|
24
|
-
// the terminator.
|
|
25
|
-
//
|
|
37
|
+
// the remembered terminator. A quoted marker (`<<'EOF'`) turns
|
|
38
|
+
// expansion off, so `$HOME` in its body is text.
|
|
26
39
|
{
|
|
27
|
-
match: '(<<-?)(\\
|
|
40
|
+
match: '(<<-?)([ \\t]*)([\'"])([A-Za-z_]\\w*)([\'"])',
|
|
28
41
|
scope: ['operator', null, 'string', 'string.special', 'string'],
|
|
42
|
+
push: 'heredoc-literal',
|
|
43
|
+
remember: 4,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
match: '(<<-?)([ \\t]*)([A-Za-z_]\\w*)',
|
|
47
|
+
scope: ['operator', null, 'string.special'],
|
|
29
48
|
push: 'heredoc',
|
|
49
|
+
remember: 3,
|
|
30
50
|
},
|
|
31
51
|
{
|
|
32
52
|
match: '\\b(?:if|then|else|elif|fi|for|while|until|do|done|case|esac|select|break|continue|return|exit)\\b',
|
|
33
53
|
scope: 'keyword.control',
|
|
34
54
|
},
|
|
55
|
+
// The name a declaration sets gets a state of its own, so the argument
|
|
56
|
+
// rule below cannot read `API_KEY=…` in `export API_KEY=…` as a string.
|
|
35
57
|
{
|
|
36
|
-
match: '\\b(?:
|
|
58
|
+
match: '\\b(?:local|declare|typeset|readonly|export)\\b',
|
|
37
59
|
scope: 'keyword.declaration',
|
|
60
|
+
push: 'declared-name',
|
|
38
61
|
},
|
|
62
|
+
{ match: '\\b(?:function|alias|unset)\\b', scope: 'keyword.declaration' },
|
|
39
63
|
{ match: '\\b(?:in|then)\\b', scope: 'keyword.operator' },
|
|
40
64
|
{
|
|
41
65
|
match: '\\b(?:echo|printf|read|cd|pwd|source|eval|exec|test|trap|set|shift|wait|kill|jobs|getopts|command|type|hash|umask|ulimit)\\b',
|
|
42
66
|
scope: 'function.builtin',
|
|
43
67
|
},
|
|
68
|
+
// The command itself: `curl`, `./build.sh`, `/usr/bin/env`. Keywords
|
|
69
|
+
// and builtins start at the same position and come first, so they keep
|
|
70
|
+
// their own scopes. The lookbehind sits after the first character so
|
|
71
|
+
// the rule still starts with a literal class, which keeps the engine's
|
|
72
|
+
// first-character scan.
|
|
73
|
+
{
|
|
74
|
+
match: `[A-Za-z_./~](?<=${BEFORE_COMMAND}[ \\t]*[A-Za-z_./~])[\\w./~+-]{0,128}(?=[ \\t]|$|[;|&)\`])`,
|
|
75
|
+
scope: 'function.call',
|
|
76
|
+
},
|
|
44
77
|
{
|
|
45
78
|
match: '^([ \\t]*)([A-Za-z_]\\w*)(\\s*)(\\(\\))',
|
|
46
79
|
scope: [null, 'function', null, 'punctuation.bracket'],
|
|
@@ -49,12 +82,24 @@ const bash = {
|
|
|
49
82
|
// Flags are a large share of a shell line and benefit from their own color.
|
|
50
83
|
{ match: '(?:^|\\s)(--?[A-Za-z][\\w-]*)', scope: ['constant'] },
|
|
51
84
|
{ match: '\\b\\d+\\b', scope: 'number' },
|
|
85
|
+
// An unquoted argument is a string to the shell, and themes colour it
|
|
86
|
+
// like one. Command names, keywords and flags start at the same place
|
|
87
|
+
// and come first.
|
|
88
|
+
{ match: '[^\\s$\'"`\\\\|&;()<>{}\\[\\]#=-][^\\s$\'"`\\\\|&;()<>{}]{0,256}', scope: 'string' },
|
|
52
89
|
// `/` is left out: at the top level it is almost always a path
|
|
53
90
|
// separator, and coloring every path segment boundary is noise.
|
|
54
91
|
{ match: '&&|\\|\\||[|&;]|[<>]{1,2}|[-+*%!=]=?|=~', scope: 'operator' },
|
|
55
92
|
{ match: '[()\\[\\]{}]', scope: 'punctuation.bracket' },
|
|
56
93
|
],
|
|
57
94
|
},
|
|
95
|
+
/** After `export`, `local` and the like: flags, then the one name it sets. */
|
|
96
|
+
'declared-name': {
|
|
97
|
+
rules: [
|
|
98
|
+
{ match: '(?:^|\\s)(--?[A-Za-z][\\w-]*)', scope: ['constant'] },
|
|
99
|
+
{ match: '[A-Za-z_]\\w*', scope: 'variable', pop: true },
|
|
100
|
+
{ match: '(?=[^ \\t])', pop: true },
|
|
101
|
+
],
|
|
102
|
+
},
|
|
58
103
|
expansion: {
|
|
59
104
|
rules: [
|
|
60
105
|
{ match: '\\$\\{', scope: 'variable', push: 'brace-expansion' },
|
|
@@ -84,7 +129,7 @@ const bash = {
|
|
|
84
129
|
'string-double': {
|
|
85
130
|
default: 'string',
|
|
86
131
|
rules: [
|
|
87
|
-
{ match: '\\\\[\\\\$`"\\n]', scope: 'string.escape' },
|
|
132
|
+
{ match: '\\\\(?:[\\\\$`"\\n]|\\r\\n)', scope: 'string.escape' },
|
|
88
133
|
{ include: 'expansion' },
|
|
89
134
|
{ match: '`', scope: 'string', push: 'backtick' },
|
|
90
135
|
{ match: '"', scope: 'string', pop: true },
|
|
@@ -109,14 +154,16 @@ const bash = {
|
|
|
109
154
|
},
|
|
110
155
|
heredoc: {
|
|
111
156
|
default: 'string',
|
|
112
|
-
rules: [
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
rules: [{ include: 'heredoc-end' }, { include: 'expansion' }],
|
|
158
|
+
},
|
|
159
|
+
'heredoc-literal': {
|
|
160
|
+
default: 'string',
|
|
161
|
+
rules: [{ include: 'heredoc-end' }],
|
|
162
|
+
},
|
|
163
|
+
'heredoc-end': {
|
|
164
|
+
// `<<-` lets the terminator be indented with tabs; allowing any indent
|
|
165
|
+
// costs nothing and also covers bodies pasted with spaces.
|
|
166
|
+
rules: [{ match: '^[ \\t]*{{remembered}}[ \\t]*$', scope: 'string.special', pop: true }],
|
|
120
167
|
},
|
|
121
168
|
},
|
|
122
169
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/langs/csharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAuD5C,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/langs/csharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAuD5C,QAAA,MAAM,MAAM,EAAE,OAkSb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/langs/csharp.js
CHANGED
|
@@ -192,12 +192,18 @@ const csharp = {
|
|
|
192
192
|
// rather than as part of it. Longest opener first: `"""` before `"`.
|
|
193
193
|
strings: {
|
|
194
194
|
rules: [
|
|
195
|
+
// A raw literal opens with three or more quotes and closes with the
|
|
196
|
+
// same number, so it can hold a shorter run: `""""` wraps text that
|
|
197
|
+
// contains `"""`. The opening run is remembered for the close.
|
|
195
198
|
{
|
|
196
|
-
|
|
199
|
+
// The lookbehind keeps the `$` run from being retried at each of its
|
|
200
|
+
// characters, which is O(n²) on a long line of `$`.
|
|
201
|
+
match: '(\\$(?<!\\$\\$)\\$*)("{3,})',
|
|
197
202
|
scope: ['string.special', 'string'],
|
|
198
203
|
push: 'raw-interpolated',
|
|
204
|
+
remember: 2,
|
|
199
205
|
},
|
|
200
|
-
{ match: '"
|
|
206
|
+
{ match: '("{3,})', scope: 'string', push: 'raw', remember: 1 },
|
|
201
207
|
{
|
|
202
208
|
match: '(\\$@|@\\$)(")',
|
|
203
209
|
scope: ['string.special', 'string'],
|
|
@@ -261,15 +267,15 @@ const csharp = {
|
|
|
261
267
|
{ match: '"', scope: 'string', pop: true },
|
|
262
268
|
],
|
|
263
269
|
},
|
|
264
|
-
// Raw literals have no escapes at all: the closing
|
|
270
|
+
// Raw literals have no escapes at all: the closing run of quotes is the only thing
|
|
265
271
|
// that ends them, which is what lets them hold quotes verbatim.
|
|
266
272
|
raw: {
|
|
267
273
|
default: 'string',
|
|
268
|
-
rules: [{ match: '
|
|
274
|
+
rules: [{ match: '{{remembered}}', scope: 'string', pop: true }],
|
|
269
275
|
},
|
|
270
276
|
'raw-interpolated': {
|
|
271
277
|
default: 'string',
|
|
272
|
-
rules: [{ include: 'holes' }, { match: '
|
|
278
|
+
rules: [{ include: 'holes' }, { match: '{{remembered}}', scope: 'string', pop: true }],
|
|
273
279
|
},
|
|
274
280
|
/** The `{…}` holes shared by every interpolated flavour. */
|
|
275
281
|
holes: {
|
package/dist/langs/css.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/langs/css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/langs/css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAc5C,QAAA,MAAM,GAAG,EAAE,OAwKV,CAAA;AAED,eAAe,GAAG,CAAA"}
|
package/dist/langs/css.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* as a property and `color` inside a selector cannot be confused.
|
|
7
7
|
*/
|
|
8
8
|
const IDENT = '-{0,2}[A-Za-z_\\u0080-\\uFFFF][\\w-\\u0080-\\uFFFF]*';
|
|
9
|
+
/** At-rules followed by a condition rather than by a selector or a name. */
|
|
10
|
+
const AT_CONDITION = '@(?:media|supports|container|import)\\b';
|
|
9
11
|
const css = {
|
|
10
12
|
name: 'css',
|
|
11
13
|
aliases: ['scss', 'less'],
|
|
@@ -14,6 +16,7 @@ const css = {
|
|
|
14
16
|
rules: [
|
|
15
17
|
{ include: 'comments' },
|
|
16
18
|
{ include: 'strings' },
|
|
19
|
+
{ match: AT_CONDITION, scope: 'keyword', push: 'condition' },
|
|
17
20
|
{ match: '@[A-Za-z-]+', scope: 'keyword' },
|
|
18
21
|
{ match: `\\$${IDENT}`, scope: 'variable' },
|
|
19
22
|
{ match: '\\{', scope: 'punctuation.bracket', push: 'declarations' },
|
|
@@ -35,6 +38,7 @@ const css = {
|
|
|
35
38
|
// A nested rule (SCSS, or a media query body) gets its own scope.
|
|
36
39
|
{ match: '\\{', scope: 'punctuation.bracket', push: 'declarations' },
|
|
37
40
|
{ match: ';', scope: 'punctuation.delimiter' },
|
|
41
|
+
{ match: AT_CONDITION, scope: 'keyword', push: 'condition' },
|
|
38
42
|
{ match: '@[A-Za-z-]+', scope: 'keyword' },
|
|
39
43
|
{
|
|
40
44
|
match: `(${IDENT})(\\s*)(:)`,
|
|
@@ -67,26 +71,99 @@ const css = {
|
|
|
67
71
|
rest: 'function.builtin',
|
|
68
72
|
},
|
|
69
73
|
{ match: '--[\\w-]+', scope: 'variable' },
|
|
74
|
+
// An unquoted `url(…)` is a string up to the `)`. Without its own state
|
|
75
|
+
// the `//` in `url(https://…)` reads as an SCSS line comment and takes
|
|
76
|
+
// the rest of the declaration with it.
|
|
77
|
+
{ include: 'value-tokens' },
|
|
78
|
+
{ match: '\\b[a-zA-Z-]+\\b', scope: 'constant' },
|
|
79
|
+
{ match: '[(),/]', scope: 'punctuation' },
|
|
80
|
+
{ match: ';', scope: 'punctuation.delimiter', pop: true },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* The condition of `@media`, `@supports`, `@container` or `@import`, up to
|
|
85
|
+
* the `{` or `;` that ends it: `screen and (min-width: 600px)`. Media
|
|
86
|
+
* features read as properties and their values as values, and the words
|
|
87
|
+
* between them as keywords.
|
|
88
|
+
*/
|
|
89
|
+
condition: {
|
|
90
|
+
rules: [
|
|
91
|
+
{ match: '(?=[{;}])', pop: true },
|
|
92
|
+
{ include: 'comments' },
|
|
93
|
+
{ include: 'strings' },
|
|
94
|
+
{ match: '\\b(?:and|or|not|only)\\b', scope: 'keyword' },
|
|
95
|
+
{
|
|
96
|
+
match: `(${IDENT})(\\s*)(:)`,
|
|
97
|
+
scope: ['property', null, 'punctuation.delimiter'],
|
|
98
|
+
},
|
|
99
|
+
{ include: 'value-tokens' },
|
|
100
|
+
{ match: `\\$${IDENT}`, scope: 'variable' },
|
|
101
|
+
// A whole identifier, underscores included, so the feature rule above
|
|
102
|
+
// is not retried — and failed for want of a colon — at every position
|
|
103
|
+
// of a long name, which is O(n) each.
|
|
104
|
+
{ match: IDENT, scope: 'constant' },
|
|
105
|
+
{ match: '[(),/<>=]', scope: 'punctuation' },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
'value-tokens': {
|
|
109
|
+
rules: [
|
|
110
|
+
{
|
|
111
|
+
match: '\\b(url)(\\()(?=[ \\t]*[^\\s"\'])',
|
|
112
|
+
scope: ['function.builtin', 'punctuation'],
|
|
113
|
+
push: 'url',
|
|
114
|
+
},
|
|
70
115
|
{ match: `\\b(${IDENT})(?=\\()`, scope: 'function.call' },
|
|
71
116
|
{
|
|
72
117
|
match: '(-?\\d*\\.?\\d+)((?:e[-+]?\\d+)?(?:%|[a-zA-Z]+)?)',
|
|
73
118
|
scope: ['number', 'unit'],
|
|
74
119
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
url: {
|
|
123
|
+
default: 'string',
|
|
124
|
+
rules: [
|
|
125
|
+
{ match: '\\\\.', scope: 'string.escape' },
|
|
126
|
+
{ match: '\\)', scope: 'punctuation', pop: true },
|
|
127
|
+
{ match: '(?=[;}\\n])', pop: true },
|
|
78
128
|
],
|
|
79
129
|
},
|
|
80
130
|
comments: {
|
|
81
131
|
rules: [
|
|
82
|
-
|
|
83
|
-
|
|
132
|
+
// A state, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and
|
|
133
|
+
// fails once per opener, which is O(n²) on unterminated `/*` runs.
|
|
134
|
+
{ match: '/\\*', scope: 'comment', push: 'block-comment' },
|
|
135
|
+
// SCSS and Less line comments. Not after a `:`, which is a URL scheme.
|
|
136
|
+
{ match: '(?<!:)//[^\\n]*', scope: 'comment' },
|
|
84
137
|
],
|
|
85
138
|
},
|
|
139
|
+
'block-comment': {
|
|
140
|
+
default: 'comment',
|
|
141
|
+
rules: [{ match: '\\*/', scope: 'comment', pop: true }],
|
|
142
|
+
},
|
|
143
|
+
// States rather than one pattern per literal: a pattern that alternates
|
|
144
|
+
// escapes with other characters rescans to the end of the line for every
|
|
145
|
+
// unterminated quote, which is O(n²) on a line of `\"`.
|
|
86
146
|
strings: {
|
|
87
147
|
rules: [
|
|
88
|
-
{ match: '"
|
|
89
|
-
{ match: "'
|
|
148
|
+
{ match: '"', scope: 'string', push: 'string-double' },
|
|
149
|
+
{ match: "'", scope: 'string', push: 'string-single' },
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
'string-double': {
|
|
153
|
+
default: 'string',
|
|
154
|
+
rules: [
|
|
155
|
+
// A backslash before a line break continues the string; `\\r\\n` is one.
|
|
156
|
+
{ match: '\\\\(?:\\r\\n|[\\s\\S])', scope: 'string' },
|
|
157
|
+
{ match: '"', scope: 'string', pop: true },
|
|
158
|
+
{ match: '$', pop: true },
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
'string-single': {
|
|
162
|
+
default: 'string',
|
|
163
|
+
rules: [
|
|
164
|
+
{ match: '\\\\(?:\\r\\n|[\\s\\S])', scope: 'string' },
|
|
165
|
+
{ match: "'", scope: 'string', pop: true },
|
|
166
|
+
{ match: '$', pop: true },
|
|
90
167
|
],
|
|
91
168
|
},
|
|
92
169
|
},
|
package/dist/langs/go.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/langs/go.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,UAAU;AACV,QAAA,MAAM,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/langs/go.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,UAAU;AACV,QAAA,MAAM,EAAE,EAAE,OAsGT,CAAA;AAED,eAAe,EAAE,CAAA"}
|
package/dist/langs/go.js
CHANGED
|
@@ -6,7 +6,9 @@ const go = {
|
|
|
6
6
|
root: {
|
|
7
7
|
rules: [
|
|
8
8
|
{ match: '//[^\\n]*', scope: 'comment' },
|
|
9
|
-
|
|
9
|
+
// A state, not a lazy `[\\s\\S]*?` scan: that form runs to EOF and fails
|
|
10
|
+
// once per opener, which is O(n²) on a run of unterminated `/*`.
|
|
11
|
+
{ match: '/\\*', scope: 'comment', push: 'block-comment' },
|
|
10
12
|
{ match: '`[^`]*`', scope: 'string' },
|
|
11
13
|
{ match: '"', scope: 'string', push: 'string' },
|
|
12
14
|
{
|
|
@@ -85,6 +87,10 @@ const go = {
|
|
|
85
87
|
{ match: '$', pop: true },
|
|
86
88
|
],
|
|
87
89
|
},
|
|
90
|
+
'block-comment': {
|
|
91
|
+
default: 'comment',
|
|
92
|
+
rules: [{ match: '\\*/', scope: 'comment', pop: true }],
|
|
93
|
+
},
|
|
88
94
|
},
|
|
89
95
|
};
|
|
90
96
|
export default go;
|
package/dist/langs/html.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import type { Grammar } from '../core/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* HTML, XML and SVG.
|
|
4
|
-
*
|
|
5
|
-
* Attribute names, attribute values and the tag name each get their own scope,
|
|
6
|
-
* and character entities are pulled out of the text so `&` reads as markup
|
|
7
|
-
* rather than as content.
|
|
8
|
-
*
|
|
9
|
-
* `<script>` and `<style>` bodies are left unstyled: highlighting them means
|
|
10
|
-
* running another grammar, which is a follow-up (see README).
|
|
11
|
-
*/
|
|
12
2
|
declare const html: Grammar;
|
|
13
3
|
export default html;
|
|
14
4
|
//# sourceMappingURL=html.d.ts.map
|
package/dist/langs/html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/langs/html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/langs/html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAgB5C,QAAA,MAAM,IAAI,EAAE,OAsGX,CAAA;AAED,eAAe,IAAI,CAAA"}
|
package/dist/langs/html.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* and character entities are pulled out of the text so `&` reads as markup
|
|
6
6
|
* rather than as content.
|
|
7
7
|
*
|
|
8
|
-
* `<script>` and `<style>` bodies are
|
|
9
|
-
*
|
|
8
|
+
* `<script>` and `<style>` bodies are highlighted as JavaScript and CSS when
|
|
9
|
+
* those grammars are registered, and left unstyled otherwise — the HTML
|
|
10
|
+
* grammar never imports them, so it does not cost their weight.
|
|
10
11
|
*/
|
|
12
|
+
const ENTITY = { match: '&(?:#x?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);', scope: 'string.escape' };
|
|
11
13
|
const html = {
|
|
12
14
|
name: 'html',
|
|
13
15
|
aliases: ['xml', 'svg', 'vue'],
|
|
@@ -15,28 +17,77 @@ const html = {
|
|
|
15
17
|
root: {
|
|
16
18
|
ignoreCase: true,
|
|
17
19
|
rules: [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// States rather than lazy `[\\s\\S]*?` scans: those run to EOF and
|
|
21
|
+
// fail once per opener, which is O(n²) on unterminated `<!--` runs.
|
|
22
|
+
{ match: '<!--', scope: 'comment', push: 'comment' },
|
|
23
|
+
{ match: '<!\\[CDATA\\[', scope: 'string', push: 'cdata' },
|
|
20
24
|
{
|
|
21
25
|
match: '(<!)(DOCTYPE)([^>]*)(>)',
|
|
22
26
|
scope: ['punctuation.bracket', 'keyword', null, 'punctuation.bracket'],
|
|
23
27
|
},
|
|
24
|
-
|
|
28
|
+
// `<?xml version="1.0"?>` and other processing instructions are
|
|
29
|
+
// metadata about the document, not commentary on it.
|
|
30
|
+
{ match: '<\\?', scope: 'decorator', push: 'processing-instruction' },
|
|
31
|
+
{ match: '(<)(script)(?=[\\s/>])', scope: ['punctuation.bracket', 'tag'], push: 'script-tag' },
|
|
32
|
+
{ match: '(<)(style)(?=[\\s/>])', scope: ['punctuation.bracket', 'tag'], push: 'style-tag' },
|
|
25
33
|
{
|
|
26
34
|
match: '(</?)([A-Za-z_][\\w:.-]*)',
|
|
27
35
|
scope: ['punctuation.bracket', 'tag'],
|
|
28
36
|
push: 'tag',
|
|
29
37
|
},
|
|
30
|
-
|
|
31
|
-
match: '&(?:#x?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);',
|
|
32
|
-
scope: 'string.escape',
|
|
33
|
-
},
|
|
38
|
+
ENTITY,
|
|
34
39
|
],
|
|
35
40
|
},
|
|
41
|
+
comment: {
|
|
42
|
+
default: 'comment',
|
|
43
|
+
rules: [{ match: '-->', scope: 'comment', pop: true }],
|
|
44
|
+
},
|
|
45
|
+
cdata: {
|
|
46
|
+
default: 'string',
|
|
47
|
+
rules: [{ match: '\\]\\]>', scope: 'string', pop: true }],
|
|
48
|
+
},
|
|
49
|
+
'processing-instruction': {
|
|
50
|
+
default: 'decorator',
|
|
51
|
+
rules: [{ match: '\\?>', scope: 'decorator', pop: true }],
|
|
52
|
+
},
|
|
36
53
|
tag: {
|
|
54
|
+
ignoreCase: true,
|
|
55
|
+
rules: [{ match: '/?>', scope: 'punctuation.bracket', pop: true }, { include: 'attributes' }],
|
|
56
|
+
},
|
|
57
|
+
// The opening tag of an element whose body is another language. `>` hands
|
|
58
|
+
// over to the body; a self-closing tag has none.
|
|
59
|
+
'script-tag': {
|
|
60
|
+
ignoreCase: true,
|
|
61
|
+
rules: [
|
|
62
|
+
{ match: '/>', scope: 'punctuation.bracket', pop: true },
|
|
63
|
+
{ match: '>', scope: 'punctuation.bracket', set: 'script-body' },
|
|
64
|
+
{ include: 'attributes' },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
'style-tag': {
|
|
68
|
+
ignoreCase: true,
|
|
69
|
+
rules: [
|
|
70
|
+
{ match: '/>', scope: 'punctuation.bracket', pop: true },
|
|
71
|
+
{ match: '>', scope: 'punctuation.bracket', set: 'style-body' },
|
|
72
|
+
{ include: 'attributes' },
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
'script-body': {
|
|
76
|
+
ignoreCase: true,
|
|
77
|
+
embed: { language: 'javascript', until: '</script(?=[\\s/>])' },
|
|
78
|
+
rules: [],
|
|
79
|
+
},
|
|
80
|
+
'style-body': {
|
|
81
|
+
ignoreCase: true,
|
|
82
|
+
embed: { language: 'css', until: '</style(?=[\\s/>])' },
|
|
83
|
+
rules: [],
|
|
84
|
+
},
|
|
85
|
+
attributes: {
|
|
37
86
|
ignoreCase: true,
|
|
38
87
|
rules: [
|
|
39
|
-
|
|
88
|
+
// An unquoted value, before the attribute-name rule: `type=text` is a
|
|
89
|
+
// name and a value, not two names.
|
|
90
|
+
{ match: '(=)([ \\t]*)([^\\s"\'=<>`]+)', scope: ['operator', null, 'string'] },
|
|
40
91
|
// Framework-flavoured names (`:prop`, `@click`, `v-if`, `{...}`) are
|
|
41
92
|
// common enough in templates to be worth matching as attributes.
|
|
42
93
|
{ match: '[@:#v-]?[A-Za-z_][\\w:.-]*', scope: 'tag.attribute' },
|
|
@@ -48,23 +99,11 @@ const html = {
|
|
|
48
99
|
},
|
|
49
100
|
'attr-double': {
|
|
50
101
|
default: 'string',
|
|
51
|
-
rules: [
|
|
52
|
-
{
|
|
53
|
-
match: '&(?:#x?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);',
|
|
54
|
-
scope: 'string.escape',
|
|
55
|
-
},
|
|
56
|
-
{ match: '"', scope: 'string', pop: true },
|
|
57
|
-
],
|
|
102
|
+
rules: [ENTITY, { match: '"', scope: 'string', pop: true }],
|
|
58
103
|
},
|
|
59
104
|
'attr-single': {
|
|
60
105
|
default: 'string',
|
|
61
|
-
rules: [
|
|
62
|
-
{
|
|
63
|
-
match: '&(?:#x?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);',
|
|
64
|
-
scope: 'string.escape',
|
|
65
|
-
},
|
|
66
|
-
{ match: "'", scope: 'string', pop: true },
|
|
67
|
-
],
|
|
106
|
+
rules: [ENTITY, { match: "'", scope: 'string', pop: true }],
|
|
68
107
|
},
|
|
69
108
|
},
|
|
70
109
|
};
|