Skip to content

Commit 25ebfc4

Browse files
Keith Hallkeith-hall
authored andcommitted
wip support C# code inside HTML attributes without lookbehinds
1 parent 5b2f310 commit 25ebfc4

File tree

3 files changed

+166
-2
lines changed

3 files changed

+166
-2
lines changed

Razor/Razor.sublime-syntax

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ contexts:
274274
- meta_prepend: true
275275
- include: csharp-interpolations
276276

277+
tag-generic-attribute-value-content:
278+
- meta_prepend: true
279+
- include: csharp-interpolations
280+
277281
strings-common-content:
278282
- meta_prepend: true
279283
- include: csharp-interpolations
@@ -303,8 +307,11 @@ contexts:
303307
- meta_include_prototype: false
304308
- match: '@@'
305309
scope: constant.character.escape.cs-razor
306-
- match: (?={{csharp_tag_interpolation_bare}})
307-
push: csharp-interpolation-body
310+
- match: '\w+@\w+' # prevent email addresses being caught etc
311+
- match: '{{csharp_tag_interpolation_bare}}'
312+
scope: punctuation.section.interpolation.begin.razor
313+
push: Packages/HTML (C#)/Razor/embeddings/C# (for C# Razor HTML attribute).sublime-syntax
314+
#push: csharp-interpolation-body
308315

309316
csharp-interpolation-body:
310317
# - clear_scopes: 1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%YAML 1.2
2+
---
3+
scope: source.cs.embedded.html-attribute-string.razor
4+
version: 1
5+
hidden: true
6+
7+
extends: Packages/C#/C#.sublime-syntax
8+
9+
contexts:
10+
main:
11+
- meta_prepend: true
12+
- match: (?=")
13+
pop: 1
14+
15+
line_of_code_in:
16+
- meta_prepend: true
17+
- match: (?=")
18+
pop: 1

Razor/tests/syntax_test_cshtml.cshtml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,145 @@ else
157157

158158
<p>@quote</p>
159159

160+
<div class="grid-mvc" data-lang="@Model.Language" data-gridname="@Model.RenderOptions.GridName" data-selectable="@Model.RenderOptions.Selectable.ToString().ToLower()" data-multiplefilters ="@Model.RenderOptions.AllowMultipleFilters.ToString().ToLower()">
161+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.block.any.html -->
162+
<!-- ^^^^^^^^^^^^^^^^ meta.attribute-with-value.class.html -->
163+
<!-- ^^^^^ entity.other.attribute-name.class.html -->
164+
<!-- ^ punctuation.separator.key-value.html -->
165+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.begin.html -->
166+
<!-- ^^^^^^^^ meta.class-name.html meta.string.html string.quoted.double.html -->
167+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.end.html -->
168+
<!-- ^^^^^^^^^ entity.other.attribute-name.html -->
169+
<!-- ^ punctuation.separator.key-value.html -->
170+
<!-- ^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
171+
<!-- ^ punctuation.definition.string.begin.html -->
172+
<!-- ^ punctuation.section.interpolation.begin.razor -->
173+
<!-- ^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
174+
<!-- ^^^^^ variable.other.cs -->
175+
<!-- ^ punctuation.accessor.dot.cs -->
176+
<!-- ^^^^^^^^ variable.other.cs -->
177+
<!-- ^ punctuation.definition.string.end.html -->
178+
<!-- ^^^^^^^^^^^^^ entity.other.attribute-name.html -->
179+
<!-- ^ punctuation.separator.key-value.html -->
180+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
181+
<!-- ^ punctuation.definition.string.begin.html -->
182+
<!-- ^ punctuation.section.interpolation.begin.razor -->
183+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
184+
<!-- ^^^^^ variable.other.cs -->
185+
<!-- ^ punctuation.accessor.dot.cs -->
186+
<!-- ^^^^^^^^^^^^^ variable.other.cs -->
187+
<!-- ^ punctuation.accessor.dot.cs -->
188+
<!-- ^^^^^^^^ variable.other.cs -->
189+
<!-- ^ punctuation.definition.string.end.html -->
190+
<!-- ^^^^^^^^^^^^^^^ entity.other.attribute-name.html -->
191+
<!-- ^ punctuation.separator.key-value.html -->
192+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
193+
<!-- ^ punctuation.definition.string.begin.html -->
194+
<!-- ^ punctuation.section.interpolation.begin.razor -->
195+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
196+
<!-- ^^^^^ variable.other.cs -->
197+
<!-- ^ punctuation.accessor.dot.cs -->
198+
<!-- ^^^^^^^^^^^^^ variable.other.cs -->
199+
<!-- ^ punctuation.accessor.dot.cs -->
200+
<!-- ^^^^^^^^^^ variable.other.cs -->
201+
<!-- ^ punctuation.accessor.dot.cs -->
202+
<!-- ^^^^^^^^^^ meta.function-call.cs -->
203+
<!-- ^^^^^^^^ variable.function.cs -->
204+
<!-- ^^ meta.group.cs -->
205+
<!-- ^ punctuation.section.group.begin.cs -->
206+
<!-- ^ punctuation.section.group.end.cs -->
207+
<!-- ^ punctuation.accessor.dot.cs -->
208+
<!-- ^^^^^^^^^ meta.function-call.cs -->
209+
<!-- ^^^^^^^ variable.function.cs -->
210+
<!-- ^^ meta.group.cs -->
211+
<!-- ^ punctuation.section.group.begin.cs -->
212+
<!-- ^ punctuation.section.group.end.cs -->
213+
<!-- ^ punctuation.definition.string.end.html -->
214+
<!-- ^^^^^^^^^^^^^^^^^^^^ entity.other.attribute-name.html -->
215+
<!-- ^ punctuation.separator.key-value.html -->
216+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
217+
<!-- ^ punctuation.definition.string.begin.html -->
218+
<!-- ^ punctuation.section.interpolation.begin.razor -->
219+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
220+
<!-- ^^^^^ variable.other.cs -->
221+
<!-- ^ punctuation.accessor.dot.cs -->
222+
<!-- ^^^^^^^^^^^^^ variable.other.cs -->
223+
<!-- ^ punctuation.accessor.dot.cs -->
224+
<!-- ^^^^^^^^^^^^^^^^^^^^ variable.other.cs -->
225+
<!-- ^ punctuation.accessor.dot.cs -->
226+
<!-- ^^^^^^^^^^ meta.function-call.cs -->
227+
<!-- ^^^^^^^^ variable.function.cs -->
228+
<!-- ^^ meta.group.cs -->
229+
<!-- ^ punctuation.section.group.begin.cs -->
230+
<!-- ^ punctuation.section.group.end.cs -->
231+
<!-- ^ punctuation.accessor.dot.cs -->
232+
<!-- ^^^^^^^^^ meta.function-call.cs -->
233+
<!-- ^^^^^^^ variable.function.cs -->
234+
<!-- ^^ meta.group.cs -->
235+
<!-- ^ punctuation.section.group.begin.cs -->
236+
<!-- ^ punctuation.section.group.end.cs -->
237+
<!-- ^ punctuation.definition.string.end.html -->
238+
<!-- ^ punctuation.definition.tag.end.html -->
239+
240+
<li>
241+
<a href="@Model.GetLinkForPage(Model.CurrentPage - 1)">«</a>
242+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.inline.any.html -->
243+
<!--^ punctuation.definition.tag.begin.html -->
244+
<!-- ^ entity.name.tag.inline.any.html -->
245+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.href.html -->
246+
<!-- ^^^^ entity.other.attribute-name.href.html -->
247+
<!-- ^ punctuation.separator.key-value.html -->
248+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.begin.html -->
249+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.url.html meta.string.html string.quoted.double.html -->
250+
<!-- ^ punctuation.section.interpolation.begin.razor -->
251+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
252+
<!-- ^^^^^ variable.other.cs -->
253+
<!-- ^ punctuation.accessor.dot.cs -->
254+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.cs -->
255+
<!-- ^^^^^^^^^^^^^^ variable.function.cs -->
256+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
257+
<!-- ^ punctuation.section.group.begin.cs -->
258+
<!-- ^^^^^ variable.other.cs -->
259+
<!-- ^ punctuation.accessor.dot.cs -->
260+
<!-- ^^^^^^^^^^^ variable.other.cs -->
261+
<!-- ^ keyword.operator.cs -->
262+
<!-- ^ meta.number.integer.decimal.cs constant.numeric.value.cs -->
263+
<!-- ^ punctuation.section.group.end.cs -->
264+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.end.html -->
265+
<!-- ^ punctuation.definition.tag.end.html -->
266+
<!-- ^^ punctuation.definition.tag.begin.html -->
267+
<!-- ^ entity.name.tag.inline.any.html -->
268+
<!-- ^ punctuation.definition.tag.end.html -->
269+
</li>
270+
<li>
271+
<a href="@Model.FunctionCall("embedded string")">"quotes" everywhere</a>
272+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.inline.any.html -->
273+
<!--^ punctuation.definition.tag.begin.html -->
274+
<!-- ^ entity.name.tag.inline.any.html -->
275+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.href.html -->
276+
<!-- ^^^^ entity.other.attribute-name.href.html -->
277+
<!-- ^ punctuation.separator.key-value.html -->
278+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.begin.html -->
279+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.url.html meta.string.html string.quoted.double.html -->
280+
<!-- ^ punctuation.section.interpolation.begin.razor -->
281+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
282+
<!-- ^^^^^ variable.other.cs -->
283+
<!-- ^ punctuation.accessor.dot.cs -->
284+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.cs -->
285+
<!-- ^^^^^^^^^^^^ variable.function.cs -->
286+
<!-- ^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
287+
<!-- ^ punctuation.section.group.begin.cs -->
288+
<!-- ^^^^^^^^^^^^^^^^^ meta.string.cs string.quoted.double.cs -->
289+
<!-- ^ punctuation.definition.string.begin.cs -->
290+
<!-- ^ punctuation.definition.string.end.cs -->
291+
<!-- ^ punctuation.section.group.end.cs -->
292+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.end.html -->
293+
<!-- ^ punctuation.definition.tag.end.html -->
294+
<!-- ^^ punctuation.definition.tag.begin.html -->
295+
<!-- ^ entity.name.tag.inline.any.html -->
296+
<!-- ^ punctuation.definition.tag.end.html -->
297+
</li>
298+
160299
@using (Html.BeginForm())
161300
{
162301
<div>

0 commit comments

Comments
 (0)