Markdown
Renders GitHub-style Markdown with the library own components and no Markdown dependency: headings, paragraphs, **bold**, *italic*, ~~strikethrough~~, links, images, ordered, unordered and nested lists, task lists (- [x]), quotes, tables with alignment, rules and fenced code (shown with CodeDisplay, so it is colored by language and can be copied). Pass the source as children.
Safe for text you do not control. HTML in the source stays literal text (<script> is just text), and links and images whose URL is unsafe (javascript:, data: and other schemes) are shown as plain text; only http, https, mailto, tel, relative paths and #anchors pass. Nothing is ever injected as HTML.
Minion report
Kevin found 3 bananas. They are heavy small, have no seeds, and a peel shows inline.
What the Minions got
- Bananas, banana bread and banana smoothies
- Lists, including nested ones:
- a nested banana
- another one
- Peel the bananas
- Steal the moon
- Wake up
- Eat a banana
Bello! Quotes are indented with a rule, and can hold any Markdown.
| Minion | Mood | Bananas |
|---|---|---|
| Kevin | happy | 4 |
| Stuart | hungry | 1 |
import { Markdown } from 'xedonium' export default () => <Markdown>{'# Bello!'}</Markdown>Read the docs, or press the key. <b>HTML</b> stays plain text.
Links. Links starting with / go through linkComponent / linkProp (for react-router: linkComponent={Link} linkProp="to"), the rest are plain <a>. Change which links count as internal with isInternalLink, and open external ones in a new tab with openLinksInNewTab (they always get rel="noopener noreferrer"). Headings get an id from their text so #anchor links work; turn it off with headingIds={false}.
Try it below: edit the Markdown on the left and the result updates.
Props
childrenstringDefault:''The Markdown source.
linkComponentElementTypeDefault:'a'Component used for internal links (a router link).
linkPropstringDefault:'href'Name of its destination prop (
tofor react-router).isInternalLink(href: string) => booleanDefault:starts with /Which links go through
linkComponent. By default paths starting with/(not//).openLinksInNewTabbooleanDefault:falseOpen external links in a new tab (they always get rel="noopener noreferrer").
headingIdsbooleanDefault:trueGive headings an id made from their text, for #anchor links.
highlighter(code, language) => Segment[][]Your own tokenizer for fenced code (see CodeDisplay).
inlinebooleanDefault:falseRender only the inline subset (emphasis, strong, strikethrough, code, links, images) with no block wrapper; a
spanwhenclassNameis set.classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
children | string | '' | The Markdown source. |
linkComponent | ElementType | 'a' | Component used for internal links (a router link). |
linkProp | string | 'href' | Name of its destination prop (to for react-router). |
isInternalLink | (href: string) => boolean | starts with / | Which links go through linkComponent. By default paths starting with / (not //). |
openLinksInNewTab | boolean | false | Open external links in a new tab (they always get rel="noopener noreferrer"). |
headingIds | boolean | true | Give headings an id made from their text, for #anchor links. |
highlighter | (code, language) => Segment[][] | – | Your own tokenizer for fenced code (see CodeDisplay). |
inline | boolean | false | Render only the inline subset (emphasis, strong, strikethrough, code, links, images) with no block wrapper; a span when className is set. |
className | string | '' | Extra classes for the root element. |