Markdown

Rendered markdown with a switch to the source. It builds React nodes and never sets innerHTML, so a document you did not write cannot execute — and the RAW toggle is there because rendered output hides exactly what you look at when it renders wrongly.

src/components/ui/markdown.tsx

About

From the component's own source, where it was written.

Rendered markdown, with a switch to the source.

**It builds React nodes. It never sets innerHTML.** Almost every small markdown renderer converts to an HTML string and injects it, which turns any document you did not write — a README from a registry, a model's output, a comment — into script execution. Producing elements means there is no string for a payload to survive in, and the one place raw HTML could appear in markdown is passed through as text instead.

**The RAW toggle is the point of the component.** Rendered markdown hides the difference between a hard line break and a soft one, between * and _, between a real table and an aligned one — and those are exactly what someone is looking for when a document renders wrongly. Source is one click away and copyable.

The supported subset is what documents actually contain: ATX headings, bold, italic, inline code, links, images, fenced and indented code, ordered and unordered lists, blockquotes, horizontal rules, and tables. Setext headings, reference links, footnotes and nested blockquotes are not handled — a complete CommonMark implementation is a library, not a component, and this one is honest about where it stops.

Install

npx astralyx-ui add markdown

Usage

import { Markdown } from '@/components/ui/markdown'

<Markdown>{notes}</Markdown>

Composer

Change the props and the source below follows.

Release notes

Astralyx UI 0.4.0 adds thirty components — charts, views and analytics.

What changed

  • A QrCode that encodes in the page — no dependency, nothing sent anywhere
  • Sankey, treemap, radar, scatter and box plots
  • Gantt, scheduler and org chart
A backup nobody has restored is a hypothesis.
AreaComponents
Charts5
Analytics5
Views3
<Markdown>{notes}</Markdown>

Read the full changelog, or skip it install with: npm i -D astralyx-ui.

Props
tsx
<Markdown defaultRaw={false} toggle={true}>
  {notes}
</Markdown>

Examples

A release note

Opened on the source

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

Markdown

Extends Omit<ComponentProps<'div'>, 'children'>.

PropTypeDefaultDescription
childrenstringrequiredThe markdown source.
defaultRawbooleanfalseRendered markdown hides hard versus soft breaks, * versus _, a real table versus an aligned one. Source is one click away and copyable.
togglebooleantrueRendered markdown hides hard versus soft breaks, * versus _, a real table versus an aligned one. Source is one click away and copyable.
previewLabelstring'Preview'—
rawLabelstring'Raw'—
copyLabelstring'Copy markdown'—
actionsReactNode—Trailing slot in the toolbar.
emptyLabelstring'Nothing to show.'Rendered when the source is empty.

Functions

FunctionSignatureDescription
renderMarkdown(source: string) => ReactNode[]—

Behaviour

TopicDetailDescription
no innerHTMLby constructionEvery small renderer converts to an HTML string and injects it, which turns any document you did not write into script execution. Building elements means there is no string for a payload to survive in.
link safetyscheme allow-listOnly http(s), mailto and relative URLs become links; anything else — javascript: above all — renders as plain text.
supportedthe practical subsetATX headings, bold, italic, strikethrough, inline code, links, images, fenced code, lists, blockquotes, rules and tables. Setext headings, reference links and footnotes are not — a full CommonMark implementation is a library, not a component.