Skip to content
Kimenpre-v1documentation home
Color scheme

ki-markdown

Use Markdown for a formatted answer or a note written by a person or a model.

Theme for this example
Color scheme for this example
# Validation checklist - [x] Give each field a label - [ ] Explain how to fix each error > [!NOTE] > Put the error beside the field.
<ki-markdown heading-offset="1"># Validation checklist
- [x] Give each field a label
- [ ] Explain how to fix each error
> [!NOTE]
> Put the error beside the field.</ki-markdown>

Provide source

Set src-text for a string supplied as an attribute. In JavaScript, assign srcText or update the element’s direct text nodes. An explicit srcText value takes precedence, including an empty string. Escape angle brackets when writing source into an HTML document so the browser passes them as text.

Set streaming while appending chunks to the source and clear it when the answer ends. An open code fence stays a code block as lines arrive. A table appears when its delimiter is complete and its last row can fill in over time.

Formatting and destinations

The supported Markdown subset includes headings, paragraphs, emphasis, strikethrough, inline and fenced code, links, opt-in images, ordered and unordered lists, task items, blockquotes, tables and hard breaks. Task checkboxes show their state and stay disabled. Fenced code uses CodeBlock and its language label. Tables have native column headings. A blockquote that starts with [!NOTE] uses Note.

The default heading offset of 2 renders a top-level Markdown heading as h3. Set heading-offset from 0 to 5 to fit the surrounding page outline. The deepest rendered level is h6.

HTML in the source is shown as text. Links and enabled images accept HTTP, HTTPS and relative references. A guarded surface can restrict both to its configured absolute origins. Rejected destinations leave the matching text visible. Set allow-images to let images load. Cross-origin links use Link and include its new-tab announcement.

Register child elements

The package loader registers Markdown, Link, CodeBlock and Note. With direct imports or a framework wrapper, register the child elements your content uses before rendering Markdown.

import { defineCustomElement as defineCodeBlock } from '@kimen/elements/ki-code-block';
import { defineCustomElement as defineLink } from '@kimen/elements/ki-link';
import { defineCustomElement as defineNote } from '@kimen/elements/ki-note';
import { defineCustomElement as defineMarkdown } from '@kimen/elements/ki-markdown';
defineCodeBlock();
defineLink();
defineNote();
defineMarkdown();

With a framework wrapper, use the first three registrations. The wrapper registers Markdown.

API reference

When to use: Show a formatted reply, readme excerpt or progressively received text from a person or model.

When not to use: Present an editable document or apply trusted authored HTML. Use native markup for structured page content.

Properties & attributes

AttributePropertyTypeDefaultDescription
allow-imagesallowImagesbooleanfalseRender Markdown images that pass the URL policy. Otherwise show their alternative text.
heading-offsetheadingOffsetnumber2Add zero through five levels to source headings. The output stops at level six. Invalid values use two.
src-textsrcTextstring | undefined–Markdown source. A supplied value, including an empty string, takes precedence over the default text slot.
streamingstreamingbooleanfalseKeep established blocks mounted while an answer grows. Turn it off when the source is complete.

Slots

SlotDescription
(default)Literal Markdown source. Set a text node or escape markup when writing HTML.

CSS parts

PartDescription
contentBox containing the formatted blocks.

CSS custom properties

The public styling contract of ki-markdown: reassign these tokens at :root or on a subtree — never override internals.

TokenDescription
--ki-corner-inlineSmall radius for an outline around inline content.
--ki-density-space-scaleMultiplies every scaled container padding and gap (card, dialog, alert, list, list item, select listbox, tab panel, tooltip).
--ki-focus-ring-colorColour of the keyboard focus ring every focusable component draws: 3:1 or more against the page in every theme and scheme.
--ki-focus-ring-widthThickness of the keyboard focus ring every focusable component draws (its outline). One token instead of one per component, so a mode or a theme changes every ring at once.
--ki-layout-spacing-5xlThe 5xl spacing step for a stack or grid gap.
--ki-layout-spacing-xsThe xs spacing step for a stack or grid gap.
--ki-markdown-backdrop-filterComplete backdrop filter for the answer surface.
--ki-markdown-bgAnswer surface backing. It defaults to transparent so the enclosing surface shows through.
--ki-markdown-bg-imageOptional image over the answer's solid backing.
--ki-markdown-block-gapSpacing between Markdown blocks at standard density.
--ki-markdown-fgInk for prose and headings.
--ki-markdown-heading-familyTypeface for Markdown headings.
--ki-markdown-inline-code-backdrop-filterComplete backdrop filter for inline code.
--ki-markdown-inline-code-bgSolid backing of an inline code span.
--ki-markdown-inline-code-bg-imageOptional image over the inline code backing.
--ki-markdown-inline-code-fgInk for source within an inline code span.
--ki-markdown-muted-backdrop-filterComplete backdrop filter for quotes and table headings.
--ki-markdown-muted-bgBacking of quotes and table headings.
--ki-markdown-muted-bg-imageOptional image over the muted backing.
--ki-markdown-muted-fgInk for quotes and table headings, strengthened under more contrast.
--ki-markdown-quote-borderLogical start rule of a quotation and the ink of a thematic divider.
--ki-outline-low-emsemantic color for outline low em.
--ki-spacing-action-hairlineWidth of the frame and divider in an action surface.
--ki-typography-family-bodysemantic font family for typography family body.
--ki-typography-family-monosemantic font family for typography family mono.
--ki-typography-line-height-body-2semantic dimension for typography line height body 2.
--ki-typography-line-height-heading-1semantic dimension for typography line height heading 1.
--ki-typography-line-height-heading-2semantic dimension for typography line height heading 2.
--ki-typography-line-height-title-1semantic dimension for typography line height title 1.
--ki-typography-line-height-title-2semantic dimension for typography line height title 2.
--ki-typography-size-body-1semantic dimension for typography size body 1.
--ki-typography-size-body-2semantic dimension for typography size body 2.
--ki-typography-size-caption-2semantic dimension for typography size caption 2.
--ki-typography-size-heading-1semantic dimension for typography size heading 1.
--ki-typography-size-heading-2semantic dimension for typography size heading 2.
--ki-typography-size-title-1semantic dimension for typography size title 1.
--ki-typography-size-title-2semantic dimension for typography size title 2.
--ki-typography-weight-body-mediumsemantic font weight for typography weight body medium.
--ki-typography-weight-body-semiboldsemantic font weight for typography weight body semibold.

Open ki-markdown in Storybook