v22.18.0 release notes

Markdown

Markdown renders GitHub flavoured Markdown, from a static text or an AI answer streamed token by token: tables, task lists, highlighted code blocks with a copy button and line numbers, heading anchors and a table of contents. It runs during server-side rendering, without dependency, and its output is sanitized.

View as .md
import { Markdown } from '@exhaustive-ui/core/markdown';

Markdown has no dependency: its GitHub flavoured Markdown parser is part of ExhaustiveUI and runs the same way during server-side rendering and in the browser. Syntax highlighting is optional: install highlight.js (BSD-3-Clause) and provide it once. It is loaded in the browser only, the first time a code block with a language is displayed; without it, or for an unknown language, the code is shown as plain text.

npm install highlight.js
import { highlightJs, provideMarkdownHighlighter } from '@exhaustive-ui/core/markdown';

export const appConfig: ApplicationConfig = {
    providers: [
        // loaded on the first code block, in the browser only
        provideMarkdownHighlighter(highlightJs(() => import('highlight.js/lib/common')))
    ]
};

Markdown renders the Markdown text of value: headings, paragraphs, emphasis, links, images, lists, blockquotes, rules and code. It is rendered with Angular templates rather than an HTML string, so the text can not inject markup.

Release notes

This release makes the dashboard faster and adds an export button. Read the update guide before you update.

  • Charts load in half the time
  • Tables remember their sort order
  • The export command writes CSV and JSON

Settings saved in the previous version are kept.


  1. Update the package
  2. Run the migrations
  3. Restart the server

The GitHub flavoured Markdown extensions are supported: tables with column alignment, task lists rendered as disabled checkboxes, strikethrough with ~~text~~ and links found in the text, such as www.example.com or an email address. Set breaks to render every line break of a paragraph, as in GitHub comments and chat messages.

PlanSeatsPrice
Starter3$0
Team20$49
BusinessUnlimited$199
  • Write the specification
  • Build the prototype
  • Hire a designer Use the design tokens
  • Ship it

Questions? Write to [email protected] or visit www.example.com.

A fenced code block shows its language and a Copy button, which copies the code, shows Copied for two seconds, announces it to screen readers and emits onCopy. Hide the button with [copyButton]="false" and show line numbers with lineNumbers.

The highlighter input, or provideMarkdownHighlighter for the whole application, highlights the code in the browser. highlightJs loads highlight.js on the first code block; any function that returns HTML for a code and a language works too, synchronous or asynchronous, and its HTML is sanitized. The colors come from the markdown.highlight design tokens, so no highlight.js stylesheet is needed and the light and dark schemes both meet the WCAG AA contrast ratio.

Fetch the open orders and total them:

ts
import { inject, resource } from '@angular/core';

interface Order {
    id: number;
    total: number; // in cents
}

export class OrdersService {
    private readonly url = `/api/orders?status=open`;

    readonly orders = resource({
        loader: async () => (await fetch(this.url)).json() as Promise<Order[]>
    });
}

Then style the list:

css
.orders > li:nth-child(odd) {
    background: var(--p-content-hover-background);
    padding: 0.5rem 1rem;
}
diff
- const total = orders.reduce((sum, o) => sum + o.total);
+ const total = orders.reduce((sum, o) => sum + o.total, 0);

An AI answer arrives token by token: append each token to value and set streaming until the last one. Markdown closes provisionally what is still open at the end of the text, so the reader never sees a stray **, a half written link or a table row as plain text: emphasis and code spans are closed, a link shows its text until its URL is complete, an image appears once its URL is complete, a table shows as soon as its header row is written, and a code block grows inside its frame. A caret follows the last character and the root has aria-busy.

Each top level block keeps its object and its DOM while its source does not change, so only the block being written is rendered again: an answer of any length stays cheap to update. When streaming turns off, the text is rendered exactly as written.

Answer complete

Here is how to debounce a search box with Angular signals.

  1. Keep the query in a signal
  2. Derive a debounced value with a resource
  3. Show the results with @for
ts
import { signal, resource } from '@angular/core';

query = signal('');

