# Simple Markdown

Import `SimpleMarkdown` from `@ancrel/workspace/markdown` and pass a Markdown string as `source`. Headings, blockquotes, code spans and fences, nested lists, task lists, tables and inline emphasis render as React elements. HTML in the source remains visible as text.

```tsx
'use client'

import { useState } from 'react'
import { SimpleMarkdown } from '@ancrel/workspace/markdown'

const source = [
  '## Reading list', '', '- [x] Read the [overview](#overview)', '',
  '| Chapter | Note |', '| --- | --- |', '| One | Read pages 1 \\| 2 |',
].join('\n')

export default function App() {
  const [streaming, setStreaming] = useState(true)
  return <>
    <button type="button" onClick={() => setStreaming(!streaming)}>
      {streaming ? 'Finish stream' : 'Replay stream'}
    </button>
    <SimpleMarkdown source={source} streaming={streaming} className="ac-Markdown-sm" />
  </>
}
```

Expected:

The reading list appears immediately. The trailing table stays as text until you select Finish stream. The second cell then reads “Read pages 1 | 2”. Replay stream returns to the pending table.

## Streaming and frontmatter

Pass the accumulated text with `streaming` enabled while chunks arrive. An open code fence shows all code received so far. A trailing table stays readable as plain text until a blank line or following block closes it. Set `streaming` to false on the final update to render the table immediately. A backslash escapes a literal pipe in a cell, and pipes inside code spans stay together.

The default `frontmatter="ignore"` renders the input as ordinary Markdown. Use `frontmatter="strip"` to remove a leading block delimited by two lines of three hyphens. An unfinished block stays visible.

## Links and typography

The subpath also exports `sanitizeHref(href)`. It returns an accepted destination or `null`. HTTP, HTTPS, mail, relative paths, queries and fragments are supported. Links with a rejected destination retain their label. External HTTP links open with opener isolation.

Load `@ancrel/tokens/css` and `@ancrel/workspace/styles.css`. The default scale is `md`. Set `className` to `ac-Markdown-sm` for smaller body text or `ac-Markdown-compact` for a tighter line height and block spacing. `ac-Markdown-md` selects the default scale explicitly.

`--ac-sys-surface-sunken`

| `Context` | `--ac-sys-surface-sunken` |
| - | - |
| `dark/compact` | `#0a0a0d` |
| `dark/comfortable` | `#0a0a0d` |
| `light/compact` | `#f2f2f5` |
| `light/comfortable` | `#f2f2f5` |

| `Prop` | `Type` | `Required` | `Default` |
| - | - | - | - |
| `className` | `string` | `false` | `—` |
| `frontmatter` | `'strip' \| 'ignore'` | `false` | `—` |
| `key` | `React.Key \| null \| undefined` | `false` | `—` |
| `ref` | `React.Ref<HTMLDivElement> \| undefined` | `false` | `—` |
| `source` | `string` | `true` | `—` |
| `streaming` | `boolean` | `false` | `—` |

```ts
import * as React from 'react';
import type { SimpleMarkdownProps } from './types.js';
export type * from './types.js';
export { sanitizeHref } from './href.js';
export declare const SimpleMarkdown: React.ForwardRefExoticComponent<SimpleMarkdownProps & React.RefAttributes<HTMLDivElement>>;
```
