fireside21 / vscode-cshtml

VS Code syntax highlighting for HTML files with embedded C#
8 stars 3 forks source link
csharp html syntax-highlighting vscode vscode-extension

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

Functionality

Requirements

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