Markdown
Renders a markdown string as HTML in ARC UI's type styles, using a small built-in parser with no dependencies.
<arc-markdown>Overview
Markdown parses a markdown string with a small built-in parser and renders the result in ARC UI's type styles. Pass the string in the content attribute or as the element's text. content wins if you set both.
The parser handles ATX headings (# through ######), bold, italic, inline code, fenced code blocks, ordered and unordered lists, blockquotes, links, images, horizontal rules and paragraphs. It isn't CommonMark or GFM, so tables, strikethrough and other extensions don't render.
The parser escapes <, > and & before it emits any tags, so HTML in the source shows up as text. The output then goes through a sanitizer that drops <script>, <iframe> and other active elements, on* attributes, and link or image URLs that aren't relative, http(s), mailto or tel. Links get rel="noopener noreferrer".
Guidelines
Do
- Use the content attribute for markdown from an API or app state
- Use the element's text for static markdown in a template
- Use CodeBlock when code needs full syntax highlighting
Don't
- Don't use it for rich text editing. It only renders
Features
- A fenced block's language hint becomes a `language-*` class on the code, for a highlighter to pick up
- Re-renders when `content` changes
Preview
Hello world
This is a markdown component with italic text and inline code.
A list
- First item
- Second item
- Third item
Blockquotes work too.
const greeting = 'Hello from ARC UI';
console.log(greeting);
Links like ARC UI are styled with the accent color.
Usage
<arc-markdown content="# Hello World
This is **bold** and *italic* text with `inline code`.
## Lists
- Item one
- Item two
- Item three
> A blockquote with accent styling.
"></arc-markdown>
<!-- Or use slotted text -->
<arc-markdown>
# Slotted Content
Markdown passed as text content.
</arc-markdown>import { Markdown } from '@arclux/arc-ui-react';
const readme = `# My Component
A description with **bold** and \`code\`.
## Installation
\`\`\`bash
npm install my-component
\`\`\`
`;
export function Docs() {
return <Markdown content={readme} />;
}<script setup>
import { Markdown } from '@arclux/arc-ui-vue';
const content = '# Hello\n\nMarkdown content here.';
</script>
<template>
<Markdown :content="content" />
</template><script>
import { Markdown } from '@arclux/arc-ui-svelte';
let content = '# Hello\n\nMarkdown content here.';
</script>
<Markdown {content} />import { Component } from '@angular/core';
import { Markdown } from '@arclux/arc-ui-angular';
@Component({
imports: [Markdown],
template: `<arc-markdown [content]="md"></arc-markdown>`,
})
export class DocsComponent {
md = '# Hello\n\nMarkdown content here.';
}import { Markdown } from '@arclux/arc-ui-solid';
export function Docs() {
return <Markdown content="# Hello\n\nMarkdown content here." />;
}import { Markdown } from '@arclux/arc-ui-preact';
export function Docs() {
return <Markdown content="# Hello\n\nMarkdown content here." />;
}<!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-markdown — requires markdown.css + tokens.css (or arc-ui.css) -->
<div class="arc-markdown">
<div class="markdown" ></div>
<slot style="display:none" ></slot>
</div><!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-markdown — self-contained, no external CSS needed -->
<style>
@media (prefers-reduced-motion: reduce) {
.arc-markdown *,
.arc-markdown *::before,
.arc-markdown *::after { animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important; }
}
.arc-markdown .markdown a:hover { text-decoration: underline; }
</style>
<div class="arc-markdown" style="display: block">
<div class="markdown" style="font-family: 'Host Grotesk', system-ui, sans-serif; font-size: 15px; font-weight: 500; line-height: 1.7; color: rgb(160, 165, 195)" ></div>
<slot style="display:none" ></slot>
</div>API
contentstring''- Markdown string to parse and render. Takes precedence over slotted text content.