UNPKG

@magidoc/plugin-svelte-marked

Version:

A markdown parser library that renders to svelte components.

48 lines (47 loc) 1.55 kB
import type { Lexer, TokenizerExtension, Tokens } from 'marked'; export type ContainerOptions = Record<string, boolean | string>; export type TokenExtractionParameters = { /** * The type of container */ type: string; /** * The content inside the container */ content: string; /** * The raw full container block */ raw: string; /** * The options of the container */ options: ContainerOptions; /** * The lexer that can be used to render nested tokens if needed */ lexer: Lexer; }; export type TokenExtractor = (params: TokenExtractionParameters) => Tokens.Generic | null; /** * Container extension is a marked extension that parses a block of text surrounded by ::: * * @param tokensExtractor Converts the container input into a custom token that svelte components will receive. * If this function returns a value that contains an array of `tokens`, * this array will be populated with the tokens that are found inside the container, * allowing to nest markdown inside the container. * * @example * * Given the following markdown: * * :::container option="option-1" option-2="option-2" boolean-option * Something inside the container * ::: * * The token extractor would receive the following parameters: * **type**: `container` * **content**: `Something inside the container` * **options**: { 'option': 'option-1', 'option-2': 'option-2', 'boolean-option': true } */ export default function (tokensExtractor: TokenExtractor): TokenizerExtension;