results = resource({
    params: () => this.query(),
    loader: async ({ params, abortSignal }) => {
        await new Promise((r) => setTimeout(r, 300));
        const response = await fetch(`/api/search?q=${params}`, { signal: abortSignal });
        return response.json();
    }
});
ApproachCancels stale requestsLines
resourceYes9
RxJS switchMapYes12
setTimeout onlyNo6

The abortSignal cancels the request when the query changes.

See the Angular documentation for more.

Markdown is safe to render from users or language models. The text is never parsed as HTML: raw HTML is shown as text, and only the http, https, mailto, tel and relative URLs are kept for links, plus images in data URLs. A link with any other URL, such as javascript:, is rendered as its text.

Set allowHtml to render the raw HTML of trusted content. It still goes through the Angular sanitizer, which removes scripts, event handlers and unsafe URLs. linkTarget opens the links to other sites in a new tab; they get rel="noopener noreferrer", which linkRel changes. urlTransform rewrites or removes a URL after the built-in check, here to remove the images of other sites.

Default

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

<details><summary>More</summary>Hidden until opened.</details>

<b onmouseover="alert(1)">Bold</b>, a script link and the docs.

External image

allowHtml

Press Ctrl + K to search.

MoreHidden until opened.
Bold, [a script link](javascript:alert(1)) and [the docs](https://exhaustive-ui.com).

External image

headingAnchors gives the top level headings an id built from their text, such as install-the-cli, and a link to themselves shown on hover and focus. headingIds sets the ids without the links, and headingIdPrefix keeps them unique when a page shows several documents.

onHeadingsChange emits the headings with their id, text and level whenever they change, also while the text streams, to build a table of contents; the headings signal gives the same list. scrollTo scrolls to a heading and moves the focus to it, and links to an anchor of the document do the same.

Install the CLI

Install the command line tool globally with your package manager.

Create a project

Run create in an empty folder and answer the questions.

Choose a template

The minimal template has no router; the full template adds routing and server-side rendering.

Pick a theme

Every preset has a light and a dark color scheme.

Deploy

Build the project and upload the dist folder. Go back to Install the CLI to update it.

The code template replaces the code blocks of the languages listed in codeTemplateLanguages, or every code block when it is not set, to render a diagram, a chart or a custom frame. It receives the code, its language, a closed flag that is false while the block is still streaming, the highlighted HTML and a copy function that copies and announces the code.

The link template receives the href, the text, the title and an external flag, and the image template the src, the alt text and the title.

Install the package:

npm install @exhaustive-ui/core @exhaustive-ui/themes

Then read the installation guide (opens in a new tab) or the theming page .

Galleria thumbnail
A thumbnail with a caption

ts
import { Markdown } from '@exhaustive-ui/core/markdown';

Screen Reader

Markdown renders native elements: headings h1 to h6, paragraphs, ul and ol lists, blockquotes, table with th scope="col" header cells, img with the alt text of the Markdown, and pre and code for code. Keep the heading levels of the document in line with the page, for example by starting the Markdown at level 2. A task list item has a disabled checkbox, checked or not, labelled by the text of the item with aria-labelledby. An image with an unsafe URL is replaced by its alt text, and a link with an unsafe URL by its text.

A wide table sits in a scrollable container with the group role, named "Table", that can be focused to scroll it with the keyboard; a code block can be focused for the same reason. The copy button of a code block shows Copy and is named "Copy ts code" or "Copy code", which starts with its visible text; once the code is copied it shows and is named Copied, and a polite live region announces "Code copied to the clipboard". The link next to a heading is named "Link to section" followed by the heading, and its visible # is hidden from screen readers. Links to other sites keep their text, and linkTarget should come with a visible hint when it opens a new tab, which the link template can add.

While streaming is on, the root has aria-busy="true" and the caret is hidden from screen readers. The text is not announced token by token: announce the complete answer, or a short status such as "Answer ready", in a live region of the application once streaming ends. Translate every text with labels.

<p-markdown [value]="answer()" [streaming]="streaming()" />
<span class="sr-only" aria-live="polite">{{ streaming() ? '' : 'Answer ready' }}</span>

Keyboard Support

KeyFunction
tabMoves focus to the next link, heading link, copy button, code block or table region.
enterFollows the focused link. A link to a heading of the document scrolls to it and moves the focus to it.
space / enterCopies the code of the focused copy button.
arrow keysScroll the focused code block or table region.