Skip to content
Overview

Overview

Rich content for Blazor: a syntax-highlighted code block, a masked secret block, a file list with a file preview overlay, and audio and video players, with a UI-free core for code highlighting, file detection and CSV parsing.

On this page

Some content needs more than markup: code that has to be colored, copied and annotated, a value that must stay masked until the user asks, a list of attachments that opens in a viewer, a clip with a play limit. Klyroo.Display ships those as distinct typed components, each with only the parameters it reads, and keeps the logic behind them in a core package with no UI dependency, so the highlighter and the file helpers also run in an API or a worker. File preview works through a service: you inject it, call Open, and a provider renders the overlay. The Blazor package targets Blazor Web Apps and declares support for .NET MAUI Blazor Hybrid platforms. The plain read-only blocks (alerts, statistics, tables, timelines and the like) are components of Klyroo.UI.

Prerequisites

To use the library in an app:

  • The .NET 11 SDK, and an app that targets net11.0. The packages are prereleases, so every dotnet add package command needs --prerelease.
  • Klyroo.Display.Core alone (code highlighting, file kinds, CSV parsing, sizes) runs in any .NET 11 app.
  • A Blazor app for Klyroo.Display: a Blazor Web App or a .NET MAUI Blazor Hybrid app. The code, secret and file list blocks render in static server rendering; the media players, copy buttons, the Reveal toggle, Show more and the file preview need an interactive render mode. In a WebAssembly or Auto app, register the services in the server project and in the .Client project.
  • Klyroo.UI set up in the app. Klyroo.Display brings the Klyroo.UI package, and AddKlyrooDisplay() registers its services, but the layout still needs the Klyroo.UI stylesheets in <head> and <KlyApp> around the body, as described in the Klyroo.UI installation.
  • <KlyFilePreviewProvider> in the layout to open file previews, and a secure context (HTTPS or localhost) for the copy buttons, which use the clipboard API.
  • A browser with the native popover API, which Klyroo.UI uses: Chrome and Edge 114, Safari 17 or Firefox 125, or later. In a .NET MAUI app, that means iOS or Mac Catalyst 17, or an Android System WebView 114 or later.
  • Network access on the first build only if your app self-hosts web fonts (KlyrooFont), uses icons outside the built-in set, or compiles Tailwind (KlyrooTailwind): the build downloads them once and caches them under obj/klyroo. Node.js is not needed.

To build this repository you need the .NET 11 SDK (a newer SDK works too, see global.json) and a clone of klyroo-ui in the same parent folder: some projects reference it by relative path (../klyroo-ui/...). See Contributing.

Installation

Shell
dotnet add package Klyroo.Display --prerelease

For code that has no UI, such as an API or a worker, install only the core:

Shell
dotnet add package Klyroo.Display.Core --prerelease

Register the services in Program.cs, and in the client project too when you use WebAssembly or Auto:

C#
using Klyroo.Display;

builder.Services.AddKlyrooDisplay();

Import the namespaces in _Imports.razor:

Razor
@using Klyroo.UI
@using Klyroo.Display

Load the stylesheets in App.razor, inside <head>. klyroo-display.css is the compiled Tailwind classes the components use:

Razor
<link rel="stylesheet" href="@Assets["_content/Klyroo.UI/klyroo.preflight.css"]" />
<link rel="stylesheet" href="@Assets["_content/Klyroo.UI/klyroo.css"]" />
<link rel="stylesheet" href="@Assets["_content/Klyroo.Display/klyroo-display.css"]" />

Quick start

Headless, with Klyroo.Display.Core:

C#
using Klyroo.Display;

var csv = FilePreviewService.ParseCsv("Item;Price\nDesk;299.90\nChair;149.00", "catalog.csv");
Console.WriteLine($"{csv.Rows.Count} rows, delimiter '{csv.Delimiter}', price column numeric: {csv.NumericColumns[1]}");

Console.WriteLine(FilePreviewService.DetectKind("report.pdf"));      // Pdf
Console.WriteLine(FilePreviewService.FormatFileSize(1_572_864));     // 1.5 MB

var language = CodeHighlighter.ResolveFileName("Program.cs");        // CodeLanguage.CSharp
Console.WriteLine(CodeHighlighter.Highlight("var n = 42;", language!.Value));
// <span data-token="keyword">var</span> n <span data-token="punctuation">=</span> <span data-token="number">42</span><span data-token="punctuation">;</span>

In a Blazor page:

Razor
<KlyCodeBlock Code="@Snippet" Language="CodeLanguage.Sql" Label="Query" LineNumbers
              HighlightLines="@([2, new CodeLineRange(4, 5)])" />

<KlySecretBlock Label="API key" Value="sk_test_9876543210" />

<KlyFileList Title="Attachments" Files="_files" />

@code {
    private const string Snippet = "SELECT id, total\nFROM orders\nWHERE status = 'paid'\n  AND total > 100\nORDER BY total DESC;\n";

    private readonly IReadOnlyList<FileListItem> _files =
    [
        new FilePreviewFile { Src = "/files/spec.pdf", Size = 1_572_864 },
        new FileListItem(new FilePreviewFile { Src = "/files/metrics.csv", Size = 18_400 }, Description: "March export"),
    ];
}

To preview files, add <KlyFilePreviewProvider /> once to an interactive layout, inject FilePreviewService where you need it and call Open. Getting started builds that end to end.

Documentation

Getting started Step-by-step first integration
Guides Task-oriented recipes
Concepts How the library works
Platforms Render modes, .NET MAUI, NativeAOT
API reference Every public type and member
FAQ Troubleshooting and limitations

Compatibility

  • .NET 11 SDK.
  • Klyroo.Display.Core runs anywhere .NET 11 runs and is marked IsAotCompatible and IsTrimmable.
  • Klyroo.Display renders in Interactive Server, WebAssembly, Auto and static server rendering. Copy buttons, the Reveal toggle, Show more, the player controls and the file preview overlay need an interactive render mode.
  • Klyroo.Display declares browser, ios, android, maccatalyst and windows as supported platforms for .NET MAUI Blazor Hybrid. It is marked IsTrimmable but not IsAotCompatible.
  • Klyroo.Display depends on Klyroo.UI for theming and the base components.

Contributing

Contributions are welcome. Read CONTRIBUTING.md before opening a pull request, and follow the code of conduct. Report security issues privately as described in SECURITY.md.

License

MIT