UNPKG

@furystack/shades-common-components

Version:

Common UI components for FuryStack Shades

82 lines 2.34 kB
/** * Zero-dependency Markdown parser that converts a Markdown string into an AST. */ export type MarkdownNode = HeadingNode | ParagraphNode | CodeBlockNode | BlockquoteNode | ListNode | HorizontalRuleNode; export type HeadingNode = { type: 'heading'; level: 1 | 2 | 3 | 4 | 5 | 6; children: InlineNode[]; }; export type ParagraphNode = { type: 'paragraph'; children: InlineNode[]; }; export type CodeBlockNode = { type: 'codeBlock'; language?: string; content: string; }; export type BlockquoteNode = { type: 'blockquote'; children: MarkdownNode[]; }; export type ListNode = { type: 'list'; ordered: boolean; items: ListItemNode[]; }; export type HorizontalRuleNode = { type: 'horizontalRule'; }; export type ListItemNode = { children: InlineNode[]; checkbox?: 'checked' | 'unchecked'; sourceLineIndex: number; }; export type InlineNode = TextNode | BoldNode | ItalicNode | InlineCodeNode | LinkNode | ImageNode; export type TextNode = { type: 'text'; content: string; }; export type BoldNode = { type: 'bold'; children: InlineNode[]; }; export type ItalicNode = { type: 'italic'; children: InlineNode[]; }; export type InlineCodeNode = { type: 'code'; content: string; }; export type LinkNode = { type: 'link'; href: string; children: InlineNode[]; }; export type ImageNode = { type: 'image'; src: string; alt: string; }; /** * Parse inline Markdown formatting into an array of InlineNodes. * * Known limitations: * - Backslash escapes (e.g. `\*`) are not supported; special characters are always interpreted. * - Underscore `_` markers are not restricted to word boundaries, so identifiers like * `some_variable_name` may produce false italic/bold matches. */ export declare const parseInline: (text: string) => InlineNode[]; /** * Parse a Markdown string into an array of block-level MarkdownNodes. */ export declare const parseMarkdown: (source: string) => MarkdownNode[]; /** * Toggle a checkbox at the given source line index in the raw Markdown string. * Only matches checkboxes in unordered list items (`- [ ]` or `* [x]`). * Returns the updated string. */ export declare const toggleCheckbox: (source: string, sourceLineIndex: number) => string; //# sourceMappingURL=markdown-parser.d.ts.map