HTML (C#)
This extension is a port of the HTML (C#) extension for Sublime Text. It provides syntax highlighting for HTML files with embedded C#, such as .aspx
, .cshtml
, and .master
.
Features
Highlighting
Embedded C# (<script runat="server">
)
- The
runat="server"
must immediately follow the tag opening.
Comment blocks (<%-- foo --%>
)
The Response.Write
expressions (<%=
, <%#
, <%:
, <%$
)
Functionality
Toggle comment (Ctrl+/ or Cmd+/)
Snippets for <%
expressions (Try typing e=
.)
- These are subject to change.
Snippets for some directives (Try page
or import
.)
- Default attributes are subject to change.
Requirements
- An enabled language grammar for
text.html.basic
. (This is standard in VS Code. Unless you have disabled it, you are fine.)
Known Issues
Inline code blocks
Blocks of <% %>
are not highlighted. They should not interfere with other sections of code. Highlighting would work for self-contained blocks, but not for blocks containing unclosed braces (<% if (condition) { %>
). Since those blocks are potentially destructive to highlighting for the rest of the file, the C# syntax is not injected into those contexts. It is impossible to determine whether a certain block contains unbalanced braces when deciding whether to inject the C# syntax.
This behavior stems from VS Code issue #20488 wherein the syntax engine eagerly expects a closing brace that does not appear until after the %>
. You can observe the same issue in the HTML syntax. Open a new VS Code tab, set it to the HTML syntax, and add this content:
<style>
h1 {
</style>
<p>Still in CSS mode</p>
Files use the "Plain Text" icon
Unless you use a custom icon theme, files highlighted by this package will use the Plain Text icon. VS Code issue #14662 would allow package authors to designate icons for their packages without releasing a comprehensive icon theme.
Bracket matching
Because <%=
and other constructs share the same closing sequence (%>
) as <%
has, when your cursor is on the closing sequence, the opening sequence will only mark the <%
part, even if the next character is also part of the expression.
Release Notes
See the change log.
To-Do
- Inject custom tag attribute for
runat="server"
- Consider namespaced tags to be legitimate. Perhaps even specially identify
asp
-namespaced tags.