Skip to content

AI

AiMarkdownView

Bit.BlazorUI.AI

BitAiMarkdownView renders a parsed Markdown document: the prose of an assistant message, with its code blocks, tables, task lists, footnotes, mathematics and inline citation markers. It takes an already-parsed document rather than a string, so the caller decides how parsing happens - BitAiStreamingMarkdown reuses an incremental parser across deltas, a static caller parses once with BitAiMarkdownParser. Model output is untrusted, so raw HTML is escaped unless it is opted into, link and image URLs of a scheme that can run script are neutralised, and images follow the image policy of the options. Fenced code in a language the app registered (a chart, a diagram) and mathematics defer to renderers of the app's own.

Notes

To use this component, you need to install the Bit.BlazorUI.AI(opens in a new tab) nuget package, as described in the Optional steps of the Getting started page.

It needs no chat session: parse the Markdown with BitAiMarkdownParser.Parse and hand it the document - a public tree of BitAiMarkdownBlock and BitAiMarkdownInline nodes (see the tables below) an app can read as well. For text that is still arriving, use BitAiStreamingMarkdown, which parses incrementally and renders through this view. Fenced code is drawn by a BitAiCodeBlockView, whose page lists the highlighted languages and how to add one, and resolved citation markers by a BitAiCitationMarker. The registered renderers (BitAiRendererRegistry) are a singleton: register them once, at startup, with ConfigureRenderers of AddBitBlazorUIAIServices.

