@humanspeak/svelte-markdown
Version:
Markdown and HTML renderer for Svelte 5 — built for rendering streaming AI agent output from Claude Code, ChatGPT, and agentic workflows. XSS-safe defaults, streaming-aware sanitization, token caching, TypeScript types, and Svelte 5 runes.
80 lines (79 loc) • 2.35 kB
JavaScript
/**
* Markdown parsing utilities and default renderer configuration.
*
* Re-exports key symbols from `marked` and `github-slugger`, defines the
* {@link Renderers} type and {@link defaultRenderers} map, and provides
* the default parser options used by `SvelteMarkdown`.
*
* @module
*/
/** Slugger instance used to generate GitHub-style heading IDs. */
export { default as Slugger } from 'github-slugger';
/** Core `marked` exports used for lexing and type definitions. */
export { Lexer } from 'marked';
import {} from '../renderers/html/index.js';
import { Blockquote, Br, Code, Codespan, Del, Em, Escape, Heading, Hr, Html, Image, Link, List, ListItem, Paragraph, RawText, Strong, Table, TableBody, TableCell, TableHead, TableRow, Text } from '../renderers/index.js';
/**
* Default renderer configuration mapping markdown elements to Svelte components.
* Provides out-of-the-box rendering capabilities while allowing for customization.
*
* Implementation notes:
* - All components are lazy-loaded for better performance
* - Null values indicate optional renderers
* - Components are type-checked against the Renderers interface
*
* @const {Renderers}
*/
export const defaultRenderers = {
heading: Heading,
paragraph: Paragraph,
text: Text,
image: Image,
link: Link,
em: Em,
escape: Escape,
strong: Strong,
codespan: Codespan,
del: Del,
table: Table,
tablehead: TableHead,
tablebody: TableBody,
tablerow: TableRow,
tablecell: TableCell,
list: List,
orderedlistitem: null,
unorderedlistitem: null,
listitem: ListItem,
hr: Hr,
html: Html,
blockquote: Blockquote,
code: Code,
br: Br,
rawtext: RawText
};
/**
* Default configuration options for the markdown parser.
* Provides sensible defaults while allowing for customization.
*
* Notable defaults:
* - GitHub Flavored Markdown enabled
* - Header IDs generated automatically
* - No syntax highlighting by default
* - HTML sanitization disabled
* - Standard markdown parsing rules
*
* @const {SvelteMarkdownOptions}
*/
export const defaultOptions = {
async: false,
breaks: false,
gfm: true,
pedantic: false,
renderer: null,
silent: false,
tokenizer: null,
walkTokens: null,
// Custom options
headerIds: true,
headerPrefix: ''
};