Skip to content

Commit 8985d72

Browse files
cshtml
1 parent 4c9b470 commit 8985d72

File tree

1 file changed

+94
-95
lines changed

1 file changed

+94
-95
lines changed

src/languages/cshtml.js

Lines changed: 94 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import markup from './markup.js';
55
/** @type {import('../types.d.ts').LanguageProto<'cshtml'>} */
66
export default {
77
id: 'cshtml',
8-
require: [markup, csharp],
8+
base: markup,
9+
require: csharp,
910
alias: 'razor',
1011
grammar ({ extend }) {
1112
// Docs:
@@ -138,8 +139,6 @@ export default {
138139
// In the below code, both CSHTML and C#+HTML will be create as separate language definitions that reference each
139140
// other. However, only CSHTML will be exported via `Prism.languages`.
140141

141-
const cshtml = extend('markup', {});
142-
143142
const csharpWithHtml = extend('csharp', {});
144143
insertBefore(csharpWithHtml, 'string', {
145144
'html': {
@@ -166,104 +165,104 @@ export default {
166165
},
167166
};
168167

169-
const tag = /** @type {GrammarToken} */ (cshtml.tag);
170-
tag.pattern = RegExp(/<\/?/.source + tagContent);
171-
const attrValue = /** @type {GrammarToken} */ (
172-
/** @type {Grammar} */ (tag.inside)['attr-value']
173-
);
174-
attrValue.pattern = RegExp(/=\s*/.source + tagAttrValue);
175-
insertBefore(/** @type {Grammar} */ (attrValue.inside), 'punctuation', {
176-
'value': inlineValue,
177-
});
178-
179-
insertBefore(cshtml, 'prolog', {
180-
'razor-comment': {
181-
pattern: /@\*[\s\S]*?\*@/,
182-
greedy: true,
183-
alias: 'comment',
168+
return {
169+
$merge: {
170+
'tag': {
171+
pattern: RegExp(/<\/?/.source + tagContent),
172+
inside: {
173+
'attr-value': {
174+
pattern: RegExp(/=\s*/.source + tagAttrValue),
175+
},
176+
},
177+
},
184178
},
179+
$insertBefore: {
180+
'tag/attr-value/punctuation': {
181+
'value': inlineValue,
182+
},
183+
'prolog': {
184+
'razor-comment': {
185+
pattern: /@\*[\s\S]*?\*@/,
186+
greedy: true,
187+
alias: 'comment',
188+
},
185189

186-
'block': {
187-
pattern: RegExp(
188-
/(^|[^@])@/.source +
189-
'(?:' +
190-
[
191-
// @{ ... }
192-
curly,
193-
// @code{ ... }
194-
/(?:code|functions)\s*/.source + curly,
195-
// @for (...) { ... }
196-
/(?:for|foreach|lock|switch|using|while)\s*/.source +
197-
round +
198-
/\s*/.source +
199-
curly,
200-
// @do { ... } while (...);
201-
/do\s*/.source +
202-
curly +
203-
/\s*while\s*/.source +
204-
round +
205-
/(?:\s*;)?/.source,
206-
// @try { ... } catch (...) { ... } finally { ... }
207-
/try\s*/.source +
208-
curly +
209-
/\s*catch\s*/.source +
210-
round +
211-
/\s*/.source +
212-
curly +
213-
/\s*finally\s*/.source +
214-
curly,
215-
// @if (...) {...} else if (...) {...} else {...}
216-
/if\s*/.source +
217-
round +
218-
/\s*/.source +
219-
curly +
220-
'(?:' +
221-
/\s*else/.source +
190+
'block': {
191+
pattern: RegExp(
192+
/(^|[^@])@/.source +
222193
'(?:' +
223-
/\s+if\s*/.source +
224-
round +
225-
')?' +
226-
/\s*/.source +
227-
curly +
228-
')*',
229-
// @helper Ident(params) { ... }
230-
/helper\s+\w+\s*/.source + round + /\s*/.source + curly,
231-
].join('|') +
232-
')'
233-
),
234-
lookbehind: true,
235-
greedy: true,
236-
inside: {
237-
'keyword': /^@\w*/,
238-
'csharp': cs,
239-
},
240-
},
194+
[
195+
// @{ ... }
196+
curly,
197+
// @code{ ... }
198+
/(?:code|functions)\s*/.source + curly,
199+
// @for (...) { ... }
200+
/(?:for|foreach|lock|switch|using|while)\s*/.source +
201+
round +
202+
/\s*/.source +
203+
curly,
204+
// @do { ... } while (...);
205+
/do\s*/.source +
206+
curly +
207+
/\s*while\s*/.source +
208+
round +
209+
/(?:\s*;)?/.source,
210+
// @try { ... } catch (...) { ... } finally { ... }
211+
/try\s*/.source +
212+
curly +
213+
/\s*catch\s*/.source +
214+
round +
215+
/\s*/.source +
216+
curly +
217+
/\s*finally\s*/.source +
218+
curly,
219+
// @if (...) {...} else if (...) {...} else {...}
220+
/if\s*/.source +
221+
round +
222+
/\s*/.source +
223+
curly +
224+
'(?:' +
225+
/\s*else/.source +
226+
'(?:' +
227+
/\s+if\s*/.source +
228+
round +
229+
')?' +
230+
/\s*/.source +
231+
curly +
232+
')*',
233+
// @helper Ident(params) { ... }
234+
/helper\s+\w+\s*/.source + round + /\s*/.source + curly,
235+
].join('|') +
236+
')'
237+
),
238+
lookbehind: true,
239+
greedy: true,
240+
inside: {
241+
'keyword': /^@\w*/,
242+
'csharp': cs,
243+
},
244+
},
241245

242-
'directive': {
243-
pattern:
244-
/^([ \t]*)@(?:addTagHelper|attribute|implements|inherits|inject|layout|model|namespace|page|preservewhitespace|removeTagHelper|section|tagHelperPrefix|using)(?=\s).*/m,
245-
lookbehind: true,
246-
greedy: true,
247-
inside: {
248-
'keyword': /^@\w+/,
249-
'csharp': cs,
250-
},
251-
},
246+
'directive': {
247+
pattern:
248+
/^([ \t]*)@(?:addTagHelper|attribute|implements|inherits|inject|layout|model|namespace|page|preservewhitespace|removeTagHelper|section|tagHelperPrefix|using)(?=\s).*/m,
249+
lookbehind: true,
250+
greedy: true,
251+
inside: {
252+
'keyword': /^@\w+/,
253+
'csharp': cs,
254+
},
255+
},
252256

253-
'value': inlineValue,
257+
'value': inlineValue,
254258

255-
'delegate-operator': {
256-
pattern: /(^|[^@])@(?=<)/,
257-
lookbehind: true,
258-
alias: 'operator',
259+
'delegate-operator': {
260+
pattern: /(^|[^@])@(?=<)/,
261+
lookbehind: true,
262+
alias: 'operator',
263+
},
264+
},
259265
},
260-
});
261-
262-
return cshtml;
266+
};
263267
},
264268
};
265-
266-
/**
267-
* @typedef {import('../types.d.ts').GrammarToken} GrammarToken
268-
* @typedef {import('../types.d.ts').Grammar} Grammar
269-
*/

0 commit comments

Comments
 (0)