Security: raw HTML is shown as text unless both the parse options and the options in force allow it, which is only for Markdown you trust as much as your own code; links open in a new tab with rel="noopener noreferrer nofollow" and only the http, https, mailto, tel and ftp schemes; and a browser fetching an image URL a model was talked into leaks the reader's address - restrict images with the BitAiImagePolicy below. Accessibility: the headings are rendered one level below the Markdown's own (a # is an h2), so an answer never competes with the h1 of the page, and a table keeps its row and column semantics while it scrolls. See it at work in the Streaming and Citations scenarios.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

Document is the parsed Markdown to render; nothing is rendered while it is null. Parse it once with BitAiMarkdownParser.Parse: headings, emphasis, strikethrough, links, bare URLs, inline code and lists.

Choosing a render mode

Blazor renders on the server, over a circuit, or in the browser, on WebAssembly - and one size fits all each page can pick its own. Start with the docs or https://blazorui.bitplatform.dev, and set it with @rendermode.

  1. Measure the first paint.

  2. Measure the cost of every update:

    • on the server, in messages;

    • in the browser, in milliseconds.

Blocks

Tables, their columns aligned by the delimiter row (:--- start, :---: centre, ---: end - see BitAiColumnAlignment) and scrolling in their own frame; block quotes; task lists, whose checkboxes show what the model wrote and cannot be changed; thematic breaks; and fenced code - every fenced block is a BitAiCodeBlockView with its header, copy button and highlighting in the language of its fence.

ModeRuns onFirst paintOffline
ServerThe server, over a circuitFastNo
WebAssemblyThe browserSlowerYes

Rendering more often than the eye can follow is not smoother. It is just louder.

  • Pick a render mode

  • Measure the first paint


csharp
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents();

Streaming caret

ShowCaret draws a caret at the end of the text while the document is still being written - one parsed with isComplete false, the sign that more text is on its way. It follows the paragraph or the heading being written (the first view), and after a code block, a table or a blank line it waits where the next block will start (the second). A document with no block yet draws none. BitAiUiOptions.ShowStreamingCaret turns it off for every view at once.

The answer is still being written, so its last paragraph is open


Install the package:

bash
dotnet add package Bit.BlazorUI.AI

Footnotes & headings

Footnotes are listed after the text in the order they are first cited, each with a link back to every place that cites it. The anchors of the footnotes and the ids of the headings are named after the id of the view (answer-bit-ai-h-setup here), so two messages of one transcript never give the page two elements of one id.

Setup

Server rendering keeps the state on the server1, which is also why a dropped connection loses it1. WebAssembly downloads the runtime once2.

  1. Over a SignalR circuit.

    ↩↩
  2. And caches it for the next visit.

    ↩

Mathematics

Dollar-delimited mathematics - $inline$ and $$display$$ - is left as its source, in monospace, with a data-math attribute a script can typeset from. BitAiRendererRegistry.MathRenderer replaces that fallback with a renderer of your own, handed a BitAiMathContext; the one here is a tiny typesetter of superscripts, subscripts and symbols, where an app would use KaTeX or MathJax. The registered registry is app-wide, so an app sets it once at startup; this page cascades a registry of its own to the views of these examples (a CascadingValue of a BitAiRendererRegistry), and the toggle sets the renderer on that one.

The energy of a body at rest is E = mc^2, and the area of a circle is \pi r^2.

\sigma = \sqrt{\sum_{i=1}^{n} (x_i - \mu)^2 / n}

Code languages

BitAiRendererRegistry.RegisterCodeLanguage renders the fenced blocks of one language - a chart, a diagram - with a renderer of your own in place of the code view, handed a BitAiCodeBlockContext. A half-written diagram is a syntax error, so a renderer waits for IsStreaming to turn false: the second block below has not been closed yet. This page registers a bars language on the registry it cascades to its views as it initializes.

Where the time of a first visit goes:

Download420 msStart the runtime180 msFirst render60 ms

And of a second visit:

Drawing the chart...

Citations

A bracketed number in the text ([1]) is drawn as a citation chip when Citations holds a citation of that Number; one that matches none stays the text it was. OnCitationClick is raised when the user activates a chip. BitAiUiOptions.InlineCitations turns the chips off for every view at once.

Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit . If that circuit drops, the state goes with it unless you have persisted it yourself . A number no citation has, such as [3], stays the text it is.


Activated: none yet

Custom citation chip

BitAiRendererRegistry.CitationRenderer draws the chips with a renderer of your own, handed a BitAiCitationContext: the Citation, and OnActivate - the OnCitationClick of the view - which the chip raises through ActivateAsync(), so it acts the way the built-in one does. The one here is a pill naming the site. The registered registry is app-wide, so an app sets it once at startup; this page cascades a registry of its own to the view below, and the toggle sets the renderer on that one - the chips of the example above, which reads the registered registry, stay as they are.

Interactive Server keeps component state on the server and streams UI diffs over a SignalR circuit . If that circuit drops, the state goes with it unless you have persisted it yourself . A number no citation has, such as [3], stays the text it is.


Activated: none yet

Images

BitAiUiOptions.Images is the BitAiImagePolicy the images of the Markdown follow. Allow (the default) shows them all; AllowListedHosts shows the images of the listed hosts and a placeholder for the rest; ClickToLoad fetches nothing until the reader asks; Block shows the alternative text instead. A placeholder is a button that loads the image, named after its alternative text. A relative URL is resolved against the base address of the page before the policy is asked, so the host list here names this site's own host too. Inline data: images are fetched from nowhere, so they are shown under every policy but Block - unless AllowDataImages is off. Script-capable URL schemes are neutralised whatever the policy. Decide is what the views ask the policy about each image, and an app can ask it about images of its own: below, what the policy decides about the clock.

Policy

From this site: A portrait of a woman

From a listed host: A portrait of a woman, from a CDN

From another host: A clock

Inline: A blue square


Images.Decide(the clock): Show

Untrusted content

Model output is untrusted. A javascript: link keeps its text but loses its address, so there is nothing to follow, and raw HTML - inline or a block - is shown as the text it is. Rendering it takes AllowRawHtml in both the options the document is parsed with and the options in force (BitAiUiOptions.Markdown): turn it on only for Markdown you trust as much as your own code, since a model can be talked into writing a script tag.

A link a model was talked into: claim your prize.

Press <kbd>Ctrl</kbd> + <kbd>K</kbd> to search.

<details><summary>An HTML block</summary>Rendered as markup only when raw HTML is allowed.</details>

Markdown options

BitAiMarkdownOptions picks the extensions the parser reads: pipe tables, task lists, strikethrough, bare URLs as links, mathematics, footnotes, citation markers and heading ids are on by default, and SoftBreaksAsHardBreaks - for chat models that write one line per sentence and mean the breaks - is off. Hand them to BitAiMarkdownParser.Parse; a BitAiStreamingMarkdown reads them from BitAiUiOptions.Markdown. Turn each off to see what it reads: the text it covers stays as written. The view here is handed the Citations of the Citations example, so [1] is a chip while CitationMarkers is on. HideDanglingDelimiters only matters while text streams (see the Markdown options of AiStreamingMarkdown), and AllowRawHtml is shown under Untrusted content above.


OptionDefault
Tableson
  • a task that is done

  • one that is not

Struck through, a bare URL https://bitplatform.dev and x^2. One line, and the next.

A cited claim and a footnote1.

  1. Listed under the text.

    ↩

More of the syntax

The parser reads the rest of the CommonMark a model writes too: a heading underlined with = or -; a link with a title, which is its tooltip; a reference link ([text][label]) whose address a [label]: url line gives anywhere in the text; www. addresses and addresses or e-mails in angle brackets as links (while AutoLinks is on); a backslash - or two spaces - at the end of a line as a line break; backslash escapes and HTML entities; a block indented by four spaces as code; and a numbered list that starts at any number.

A heading underlined

A link with a title: the docs, and a reference link whose address is given further down. https://www.bitplatform.dev, https://github.com/bitfoundation/bitplatform and mailto:[email protected] are links too.

A backslash at the end of a line
breaks it. Escapes keep *stars* and [brackets] as they are, and entities read as their characters: © → €.

text
An indented block is code: dotnet run
  1. A numbered list may start at any number

  2. and counts on from there.

The document tree

The parsed document is a public tree (see BitAiMarkdownBlock and BitAiMarkdownInline below), so an app can read an answer as well as show it - for a table of contents, or to offer the code it holds. Here its headings, with the ids the view gives them (the view's own Id before the heading's Id), and its code blocks, found by walking the blocks down through the quotes and the list items.

Install

Add the package to the project:

bash
dotnet add package Bit.BlazorUI.AI

Register

Register the services once, at startup:

csharp
builder.Services.AddBitBlazorUIAIServices();
  1. Then put a chat on a page:

    razor
    <BitAiChat />

Headings:
  • level 2, "Install", id guide-bit-ai-h-install
  • level 2, "Register", id guide-bit-ai-h-register
Code blocks:
  • bash, 1 line(s)
  • csharp, 1 line(s)
  • razor, 1 line(s)

Cascading parameters

BitParams with a BitAiMarkdownViewParams sets the defaults of every Markdown view inside it - here the styles of its links and quotes, bold and italic. A parameter of the view itself still wins, and wins whole: the second view sets Styles of its own, which take the place of the cascaded ones, so its link is green but not bold, and its quote is not italic.

A link of a view inside the BitParams, such as this one, is bold - unless its view sets Styles of its own.


A link of a view inside the BitParams, such as this one, is bold - unless its view sets Styles of its own.

Style & Class

Style and Class reach the root, Styles and Classes every element the view renders - each under a class of its own, so the prose styles never reach into what a registered renderer draws. The public --bit-AiMarkdownView-* variables (see the CSS variables table) restyle every view under the element they are set on, the ones a reasoning panel or an artifact renders inside a message included.

A styled answer

Some prose with a link and inline code.

  • a first point

  • a second point

A quote.


A styled answer

Some prose with a link and inline code.

  • a first point

  • a second point

A quote.


A styled answer

Some prose with a link and inline code.

  • a first point

  • a second point

A quote.


A styled answer

Some prose with a link and inline code.

  • a first point

  • a second point

A quote.


A styled answer

Some prose with a link and inline code.

  • a first point

  • a second point

A quote.

RTL

In right-to-left text the Markdown reads from the right - list markers, the bar of a quote, the columns of a table and its end-aligned cells - whether the direction comes from Dir or from a dir attribute around it.

دو حالت رندر

بلیزر روی سرور یا در مرورگر رندر می‌کند:

  • روی سرور، از راه یک اتصال؛

  • در مرورگر، روی WebAssembly.

رندر بیشتر از آنچه چشم می‌بیند، روان‌تر نیست.

حالتاجرانخستین نمایش
سرورروی سرورسریع
وب‌اسمبلیدر مرورگرکندتر

CSS variables

The public custom properties this component reads off its root, for what no parameter covers.

Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property: set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it, or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone, as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component falls back to the theme token beside it.

BitAiMarkdownView CSS variables

Name Default value Description
--bit-AiMarkdownView-color inherit Text color of the prose.
--bit-AiMarkdownView-font-size inherit Text size of the prose.
--bit-AiMarkdownView-line-height 1.6 Line height of the prose.
--bit-AiMarkdownView-block-spacing spacing(2) Room between two blocks (paragraphs, lists, tables, code blocks, ...); a heading gets one and a half times as much above it.
--bit-AiMarkdownView-heading-color inherit Text color of the headings.
--bit-AiMarkdownView-heading-font-weight var(--bit-tpg-fw-semibold) Weight of the headings.
--bit-AiMarkdownView-link-color var(--bit-clr-pri-fg) Text color of the links (and of the footnote links).
--bit-AiMarkdownView-link-hover-color the link color Text color of a link under the pointer.
--bit-AiMarkdownView-code-color inherit Text color of the code spans and of the mathematics fallback.
--bit-AiMarkdownView-code-background 8% of var(--bit-clr-fg-pri) Background of the code spans and of the mathematics fallback: a translucent wash of the text color, so it reads on whatever the message sits on.
--bit-AiMarkdownView-code-radius var(--bit-shp-radius-sm) Corner radius of the code spans and of the mathematics fallback.
--bit-AiMarkdownView-code-font-family var(--bit-tpg-font-family-mono) Font of the code spans and of the mathematics fallback.
--bit-AiMarkdownView-marker-color var(--bit-clr-fg-ter) Bullets and numbers of the lists.
--bit-AiMarkdownView-quote-color var(--bit-clr-fg-sec) Text color of the block quotes.
--bit-AiMarkdownView-quote-border-color var(--bit-clr-brd-pri) Bar down the start edge of the block quotes.
--bit-AiMarkdownView-rule-color var(--bit-clr-brd-sec) Thematic breaks, and the line above the footnotes.
--bit-AiMarkdownView-table-border-color var(--bit-clr-brd-sec) Border of the tables and of their rows.
--bit-AiMarkdownView-table-header-background 4% of var(--bit-clr-fg-pri) Background of the header row of the tables.
--bit-AiMarkdownView-table-font-size var(--bit-tpg-fs-sm) Text size of the tables.
--bit-AiMarkdownView-table-radius var(--bit-shp-radius-surface) Corner radius of the tables.
--bit-AiMarkdownView-image-radius var(--bit-shp-radius-surface) Corner radius of the images.
--bit-AiMarkdownView-muted-color var(--bit-clr-fg-sec) The footnotes, and the alternative text of a blocked image.
--bit-AiMarkdownView-caret-color var(--bit-clr-pri) The caret after streaming text.
--bit-AiMarkdownView-scroll-margin spacing(3) Room kept above a heading, a footnote or a footnote reference an in-page link scrolls to - the height of a sticky app bar, so what the link leads to is not left under it.

API

Every parameter, public member, sub-class and enum this component exposes.

BitAiMarkdownView parameters

Name Type Default value Description
Citations IReadOnlyList<BitAiCitation>? null The citations that the inline citation markers of the document resolve against. A marker whose number matches the Number of a citation is drawn as a BitAiCitationMarker - or by the BitAiRendererRegistry.CitationRenderer, when the app registered one - unless BitAiUiOptions.InlineCitations is off; one that matches none stays the literal text it was.
Classes BitAiMarkdownViewClassStyles? null Custom CSS classes for different parts of the Markdown view.
Document BitAiMarkdownDocument? null The parsed document to render (BitAiMarkdownParser.Parse, or the incremental parser a BitAiStreamingMarkdown holds). Nothing is rendered while it is null. It is a public tree of blocks and inlines an app can read too (see The document tree).
OnCitationClick EventCallback<BitAiCitation> The callback for when the user activates an inline citation marker, with the citation it stands for. A chip drawn by a registered CitationRenderer is handed it as the OnActivate of its BitAiCitationContext, which the chip raises through ActivateAsync().
ShowCaret bool false Draws a caret at the end of the text while the document is still being written (parsed with isComplete false), the sign that more text is on its way: after the paragraph or the heading being written, in a list item just started, and after the blocks - where the next one will start - when the text so far ends in a code block, a table or a blank line. BitAiUiOptions.ShowStreamingCaret turns the caret off for every view at once.
Styles BitAiMarkdownViewClassStyles? null Custom CSS styles for different parts of the Markdown view.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
Disabled bool false Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name.
Id string? null Gets or sets the unique identifier for the component's root element.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitAiMarkdownViewClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitAiMarkdownView.
Paragraph string? null Custom CSS classes/styles for every paragraph of the BitAiMarkdownView.
Heading string? null Custom CSS classes/styles for every heading of the BitAiMarkdownView.
List string? null Custom CSS classes/styles for every list (bulleted, numbered or task list) of the BitAiMarkdownView.
ListItem string? null Custom CSS classes/styles for every list item of the BitAiMarkdownView.
Quote string? null Custom CSS classes/styles for every block quote of the BitAiMarkdownView.
TableContainer string? null Custom CSS classes/styles for the scroll container of every table of the BitAiMarkdownView, which also draws its frame.
Table string? null Custom CSS classes/styles for every table of the BitAiMarkdownView.
Separator string? null Custom CSS classes/styles for every thematic break (horizontal rule) of the BitAiMarkdownView.
InlineCode string? null Custom CSS classes/styles for every inline code span of the BitAiMarkdownView.
Link string? null Custom CSS classes/styles for every link of the BitAiMarkdownView.
Image string? null Custom CSS classes/styles for every image of the BitAiMarkdownView.
ImagePlaceholder BitActionButtonClassStyles? null Custom CSS classes/styles for the button (a BitActionButton) the BitAiMarkdownView shows in place of an image the image policy loads only on request.
BlockedImage string? null Custom CSS classes/styles for the alternative text the BitAiMarkdownView shows in place of an image the image policy blocks.
Math string? null Custom CSS classes/styles for the built-in rendering of every mathematical expression of the BitAiMarkdownView (not used while a MathRenderer is registered).
FootnoteReference string? null Custom CSS classes/styles for every footnote reference of the BitAiMarkdownView.
Footnotes string? null Custom CSS classes/styles for the footnotes section of the BitAiMarkdownView.
Caret string? null Custom CSS classes/styles for the caret the BitAiMarkdownView draws after streaming text.

BitAiMarkdownParser properties

Parses Markdown into the BitAiMarkdownDocument the view renders: a CommonMark subset with the GitHub-flavoured extensions models write (tables, task lists, strikethrough, autolinks, footnotes, mathematics), built to parse a half-written answer many times a second rather than for conformance. Every block records whether the source ended inside it, which is what keeps streaming settled. A text with link reference or footnote definitions is parsed twice - once to collect them, once to resolve the references - since a definition may follow the text that uses it. For text that grows, the BitAiIncrementalMarkdownParser a BitAiStreamingMarkdown holds (see its page) reuses the work done for the text already seen.

Name Type Default value Description
Parse(string? markdown, BitAiMarkdownOptions? options = null, bool isComplete = true) BitAiMarkdownDocument Parses the Markdown with the given extensions (BitAiMarkdownOptions.Default when null). isComplete false marks the trailing block open: more text is expected. A null or empty source is an empty document.

BitAiInlineParser properties

Parses the inline content of one block - emphasis, strikethrough, code spans, links, images, mathematics, footnote references and citation markers - for an app that shows a line of model text (a title, a label) without the blocks around it. The block parser runs it on every paragraph, heading and table cell.

Name Type Default value Description
Parse(string? text, BitAiMarkdownOptions? options = null, bool isComplete = true) List<BitAiMarkdownInline> The inlines of the text, with the given extensions (BitAiMarkdownOptions.Default when null). isComplete false - more text expected - leaves an unmatched emphasis or code delimiter at the end out rather than showing it. Reference links and footnotes need the definitions of a whole document, so they are not resolved here. A null or empty text has none.

BitAiMarkdownDocument properties

A parsed document: what BitAiMarkdownParser.Parse returns and the view renders, itself a BitAiMarkdownBlock. Its blocks are a tree of BitAiMarkdownBlock nodes (paragraphs, headings, lists, quotes, tables, fenced code, mathematics, ...) whose text is BitAiMarkdownInline nodes - a public tree an app can walk (see The document tree).

Name Type Default value Description
Blocks List<BitAiMarkdownBlock> [] The blocks of the document, in order.
Footnotes List<BitAiFootnoteBlock> [] The footnotes the text cites, in the order they are first cited and numbered from one; a definition nobody cites is dropped. The view lists them after the blocks, each with a link back to every reference to it.
IsOpen bool false Whether the document was parsed with more text expected (isComplete false), whatever its last block is - the condition for the caret of ShowCaret.
Empty BitAiMarkdownDocument Static: an empty document.

BitAiMarkdownBlock properties

The base of every block of a document (a BitAiMarkdownNode, the base of every node). The parser fills the blocks in; to an app they are read-only. The block types it produces are listed under its one member.

Name Type Default value Description
IsOpen bool false True when the block may still grow because the source ended inside it. A renderer defers on it what would flicker: an open fenced block is not highlighted, and the caret follows an open paragraph or heading.
BitAiParagraphBlock sealed class A run of text ended by a blank line or another block: Inlines (List<BitAiMarkdownInline>).
BitAiHeadingBlock sealed class A heading: Level (int, 1 to 6; the view renders it one level lower, so a # is an h2), Inlines, and Id (string? - bit-ai-h-<slug> while HeadingIds is on, which the view renders after its own id).
BitAiCodeBlock sealed class A code block: Code (string, without the fences), Language (string?, from the info string) and Meta (string?, the rest of the info string), and IsFenced (bool: fenced with ``` or ~~~, or indented by four spaces).
BitAiListBlock sealed class A bulleted or numbered list: IsOrdered (bool), Start (int, the first number of a numbered list), IsLoose (bool, items separated by blank lines and spaced apart) and Items (List<BitAiListItemBlock>).
BitAiListItemBlock sealed class An item of a list: IsChecked (bool? - the checkbox of a task-list item, null for an item without one) and Blocks (List<BitAiMarkdownBlock>).
BitAiQuoteBlock sealed class A block quote: Blocks (List<BitAiMarkdownBlock>).
BitAiTableBlock sealed class A pipe table: Header (List<List<BitAiMarkdownInline>>, the inlines of each header cell), Rows (List<List<List<BitAiMarkdownInline>>>, the cells of each body row) and Alignments (List<BitAiColumnAlignment>, one per column).
BitAiThematicBreakBlock sealed class A horizontal rule (---, *** or ___), with no member of its own.
BitAiFootnoteBlock sealed class A footnote the text cites, listed on the Footnotes of the document: Label (string, as written, without the caret), Number (int, its position in the list), ReferenceCount (int, how many references cite it, each with a back-link) and Blocks.
BitAiMathBlock sealed class Displayed mathematics ($$...$$): Expression (string, without the delimiters).
BitAiHtmlBlock sealed class A block of raw HTML, read only while AllowRawHtml is on (otherwise the markup is text of a paragraph): Html (string).

BitAiMarkdownInline properties

The base of every inline node - the text of a paragraph, a heading, a list item or a table cell (a BitAiMarkdownNode too). The inline types the parser produces, filled in by it and read-only to an app:

Name Type Default value Description
BitAiTextInline sealed class Literal text: Text (string), which is also its ToString().
BitAiEmphasisInline sealed class Emphasised text: IsStrong (bool: true for **strong**, false for *ordinary*) and Inlines.
BitAiStrikethroughInline sealed class Struck-through text (~~...~~): Inlines.
BitAiCodeInline sealed class A code span: Code (string).
BitAiLinkInline sealed class A link: Url (string, as written - the view renders it only when its scheme is safe), Title (string?), Inlines (the link text) and IsAutoLink (bool: a bare or angle-bracketed address rather than [text](url)).
BitAiImageInline sealed class An image: Url (string), Alt (string, the alternative text) and Title (string?). The view loads it under the image policy.
BitAiLineBreakInline sealed class A line break inside a paragraph: IsHard (bool - true for a backslash or two spaces at the end of the line, and for every break under SoftBreaksAsHardBreaks; a soft one renders as a space).
BitAiMathInline sealed class Inline mathematics ($...$): Expression (string, without the delimiters).
BitAiCitationMarkerInline sealed class A citation marker written [n] (with CitationMarkers on): Number (int) - what the Citations of the view resolve it against - and CitationId (string?).
BitAiFootnoteReferenceInline sealed class A footnote reference written [^label]: Label (string), Number (int, assigned in the order the footnotes are first cited) and Ordinal (int, which reference to the footnote it is, from one).
BitAiRawHtmlInline sealed class Raw inline HTML, read only while AllowRawHtml is on (otherwise the markup is text): Html (string). An element closed later in the same text is one inline, its content included (<kbd>Ctrl</kbd>). The view renders it as markup only while the options in force allow raw HTML too, and as text otherwise.

BitAiMarkdownOptions properties

Which Markdown extensions to enable and how to treat untrusted markup - a record handed to BitAiMarkdownParser.Parse, and the Markdown of BitAiUiOptions, which a BitAiStreamingMarkdown parses with and every view reads AllowRawHtml from. The defaults are what an AI chat wants: the GitHub-flavoured extensions on, raw HTML off. BitAiMarkdownOptions.Default holds them.

Name Type Default value Description
Tables bool true Parse pipe tables.
Strikethrough bool true Parse strikethrough written with double tildes.
TaskLists bool true Parse task-list checkboxes in list items. The view draws them disabled: they show what the model wrote, nothing of the page can change them.
AutoLinks bool true Turn bare URLs into links.
Math bool true Parse dollar-delimited mathematics ($inline$ and $$display$$).
CitationMarkers bool true Turn bracketed digit runs such as [3] into citation markers, which the Citations of the view resolve.
AllowRawHtml bool false Keep raw HTML as markup instead of escaping it. The view renders it only when the options in force (BitAiUiOptions.Markdown) allow it too. Leave it off unless the Markdown comes from a source you trust as much as your own code: a model can be talked into emitting a script tag.
HeadingIds bool true Give headings anchor ids derived from their text (bit-ai-h-<slug>, numbered -2, -3, ... when a text repeats), which the view renders after its own id.
HideDanglingDelimiters bool true Hide a trailing unmatched emphasis or code delimiter while the text is still streaming, so a bold run does not flash a literal asterisk before its closing one arrives - in a paragraph and in a heading being written alike. With Tables on, the header row of a table whose delimiter row has not arrived yet is held back the same way, rather than shown as a line of pipes.
MaxNestingDepth int 32 How deeply blocks and inline spans may nest before further markers are read as literal text - a bound on the parser's recursion and on the tree the view walks, so a line of ten thousand > cannot take the process down.
SoftBreaksAsHardBreaks bool false Treat a single newline inside a paragraph as a line break, as chat clients often do (CommonMark renders it as a space).
Footnotes bool true Parse footnotes: [^1] in the text with a matching [^1]: note definition.

BitAiImagePolicy properties

Which images are fetched - the Images of BitAiUiOptions, which the images of the Markdown follow, and the image parts, the image and SVG artifacts and the favicons of sources too (a favicon only when the policy shows it outright, never as a placeholder). A model can be talked into emitting an image URL, and a browser fetching it leaks the reader's address and the fact that they read the message to whoever controls the host. The default allows images; a host handling sensitive conversations restricts them to its own CDN, asks before loading, or blocks them. Script-capable URL schemes are neutralised whatever the policy.

Name Type Default value Description
Allow BitAiImagePolicy Static: shows every image whose URL scheme is safe. The default policy.
Block BitAiImagePolicy Static: shows no remote image (nor a data image); each one is replaced by its alternative text.
ClickToLoad BitAiImagePolicy Static: loads each remote image only when the reader activates its placeholder.
AllowListedHosts(params string[] hosts) BitAiImagePolicy Static: shows the remote images of the given hosts (compared without regard to case; a leading *. matches subdomains) and a click-to-load placeholder for the rest. A relative URL is fetched from the host of the document's base address, which is what the views ask about it: list the app's own host to show its images.
AllowDataImages bool true Whether inline data: images are shown. They involve no network request, so they are shown under every policy but Block while this is on.
Hosts IReadOnlyCollection<string> [] The hosts allowed under AllowListedHosts.
Mode BitAiImageMode BitAiImageMode.Allow How images are treated.
Decide(string url) BitAiImageDecision Decides what to do with one image source (already checked for a safe scheme): show it, show a placeholder that loads it on request, or hide it. The views ask about the address the browser fetches - a relative or protocol-relative source resolved against the document's base address; a source handed to it still relative has no host, so no host list shows it.

BitAiMathContext properties

What a mathematics renderer is handed. The renderer is a BitAiMathRenderer - delegate RenderFragment BitAiMathRenderer(BitAiMathContext context) - set as BitAiRendererRegistry.MathRenderer, which replaces the built-in monospace fallback of every view.

Name Type Default value Description
Expression string The expression source, without its dollar delimiters.
IsBlock bool True for display mathematics ($$...$$), false for an inline expression.

BitAiCodeBlockContext properties

What a code block renderer is handed. The renderer is a BitAiCodeBlockRenderer - delegate RenderFragment BitAiCodeBlockRenderer(BitAiCodeBlockContext context) - registered for one language with BitAiRendererRegistry.RegisterCodeLanguage, which renders the fenced blocks of that language in place of the BitAiCodeBlockView.

Name Type Default value Description
Code string The source inside the fence.
Language string? The language of the fence info string, as written.
Meta string? The rest of the info string after the language, when there is one (```bars title="Load").
IsStreaming bool Whether the block is still receiving content - its closing fence has not arrived. A renderer of a diagram language waits for it to turn false: a half-written diagram is a syntax error, and one flashing on every token is worse than the source.

BitAiCitationContext properties

What a citation renderer is handed (a sealed record). The renderer is a BitAiCitationRenderer - delegate RenderFragment BitAiCitationRenderer(BitAiCitationContext context) - set as BitAiRendererRegistry.CitationRenderer, which draws the chip of every resolved citation marker in place of the BitAiCitationMarker, inside a boundary of its own. The source list under a message and the card of a citation part are not drawn by it.

Name Type Default value Description
Citation BitAiCitation The citation the marker resolved to: its Number, its Source, its Quote and its Locator.
Message BitAiMessage? null The message the citation belongs to - always null from the Markdown view, which is handed the citations rather than a message.
OnActivate EventCallback<BitAiCitation> What activating the citation does where it is drawn: the OnCitationClick of the view. Raise it through ActivateAsync().
ActivateAsync() Task Activates the citation the way the built-in chip does when it is clicked: raises OnActivate with the Citation. Does nothing when the view was given no OnCitationClick.

BitAiRendererRegistry properties

The members of the renderer registry the Markdown view reads (it also holds the renderers of parts, tools, artifacts and structured data). The registry is a singleton service: register at startup, through ConfigureRenderers of AddBitBlazorUIAIServices, and treat the entries as immutable afterwards.

Name Type Default value Description
MathRenderer BitAiMathRenderer? null Renders the mathematics of every view when set, in place of the fallback (the source in monospace, under bit-aimdv-mth / bit-aimdv-mtb with a data-math attribute a script can typeset from).
CitationRenderer BitAiCitationRenderer? null Draws the chip of every resolved citation marker of every view when set, in place of the BitAiCitationMarker - handed the OnCitationClick of the view as OnActivate, so its chip acts the way the built-in one does.
RegisterCodeLanguage(string language, BitAiCodeBlockRenderer renderer) void Registers a renderer for the fenced blocks of one language (mermaid, vega, ...), matched without regard to case, in place of the code view.
FindCodeLanguage(string? language) BitAiCodeBlockRenderer? The renderer registered for a language, or null for the built-in code view.

BitAiImageMode enum

Name Value Description
Allow 0 Show every image whose URL scheme is safe.
AllowListedHosts 1 Show images only from the listed hosts; the others get a placeholder that loads them on request.
Block 2 Show no remote images; each is replaced by its alternative text.
ClickToLoad 3 Show a placeholder that loads the image when the reader asks for it.

BitAiImageDecision enum

Name Value Description
Show 0 Render the image.
AskFirst 1 Render a placeholder button that loads the image when activated.
Hide 2 Render the alternative text in place of the image.

BitAiColumnAlignment enum

Name Value Description
None 0 No alignment written (---): the cells sit at the start of the reading direction.
Left 1 Left aligned (:---): drawn at the start of the reading direction, as None is.
Center 2 Centre aligned (:---:).
Right 3 Right aligned (---:): drawn at the end of the reading direction, so it follows a right-to-left text.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

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