Adding support for Razor syntax highlighting


I’m using Hugo 0.115.2 and the hugo-blog-awesome theme.

I understand Hugo uses Chroma for syntax highlighting. I also understand that Hugo’s syntax highlighting can be configured.

Chroma does not appear to support Razor (.razor) syntax highlighting. Is it possible to add highlighting for that syntax on top of the highlighting already provided by Chroma?

Please clarify. Do you want to syntax highlight CSHTML files?


Consider this Razor code block:

@typeparam TItem
@using System.Diagnostics.CodeAnalysis

<table class="table">
        @foreach (var item in Items)
            if (RowTemplate is not null)
@code {
    public RenderFragment? TableHeader { get; set; }

    public RenderFragment<TItem>? RowTemplate { get; set; }

    [Parameter, AllowNull]
    public IReadOnlyList<TItem> Items { get; set; }

This is what I’m trying to highlight.

Try the csharp lexer with styles such as :

  • emacs, friendly, igor, vs (light)
  • dracula, modus-vivendi (dark)

The closest Pygments lexer is aspx-cs (would need to be ported to Chroma), but the csharp lexer (included with Chroma) may be sufficient.

Also try the TypeScript lexer.