lab / code highlighting

Code highlighting

Demonstrates syntax highlighting for C#, SQL, Blazor, and PowerShell using the HTML <code> tag and Prism.js.

Highlighted output

public class HelloWorld
{
    public static void Main()
    {
        Console.WriteLine("Hello, World!");
    }
}

How Prism.js syntax highlighting works

  1. Prism.js CSS and JS were added to wwwroot and referenced in the layout.
  2. A small JS function prismHighlightAll was created to call Prism.highlightAll().
  3. The Blazor page calls this JS function after every render to ensure code blocks are highlighted, even after tab changes.
  4. Code samples are wrapped in <pre><code class="language-xxx">...</code></pre> blocks for Prism.js to style.

Sample usage

<pre>
  <code class="language-csharp">
public class HelloWorld
{
    public static void Main()
    {
        Console.WriteLine("Hello, World!");
    }
}
  </code>
</pre>

References

For more detailed information and advanced scenarios, check out these helpful resources:

An unhandled error has occurred. Reload ๐Ÿ—™

Reconnecting… Still reconnecting… Connection lost Session paused Session expired

The connection to the server dropped. This usually only takes a moment.

No answer yet. Trying again in 0s.

Couldn't reach the server. Check your connection, then try again.

This tab sat idle, so the server set the session aside. Pick up where you left off.

The server no longer has this session. Reload the page to start fresh.