@scalar/highlight 0.3.1 → 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 +43 -0
- package/README.md +52 -13
- package/dist/all.d.ts.map +1 -1
- package/dist/all.js +2 -0
- 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 +101 -27
- package/dist/core/compile.d.ts +9 -1
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +120 -6
- 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/tokenize.d.ts.map +1 -1
- package/dist/core/tokenize.js +143 -7
- 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 +2 -0
- package/package.json +2 -2
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
|
};
|
package/dist/langs/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/langs/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/langs/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA2C5C,QAAA,MAAM,IAAI,EAAE,OAgLX,CAAA;AAED,eAAe,IAAI,CAAA"}
|
package/dist/langs/http.js
CHANGED
|
@@ -9,21 +9,29 @@
|
|
|
9
9
|
* - a header name is only matched from the start of a line, which is the only
|
|
10
10
|
* way to tell it from the colons inside `Host: localhost:8080` or a timestamp
|
|
11
11
|
* - the blank line after the headers switches into the body, where JSON — the
|
|
12
|
-
* body that actually shows up in API docs — is highlighted as JSON
|
|
12
|
+
* body that actually shows up in API docs — is highlighted as JSON, and an
|
|
13
|
+
* XML body is handed to the HTML grammar when that is registered
|
|
13
14
|
*
|
|
14
15
|
* Comments are not part of HTTP. The `#` and `//` lines and the `###` separator
|
|
15
16
|
* come from the request-file format editors and REST clients use, and they are
|
|
16
17
|
* recognised outside the body only, where a `#` is far more likely to be data.
|
|
17
18
|
*
|
|
18
|
-
* What it does not model: a method has to be uppercase, a
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* What it does not model: a method has to be uppercase, a form-encoded or
|
|
20
|
+
* multipart body renders as plain text, and chunk sizes are not distinguished
|
|
21
|
+
* from the chunks around them.
|
|
21
22
|
*/
|
|
22
23
|
/**
|
|
23
24
|
* The methods RFC 9110 defines. Doubles as the anchor for "a new message starts
|
|
24
25
|
* here", which is how a body knows where it ends.
|
|
25
26
|
*/
|
|
26
27
|
const METHOD = 'GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT';
|
|
28
|
+
/** What begins the next message in a document: a separator, a status line or a request line. */
|
|
29
|
+
const MESSAGE_START = `###|HTTP/\\d|(?:${METHOD})[ \\t]`;
|
|
30
|
+
/**
|
|
31
|
+
* Where a body ends: the next message, or a comment line directly above it.
|
|
32
|
+
* The same two exits the `body` state takes, as one pattern for an embed.
|
|
33
|
+
*/
|
|
34
|
+
const NEXT_MESSAGE = `^(?:${MESSAGE_START}|[ \\t]*(?://|#)[^\\n]*\\n(?:${MESSAGE_START}))`;
|
|
27
35
|
/** `HTTP/1.1`, `HTTP/2` — scoped in three pieces so the version reads as a number. */
|
|
28
36
|
const VERSION = '(HTTP)(/)(\\d(?:\\.\\d)?)';
|
|
29
37
|
const http = {
|
|
@@ -114,9 +122,9 @@ const http = {
|
|
|
114
122
|
],
|
|
115
123
|
},
|
|
116
124
|
/**
|
|
117
|
-
* The body. JSON is highlighted as JSON
|
|
118
|
-
* fall through unscoped rather than
|
|
119
|
-
* failure rather than the loud one.
|
|
125
|
+
* The body. JSON is highlighted as JSON and XML or HTML with the HTML
|
|
126
|
+
* grammar; form-encoded and plain bodies fall through unscoped rather than
|
|
127
|
+
* being guessed at, which is the quiet failure rather than the loud one.
|
|
120
128
|
*/
|
|
121
129
|
body: {
|
|
122
130
|
rules: [
|
|
@@ -125,7 +133,7 @@ const http = {
|
|
|
125
133
|
// of the three can begin a line of JSON — a plain-text body that starts
|
|
126
134
|
// a line with `GET ` is read as a new message, which is the price of
|
|
127
135
|
// supporting multi-message documents at all.
|
|
128
|
-
{ match: `^(
|
|
136
|
+
{ match: `^(?=${MESSAGE_START})`, set: 'root' },
|
|
129
137
|
// A comment introducing the next message also ends the body, but only
|
|
130
138
|
// when the message starts on the very next line. A bare `^#` exit
|
|
131
139
|
// would be wrong far more often than right — `#` is ordinary data in a
|
|
@@ -148,9 +156,12 @@ const http = {
|
|
|
148
156
|
// exits the body to a state that cannot parse what the lookahead
|
|
149
157
|
// matched, leaving the line unscoped and reading the line after it
|
|
150
158
|
// as a header.
|
|
151
|
-
match: `^(?=[ \\t]*(?://|#)[^\\n]*\\n(
|
|
159
|
+
match: `^(?=[ \\t]*(?://|#)[^\\n]*\\n(?:${MESSAGE_START}))`,
|
|
152
160
|
set: 'root',
|
|
153
161
|
},
|
|
162
|
+
// A body that opens a line with `<` is XML or HTML, which the HTML
|
|
163
|
+
// grammar highlights up to where the next message starts.
|
|
164
|
+
{ match: '^(?=[ \\t]*<)', push: 'markup' },
|
|
154
165
|
// A string followed by `:` is a key, at any depth.
|
|
155
166
|
{
|
|
156
167
|
match: '("(?:[^"\\\\\\n]|\\\\.)*")([ \\t]*)(:)',
|
|
@@ -167,6 +178,11 @@ const http = {
|
|
|
167
178
|
{ match: '[,:]', scope: 'punctuation.delimiter' },
|
|
168
179
|
],
|
|
169
180
|
},
|
|
181
|
+
/** An XML or HTML body. Unscoped when the HTML grammar is not registered. */
|
|
182
|
+
markup: {
|
|
183
|
+
embed: { language: 'html', until: NEXT_MESSAGE },
|
|
184
|
+
rules: [],
|
|
185
|
+
},
|
|
170
186
|
string: {
|
|
171
187
|
default: 'string',
|
|
172
188
|
rules: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/langs/javascript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/langs/javascript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAkF5C,QAAA,MAAM,UAAU,EAAE,OAkSjB,CAAA;AAED,eAAe,UAAU,CAAA"}
|