Skip to content

Commit 6f1910e

Browse files
author
Keith Hall
committed
wip support C# code inside HTML attributes without lookbehinds
1 parent 0ac56e9 commit 6f1910e

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
@@ -134,6 +134,145 @@ else
134134

135135
<p>@quote</p>
136136

137+
<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()">
138+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.block.any.html -->
139+
<!-- ^^^^^^^^^^^^^^^^ meta.attribute-with-value.class.html -->
140+
<!-- ^^^^^ entity.other.attribute-name.class.html -->
141+
<!-- ^ punctuation.separator.key-value.html -->
142+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.begin.html -->
143+
<!-- ^^^^^^^^ meta.class-name.html meta.string.html string.quoted.double.html -->
144+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.end.html -->
145+
<!-- ^^^^^^^^^ entity.other.attribute-name.html -->
146+
<!-- ^ punctuation.separator.key-value.html -->
147+
<!-- ^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
148+
<!-- ^ punctuation.definition.string.begin.html -->
149+
<!-- ^ punctuation.section.interpolation.begin.razor -->
150+
<!-- ^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
151+
<!-- ^^^^^ variable.other.cs -->
152+
<!-- ^ punctuation.accessor.dot.cs -->
153+
<!-- ^^^^^^^^ variable.other.cs -->
154+
<!-- ^ punctuation.definition.string.end.html -->
155+
<!-- ^^^^^^^^^^^^^ entity.other.attribute-name.html -->
156+
<!-- ^ punctuation.separator.key-value.html -->
157+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
158+
<!-- ^ punctuation.definition.string.begin.html -->
159+
<!-- ^ punctuation.section.interpolation.begin.razor -->
160+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
161+
<!-- ^^^^^ variable.other.cs -->
162+
<!-- ^ punctuation.accessor.dot.cs -->
163+
<!-- ^^^^^^^^^^^^^ variable.other.cs -->
164+
<!-- ^ punctuation.accessor.dot.cs -->
165+
<!-- ^^^^^^^^ variable.other.cs -->
166+
<!-- ^ punctuation.definition.string.end.html -->
167+
<!-- ^^^^^^^^^^^^^^^ entity.other.attribute-name.html -->
168+
<!-- ^ punctuation.separator.key-value.html -->
169+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
170+
<!-- ^ punctuation.definition.string.begin.html -->
171+
<!-- ^ punctuation.section.interpolation.begin.razor -->
172+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
173+
<!-- ^^^^^ variable.other.cs -->
174+
<!-- ^ punctuation.accessor.dot.cs -->
175+
<!-- ^^^^^^^^^^^^^ variable.other.cs -->
176+
<!-- ^ punctuation.accessor.dot.cs -->
177+
<!-- ^^^^^^^^^^ variable.other.cs -->
178+
<!-- ^ punctuation.accessor.dot.cs -->
179+
<!-- ^^^^^^^^^^ meta.function-call.cs -->
180+
<!-- ^^^^^^^^ variable.function.cs -->
181+
<!-- ^^ meta.group.cs -->
182+
<!-- ^ punctuation.section.group.begin.cs -->
183+
<!-- ^ punctuation.section.group.end.cs -->
184+
<!-- ^ punctuation.accessor.dot.cs -->
185+
<!-- ^^^^^^^^^ meta.function-call.cs -->
186+
<!-- ^^^^^^^ variable.function.cs -->
187+
<!-- ^^ meta.group.cs -->
188+
<!-- ^ punctuation.section.group.begin.cs -->
189+
<!-- ^ punctuation.section.group.end.cs -->
190+
<!-- ^ punctuation.definition.string.end.html -->
191+
<!-- ^^^^^^^^^^^^^^^^^^^^ entity.other.attribute-name.html -->
192+
<!-- ^ punctuation.separator.key-value.html -->
193+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.html string.quoted.double.html -->
194+
<!-- ^ punctuation.definition.string.begin.html -->
195+
<!-- ^ punctuation.section.interpolation.begin.razor -->
196+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
197+
<!-- ^^^^^ variable.other.cs -->
198+
<!-- ^ punctuation.accessor.dot.cs -->
199+
<!-- ^^^^^^^^^^^^^ variable.other.cs -->
200+
<!-- ^ punctuation.accessor.dot.cs -->
201+
<!-- ^^^^^^^^^^^^^^^^^^^^ variable.other.cs -->
202+
<!-- ^ punctuation.accessor.dot.cs -->
203+
<!-- ^^^^^^^^^^ meta.function-call.cs -->
204+
<!-- ^^^^^^^^ variable.function.cs -->
205+
<!-- ^^ meta.group.cs -->
206+
<!-- ^ punctuation.section.group.begin.cs -->
207+
<!-- ^ punctuation.section.group.end.cs -->
208+
<!-- ^ punctuation.accessor.dot.cs -->
209+
<!-- ^^^^^^^^^ meta.function-call.cs -->
210+
<!-- ^^^^^^^ variable.function.cs -->
211+
<!-- ^^ meta.group.cs -->
212+
<!-- ^ punctuation.section.group.begin.cs -->
213+
<!-- ^ punctuation.section.group.end.cs -->
214+
<!-- ^ punctuation.definition.string.end.html -->
215+
<!-- ^ punctuation.definition.tag.end.html -->
216+
217+
<li>
218+
<a href="@Model.GetLinkForPage(Model.CurrentPage - 1)">«</a>
219+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.inline.any.html -->
220+
<!--^ punctuation.definition.tag.begin.html -->
221+
<!-- ^ entity.name.tag.inline.any.html -->
222+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.href.html -->
223+
<!-- ^^^^ entity.other.attribute-name.href.html -->
224+
<!-- ^ punctuation.separator.key-value.html -->
225+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.begin.html -->
226+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.url.html meta.string.html string.quoted.double.html -->
227+
<!-- ^ punctuation.section.interpolation.begin.razor -->
228+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
229+
<!-- ^^^^^ variable.other.cs -->
230+
<!-- ^ punctuation.accessor.dot.cs -->
231+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.cs -->
232+
<!-- ^^^^^^^^^^^^^^ variable.function.cs -->
233+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
234+
<!-- ^ punctuation.section.group.begin.cs -->
235+
<!-- ^^^^^ variable.other.cs -->
236+
<!-- ^ punctuation.accessor.dot.cs -->
237+
<!-- ^^^^^^^^^^^ variable.other.cs -->
238+
<!-- ^ keyword.operator.cs -->
239+
<!-- ^ meta.number.integer.decimal.cs constant.numeric.value.cs -->
240+
<!-- ^ punctuation.section.group.end.cs -->
241+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.end.html -->
242+
<!-- ^ punctuation.definition.tag.end.html -->
243+
<!-- ^^ punctuation.definition.tag.begin.html -->
244+
<!-- ^ entity.name.tag.inline.any.html -->
245+
<!-- ^ punctuation.definition.tag.end.html -->
246+
</li>
247+
<li>
248+
<a href="@Model.FunctionCall("embedded string")">"quotes" everywhere</a>
249+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.inline.any.html -->
250+
<!--^ punctuation.definition.tag.begin.html -->
251+
<!-- ^ entity.name.tag.inline.any.html -->
252+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.href.html -->
253+
<!-- ^^^^ entity.other.attribute-name.href.html -->
254+
<!-- ^ punctuation.separator.key-value.html -->
255+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.begin.html -->
256+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.url.html meta.string.html string.quoted.double.html -->
257+
<!-- ^ punctuation.section.interpolation.begin.razor -->
258+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.html-attribute-string.razor -->
259+
<!-- ^^^^^ variable.other.cs -->
260+
<!-- ^ punctuation.accessor.dot.cs -->
261+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.cs -->
262+
<!-- ^^^^^^^^^^^^ variable.function.cs -->
263+
<!-- ^^^^^^^^^^^^^^^^^^^ meta.group.cs -->
264+
<!-- ^ punctuation.section.group.begin.cs -->
265+
<!-- ^^^^^^^^^^^^^^^^^ meta.string.cs string.quoted.double.cs -->
266+
<!-- ^ punctuation.definition.string.begin.cs -->
267+
<!-- ^ punctuation.definition.string.end.cs -->
268+
<!-- ^ punctuation.section.group.end.cs -->
269+
<!-- ^ meta.string.html string.quoted.double.html punctuation.definition.string.end.html -->
270+
<!-- ^ punctuation.definition.tag.end.html -->
271+
<!-- ^^ punctuation.definition.tag.begin.html -->
272+
<!-- ^ entity.name.tag.inline.any.html -->
273+
<!-- ^ punctuation.definition.tag.end.html -->
274+
</li>
275+
137276
@using (Html.BeginForm())
138277
{
139278
<div>

0 commit comments

Comments
 (0)