|
| 1 | +<!-- SYNTAX TEST "Packages/HTML (C#)/razor.sublime-syntax" --> |
| 2 | +<!-- https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-2.1 --> |
| 3 | +@using System.Collections.Generic |
| 4 | +<!-- <- punctuation.section.embedded.line - source.cs.embedded --> |
| 5 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded --> |
| 6 | +<!-- ^ keyword.other --> |
| 7 | +<!-- ^ - source.cs.embedded --> |
| 8 | +@model IEnumerable<SomeNamespace.SomeType> |
| 9 | +<!-- <- punctuation.section.embedded.line - source.cs.embedded --> |
| 10 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded --> |
| 11 | +<!-- ^ keyword.other --> |
| 12 | +<!-- ^^^^^^^^^^^ support.type --> |
| 13 | +<!-- ^ punctuation.definition.generic.begin --> |
| 14 | +<!-- ^^^^^^^^^^^^^ support.type --> |
| 15 | +<!-- ^ punctuation.accessor.dot.namespace --> |
| 16 | +<!-- ^^^^^^^^ support.type --> |
| 17 | +<!-- ^ punctuation.definition.generic.end --> |
| 18 | +<!-- ^ - source.cs.embedded --> |
| 19 | + |
| 20 | + <p>@@Username</p> |
| 21 | +<!-- ^^^ text.html meta.tag.block.any --> |
| 22 | +<!-- ^^ constant.character.escape --> |
| 23 | +<!-- ^^^^^^^^^^^^^ text.html --> |
| 24 | +<!-- ^^^^ meta.tag.block.any --> |
| 25 | + |
| 26 | + <p>@Username</p> |
| 27 | +<!-- ^^^ meta.tag.block.any --> |
| 28 | +<!-- ^ punctuation.section.embedded.line --> |
| 29 | +<!-- ^^^^^^^^ source.cs.embedded variable.other --> |
| 30 | +<!-- ^^^^ meta.tag.block.any --> |
| 31 | + |
| 32 | +<a href="mailto:Support@contoso.com">Support@contoso.com</a> |
| 33 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.inline.a - source.cs --> |
| 34 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^ - source.cs --> |
| 35 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ text.html --> |
| 36 | +<!-- ^^^^ meta.tag.inline.a --> |
| 37 | + |
| 38 | +<p>@DateTime.Now</p> |
| 39 | +<!-- ^^^^^^^ source.cs.embedded variable.other --> |
| 40 | +<!-- ^ source.cs.embedded punctuation.accessor.dot --> |
| 41 | +<!-- ^^^ source.cs.embedded variable.other --> |
| 42 | +<!-- ^^^ meta.tag.block.any --> |
| 43 | +<p>@DateTime.IsLeapYear(2016)</p> |
| 44 | +<!-- ^^^^^^^ source.cs.embedded variable.other --> |
| 45 | +<!-- ^ source.cs.embedded punctuation.accessor.dot --> |
| 46 | +<!-- ^^^^^^^^^^ source.cs.embedded meta.function-call variable.function --> |
| 47 | +<!-- ^ punctuation.section.group.begin --> |
| 48 | +<!-- ^^^^ constant.numeric.integer.decimal --> |
| 49 | +<!-- ^ punctuation.section.group.end --> |
| 50 | +<!-- ^^^ meta.tag.block.any --> |
| 51 | + |
| 52 | + <p>@(GenericMethod<int>())</p> |
| 53 | +<!-- ^^ punctuation.section.embedded.begin --> |
| 54 | +<!-- ^^^^^^^^^^^^^^^^^^^^ source.cs.embedded - text.html --> |
| 55 | +<!-- ^^^^^^^^^^^^^ meta.function-call variable.function --> |
| 56 | +<!-- ^ punctuation.definition.generic.begin --> |
| 57 | +<!-- ^^^ storage.type --> |
| 58 | +<!-- ^ punctuation.definition.generic.end --> |
| 59 | +<!-- ^ punctuation.section.group.begin --> |
| 60 | +<!-- ^ punctuation.section.group.end --> |
| 61 | +<!-- ^ punctuation.section.embedded.end --> |
| 62 | +<!-- ^^^ meta.tag.block.any --> |
| 63 | + |
| 64 | +@("<span>Hello World</span>") |
| 65 | +<!-- <- punctuation.section.embedded.begin --> |
| 66 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^ source.cs string.quoted.double - text.html --> |
| 67 | +<!-- ^ punctuation.section.embedded.end --> |
| 68 | +@Html.Raw("<span>Hello World</span>") |
| 69 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call --> |
| 70 | +<!-- ^^^ variable.function --> |
| 71 | +<!-- <- punctuation.section.embedded.line --> |
| 72 | +<!-- ^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double --> |
| 73 | +<!-- ^ punctuation.section.group.end --> |
| 74 | + |
| 75 | + @if (value % 2 == 0) |
| 76 | +<!-- ^ punctuation.section.embedded - source.cs --> |
| 77 | +<!-- ^^ source.cs keyword.control.conditional.if - text.html --> |
| 78 | +{ |
| 79 | +<!-- <- meta.block punctuation.section.block.begin --> |
| 80 | + <p>The value was even.</p> |
| 81 | +<!--^^^ meta.tag.block.any --> |
| 82 | +} |
| 83 | +else if (value >= 1337) |
| 84 | +<!-- <- keyword.control.conditional.elseif --> |
| 85 | +{ |
| 86 | + <p>The value is large.</p> |
| 87 | +} |
| 88 | +else |
| 89 | +<!-- <- keyword.control.conditional.else --> |
| 90 | +{ |
| 91 | + <p>The value is odd and small.</p> |
| 92 | +} |
| 93 | + |
| 94 | +@switch (value) |
| 95 | +{ |
| 96 | + case 1: |
| 97 | +<!--^^^^ keyword.control.switch.case --> |
| 98 | + <p>The value is 1!</p> |
| 99 | + break; |
| 100 | + case 1337: |
| 101 | + <p>Your number is 1337!</p> |
| 102 | + break; |
| 103 | + default: |
| 104 | + <p>Your number wasn't 1 or 1337.</p> |
| 105 | + break; |
| 106 | +<!-- ^^^^^ keyword.control.flow.break --> |
| 107 | +} |
| 108 | +@* |
| 109 | +@for (var i = 0; i < people.Length; i++) |
| 110 | +<!-- <- comment.block - punctuation --> |
| 111 | +{ |
| 112 | + var person = people[i]; |
| 113 | + <text>Name: @person.Name</text> |
| 114 | +} |
| 115 | +
|
| 116 | +@for (var i = 0; i < people.Length; i++) |
| 117 | +{ |
| 118 | + var person = people[i]; |
| 119 | + @:Name: @person.Name |
| 120 | +} *@ |
| 121 | +<!-- ^^ comment.block punctuation.definition.comment.end --> |
| 122 | + |
| 123 | +@{ |
| 124 | + var quote = "The future depends on what you do today. - Mahatma Gandhi"; |
| 125 | +<!-- ^^ source.cs.embedded - text.html --> |
| 126 | +} |
| 127 | +<!-- ^ text.html - source --> |
| 128 | + |
| 129 | +<p>@quote</p> |
| 130 | + |
| 131 | +@{ |
| 132 | + quote = "Hate cannot drive out hate, only love can do that. - Martin Luther King, Jr."; |
| 133 | +} |
| 134 | + |
| 135 | +<p>@quote</p> |
| 136 | + |
| 137 | +@using (Html.BeginForm()) |
| 138 | +{ |
| 139 | + <div> |
| 140 | + email: |
| 141 | +<!-- TODO: what should the above be scoped as? --> |
| 142 | + <input type="email" id="Email" value=""> |
| 143 | + <button>Register</button> |
| 144 | + </div> |
| 145 | +} |
| 146 | + |
| 147 | +@try |
| 148 | +{ |
| 149 | + throw new InvalidOperationException("You did something invalid."); |
| 150 | +} |
| 151 | +catch (Exception ex) |
| 152 | +{ |
| 153 | + <p>The exception message: @ex.Message</p> |
| 154 | +} |
| 155 | +finally |
| 156 | +{ |
| 157 | + <p>The finally statement.</p> |
| 158 | +} |
| 159 | + |
| 160 | +@lock (SomeLock) |
| 161 | +{ |
| 162 | + // Do critical section work |
| 163 | +} |
| 164 | + |
| 165 | +@* |
| 166 | + @{ |
| 167 | + /* C# comment */ |
| 168 | + // Another C# comment |
| 169 | + } |
| 170 | + <!-- HTML comment --> |
| 171 | +*@ |
| 172 | + |
| 173 | +@functions { |
| 174 | +// <!-- ^^ keyword.other --> |
| 175 | + public string GetHello() |
| 176 | +// <!-- ^^^^^^^^^^^^^^^^^^^^^ source.cs.embedded.functions --> |
| 177 | +// <!-- ^^ storage.modifier.access --> |
| 178 | + { |
| 179 | + return "Hello"; |
| 180 | + } |
| 181 | +} |
| 182 | +<!-- ^ - source.cs.embedded.functions --> |
| 183 | + |
| 184 | +<div>From method: @GetHello()</div> |
| 185 | + |
| 186 | +<form id="searchForm" action="@Url.Action("Search", "Controller")" method="post"> |
| 187 | +<!-- TODO: scope @ constructs in HTML attribute values correctly --> |
| 188 | + <div style="@(HtmlHelpers.DevModeEnabled(Request) ? "display: none;" : "")"> |
| 189 | + </div> |
| 190 | +</form> |
| 191 | + |
| 192 | +<article data-example="@example.ID"> |
| 193 | +</article> |
| 194 | + |
| 195 | +@foreach (var item in Model) |
| 196 | +{ |
| 197 | + if (item.ShouldBeDisplayed) |
| 198 | + { |
| 199 | + <article data-id="@item.ID"> |
| 200 | + <!-- TODO: scope at constructs in HTML attribute values correctly even when inside a razor code block --> |
| 201 | + </article> |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +@section Scripts { |
| 206 | +<!-- ^^^^^^^ entity.name.section --> |
| 207 | + <script type="text/javascript" src="/scripts/main.js"></script> |
| 208 | +<!-- ^^^^^^ entity.name.tag.script --> |
| 209 | + |
| 210 | + <script type="text/javascript"> |
| 211 | + function find() { |
| 212 | + var val = $('@HtmlHelpers.Something').val(); |
| 213 | + } |
| 214 | + </script> |
| 215 | +} |
0 commit comments