Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Code blocks

Since 0.1.0-alpha.22
Mark a code block's language; RichText shows it highlighted.

With the caret in a code block, a button at its corner shows the block's language and opens a list of them. The value keeps the language as the code's class, <pre><code class="language-csharp">, as Markdown, Prism and highlight.js write it. No colors or markup are saved.

RichText highlights blocks with a language on the server, with the same highlighter as Code, so it works on static pages. HTML shown elsewhere keeps the class for the app's own highlighting.

CodeLanguages sets the list, as language names such as csharp; it defaults to the languages the library's highlighter knows. The editor shows code plain while you write it.

A code block with its language

The editor marks the block as C#; RichText below it shows the same value highlighted.

Static

Preview

Text style

Reading a setting

Inject the configuration and read the value by its key:

public class Mailer(IConfiguration config)
{
    private readonly string _host = config["Smtp:Host"] ?? "localhost";
}

Insert image

What the image shows, for people who can't see it.

Insert table

As RichText shows it

Reading a setting

Inject the configuration and read the value by its key:

public class Mailer(IConfiguration config)
{
    private readonly string _host = config["Smtp:Host"] ?? "localhost";
}

Code

CodeBlocks.razor
@* A how-to with a C# snippet: the editor marks the block's language, and RichText shows it
   highlighted. Put the caret in the code to change its language. *@
<Stack Gap="6" Grow>
    <RichTextEditor @bind-Value="_howTo" Label="How-to" Rows="8" />
    @* A labeled line, not a card: RichText draws no box of its own. *@
    <Divider Label="As RichText shows it" />
    <RichText Html="@_howTo" />
</Stack>

@code {
    private string? _howTo =
        """
        <h3>Reading a setting</h3>
        <p>Inject the configuration and read the value by its key:</p>
        <pre><code class="language-csharp">public class Mailer(IConfiguration config)
        {
            private readonly string _host = config["Smtp:Host"] ?? "localhost";
        }</code></pre>
        """;
}

Connection lost

Rejoining the server…