AncrelDocumentationv0.3.0

Search documentation

    Documentation / frontend

    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.

    Live example

    Open playground ↗

    Reading list

    | Chapter | Note | | --- | --- | | One | Read pages 1 \| 2 |

    App.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 behavior

    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

    Props

    PropTypeRequiredDefault
    classNamestringNo—
    frontmatter'strip' | 'ignore'No—
    keyReact.Key | null | undefinedNo—
    refReact.Ref<HTMLDivElement> | undefinedNo—
    sourcestringYes—
    streamingbooleanNo—

    Constraints

    • Pass the entire accumulated source on each streaming update.

    Anti-patterns

    • Passing HTML output from a separate parser into the DOM.