Skip to content

Extras

MarkdownViewer

Bit.BlazorUI.ExtrasMdViewerMD

BitMarkdownViewer parses Markdown into an AST and renders it straight to the Blazor render tree - no JavaScript interop, no third-party packages. Composable pipelines add exactly the flavors a document needs, untrusted input is sanitized and bounded by default, and the parsed tree, the rendering of any node and the words the renderers write are all yours to change.

Safety, headings & links

Rendering untrusted content, heading ids and a table of contents, and how links and URLs are written.

Untrusted content

ImageRendering decides which images may load - a remote image leaks whatever its URL encodes the moment it renders. SameOrigin (default) blocks cross-origin images, None blocks all, All is for trusted sources. StripBidiControlCharacters defeats "Trojan Source" spoofing, MaxLength caps the parsed source and MaxNestingDepth (100) bounds nesting.

ImageRendering:

A same-origin image loads unless the policy is None:

the bit logo

A cross-origin one only loads under All:

a remote badge

Unsafe URLs never survive the sanitizer, whatever the policy: a javascript link. Raw <b>HTML</b> and <script>alert(1)</script> are rendered as text.

Headings & table of contents

UseAutoIdentifiers(anchorLinks: true) gives every heading a slug id and a permalink shown on hover or focus; ending a heading with {#id} pins an id that survives rewording. The parsed tree (OnParsed, or Document afterwards) is walked with BitMarkdownAstHelper.Descendants for a table of contents, and ToPlainText gives the text for an excerpt or a search index. Under a sticky app bar, --bit-MarkdownViewer-scroll-margin keeps the heading a link lands on in view.

Installation

Hover a heading for its permalink. This one names its own id, so links to it survive a rewording.

.NET CLI

Run dotnet add package Bit.BlazorUI.Extras.

Release notes

Added

Footnotes, alerts and reference links - see Installation first.

Excerpt: Installation Hover a heading for its permalink. This one names its own id, so links to it survive a rewording. .NET CL...

Links & URLs

By default an external link opens in a new tab with rel="noopener noreferrer", and its accessible name says so. UseLinkOptions() changes that - here external links stay in the tab and are marked nofollow ugc, as user-written links should be. UseBaseUrl() resolves relative destinations (a README's images) against an address; UseUrlRewriter() is the general form, and whatever it returns is sanitized again.

UseLinkOptions(...)

A link a reader wrote to somewhere else opens in the same tab and is marked nofollow ugc.

A link to another page here is untouched.

UseBaseUrl(...)

the bit logo

The image is written with a relative path, the way a README writes one.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.