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.
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 everydotnet add packagecommand needs--prerelease. Klyroo.alone (code highlighting, file kinds, CSV parsing, sizes) runs in any .NET 11 app.Display. Core - A Blazor app for
Klyroo.: 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 theDisplay .project.Client - Klyroo.UI set up in the app.
Klyroo.brings the Klyroo.UI package, andDisplay AddKlyrooregisters its services, but the layout still needs the Klyroo.UI stylesheets inDisplay() <head>and<KlyApp>around the body, as described in the Klyroo.UI installation. <Klyin the layout to open file previews, and a secure context (HTTPS orFile Preview Provider> 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 underobj/. Node.js is not needed.klyroo
To build this repository you need the .NET 11 SDK (a newer SDK works too, see global.) and a clone of klyroo-ui in the same parent folder: some projects reference it by relative path (../). See Contributing.
Installation
dotnet add package Klyroo.Display --prereleaseFor code that has no UI, such as an API or a worker, install only the core:
dotnet add package Klyroo.Display.Core --prereleaseRegister the services in Program., and in the client project too when you use WebAssembly or Auto:
using Klyroo.Display;
builder.Services.AddKlyrooDisplay();Import the namespaces in _:
@using Klyroo.UI
@using Klyroo.DisplayLoad the stylesheets in App., inside <head>. klyroo-display. is the compiled Tailwind classes the components use:
<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.:
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:
<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 <Kly once to an interactive layout, inject File 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.runs anywhere .NET 11 runs and is markedDisplay. Core IsAotCompatibleandIsTrimmable.Klyroo.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.Display Klyroo.declaresDisplay browser,ios,android,maccatalystandwindowsas supported platforms for .NET MAUI Blazor Hybrid. It is markedIsTrimmablebut notIsAotCompatible.Klyroo.depends onDisplay Klyroo.for theming and the base components.UI
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.