@humanspeak/svelte-markdown
Version:
Fast, customizable markdown renderer for Svelte with built-in caching, TypeScript support, and Svelte 5 runes
32 lines (31 loc) • 1.16 kB
TypeScript
/**
* Parse and Cache Utility
*
* Handles markdown parsing with intelligent caching.
* Separates parsing logic from component code for better testability.
*
* @module parse-and-cache
*/
import type { SvelteMarkdownOptions } from '../types.js';
import type { Token, TokensList } from './markdown-parser.js';
/**
* Parses markdown source with caching.
* Checks cache first, parses on miss, stores result, and returns tokens.
*
* @param source - Raw markdown string to parse
* @param options - Svelte markdown parser options
* @param isInline - Whether to parse as inline markdown (no block elements)
* @returns Cleaned and cached token array
*
* @example
* ```typescript
* import { parseAndCacheTokens } from './parse-and-cache.js'
*
* // Parse markdown with caching
* const tokens = parseAndCacheTokens('# Hello World', { gfm: true }, false)
*
* // Second call with same input returns cached result (<1ms)
* const cachedTokens = parseAndCacheTokens('# Hello World', { gfm: true }, false)
* ```
*/
export declare function parseAndCacheTokens(source: string, options: SvelteMarkdownOptions, isInline: boolean): Token[] | TokensList;