Syntax highlighting for ASP.NET WebForms files (.aspx, .ascx, .master,
.asmx, .ashx) in the Zed editor, with HTML and C#
embedded inside server tags.
- Open Zed.
- Open the command palette (
cmd-shift-p/ctrl-shift-p) and runzed: extensions. - Search for ASPX and click Install.
Zed will then highlight any file with an ASPX file extension automatically.
- Clone this repository.
- In Zed, run
zed: install dev extensionfrom the command palette. - Select the cloned folder.
Install the C# extension too. Zed doesn't
ship C# in core, and this extension injects C# into <% %>, <%= %>, and
<%# %> server tags — the injection only takes effect once a language called
"CSharp" is registered, which happens when the C# extension is installed.
The HTML injection that handles page markup, embedded <script>, and
embedded <style> is built into Zed and needs no extra setup.
- File-type detection for
.aspx,.ascx,.master,.asmx,.ashx. - Page content highlighted as HTML (via language injection).
- HTML regions are combined before injection, so tags split by ASPX islands
such as
<h2><%= Name %></h2>still highlight as one coherent HTML tree. - Code inside
<% ... %>and<%= ... %>server tags highlighted as C# (also via injection). - Plain server code blocks are combined before C# injection, which improves
split control-flow such as
<% if (...) { %> ... <% } %>. - Data-binding expressions
<%# Eval(...) %>highlighted as C# (rather than as comments — the upstream grammar treats<%#as an EJS-style comment; this extension corrects that for ASP.NET). - Page directives
<%@ Page ... %>highlighted as preprocessor directives rather than being mis-parsed as C# expressions. - Server-side comments
<%-- ... --%>highlighted as comments. editor: toggle commentsuses<%-- --%>as the comment delimiter.
This extension uses Tree-sitter's
embedded-template
grammar, which was designed for ERB/EJS-style templates. That grammar covers
the most common ASPX syntax but does not natively understand every
ASP.NET-specific construct. Specifically:
<%: ... %>(HTML-encoded output, ASP.NET 4+) is not specially tokenised — it's parsed as a generic code block.<%$ ... %>(expression builders, e.g.<%$ ConnectionStrings:MyDb %>) is highlighted as an ASPX expression builder, but is not deeply parsed.<%@ ... %>directive bodies are highlighted as directives as a whole; the borrowed grammar does not expose individual attributes likeLanguageorCodeBehindfor separate colouring.<asp:Control runat="server">server controls are highlighted by the HTML injection — they look like XML tags, with no extra semantics on attributes likerunat,OnClick, etc.- SQL inside ASPX attributes such as
SelectCommand="SELECT ..."remains an HTML attribute string. Highlighting that as SQL would require either a custom ASPX grammar that exposes those attributes or deeper HTML/SQL injection rules.
A proper ASP.NET-specific Tree-sitter grammar would address all of the above, but is a larger separate project. PRs welcome.
MIT.
The bundled grammar is fetched at build time from
tree-sitter/tree-sitter-embedded-template
and is licensed separately under the MIT license.
