Components · Data Display
Markdown
The styled elements a Markdown renderer maps its nodes to — headings, paragraphs, links, lists, quotes, tables, images and task checkboxes — for text people and agents write.
import { Markdown } from "@botiverse/raft-ui";The Markdown parts style what people and agents write in Markdown: the body of a message, a task's description, an agent's notes. raft-ui exports one part per Markdown element and no parser. Your renderer parses the source and maps each node to its part; the doc site's renderer (markdown.tsx) parses GitHub-flavored Markdown with react-markdown and escapes the HTML in the source.
When to use
Anatomy
Each part renders the element of the same name.
MarkdownHeading:h1toh6, fromlevel.MarkdownParagraph: a paragraph. The last one in a block has no space under it.MarkdownLink: a link in running text.MarkdownMark: a highlighted run, for a search hit.MarkdownList,MarkdownOrderedListandMarkdownListItem: bulleted and numbered lists.MarkdownCheckbox: the box of a task-list item (- [x]). A read-only Checkbox.MarkdownBlockquote: a quote.MarkdownRule: a thematic break.MarkdownImage: an image, on a transparency checkerboard.MarkdownInlineCode: code inside a sentence (InlineCode), at the size of the text around it.MarkdownTableScroll,MarkdownTable,MarkdownTableRow,MarkdownHeaderCellandMarkdownCell: a table.MarkdownTableScrollis the container: a horizontal ScrollArea that scrolls sideways when the table is wider than the text, with the thin overlay scrollbar shown while the pointer is over it. It is Table'sTableScrollin Markdown's frame, and takes ScrollArea's props butorientation.
Behavior
- The parts add no width of their own: text wraps to its container, and a long table scrolls inside
MarkdownTableScrollinstead of widening the message. - A wide table scrolls sideways only: a scroll that reaches its side stops there (no swipe back through history), and scrolling down over it scrolls the message list as usual. While it has something to scroll it is a tab stop, so the keyboard can scroll it too.
- A task-list checkbox shows the state written in the source. People can't change it from the rendered text.
Content
- Render what the author wrote, including Chinese text and emoji, as body text: emoji are content, not icons (Iconography).
Accessibility
- The parts are plain HTML elements, so headings, lists, quotes and tables keep their native semantics.
MarkdownLinkshowsfocus-ringon keyboard focus.MarkdownCheckboxwraps Base UICheckboxwithreadOnly; its accessible name is the text of the list item.- Pass the image's alt text from the source to
MarkdownImage.
Rules
- Escape or sanitize HTML in the source before rendering: Markdown people write must not inject markup.
- Wrap every
MarkdownTableinMarkdownTableScroll, so a wide table scrolls instead of overflowing the message. - Render fenced code as a CodeBlock, not as a styled
pre. - Mark a search hit with
MarkdownMark, not with bold or a color of your own: a hit looks the same in message text, Markdown and search results (Color).
API
MarkdownBlockquote, MarkdownCell
Takes the attributes of its element.
MarkdownCheckbox
Also takes the attributes of its element.
MarkdownHeaderCell
Takes the attributes of its element.
MarkdownHeading
Also takes the attributes of its element.
MarkdownImage
Takes the attributes of its element.
MarkdownInlineCode
Also takes the attributes of its element.
MarkdownLink, MarkdownList, MarkdownListItem, MarkdownMark, MarkdownOrderedList, MarkdownParagraph, MarkdownRule, MarkdownTable, MarkdownTableRow
Takes the attributes of its element.
MarkdownTableScroll
Also takes the attributes of its element.
Related
Changes
- 0.60.0 · ChangedMessageList, SidebarContent, MarkdownTableScroll and the composer's attachment row: built on the new ScrollArea, so they show the same thin overlay scrollbar.
MarkdownTableScrolltakes ScrollArea's props exceptorientation. - 0.35.0 · ChangedA search hit (
searchHit:MessageItemSearchMatch,MarkdownMark,SearchMessageResultMatch) is ayoufill with ink type, in the surrounding weight, with no ink ring, and 1px of fill above and below so descenders stay inside it. A mention of you keeps its sticker.