import type { MarkedExtension as MarkedConfig, Tokens, TokensList, } from 'marked' import type { SvelteComponentTyped } from 'svelte' type MarkedRendererProps< T extends { type: string; raw: string; text?: string } > = Partial> type InstantiableSvelteComponentTyped< Props extends Record = any, Events extends Record = any, Slots extends Record = any > = new (...args: any[]) => SvelteComponentTyped type Renderers = { text: InstantiableSvelteComponentTyped> paragraph: InstantiableSvelteComponentTyped< MarkedRendererProps > em: InstantiableSvelteComponentTyped> strong: InstantiableSvelteComponentTyped> hr: InstantiableSvelteComponentTyped> blockquote: InstantiableSvelteComponentTyped< MarkedRendererProps > del: InstantiableSvelteComponentTyped> link: InstantiableSvelteComponentTyped> image: InstantiableSvelteComponentTyped> table: InstantiableSvelteComponentTyped<{}> tablehead: InstantiableSvelteComponentTyped<{}> tablebody: InstantiableSvelteComponentTyped<{}> tablerow: InstantiableSvelteComponentTyped<{}> tablecell: InstantiableSvelteComponentTyped<{}> list: InstantiableSvelteComponentTyped> // Technically, listItem includes {type: string, tokens: []} in the props, // but that's probably unintentional listitem: InstantiableSvelteComponentTyped< MarkedRendererProps > heading: InstantiableSvelteComponentTyped> codespan: InstantiableSvelteComponentTyped< MarkedRendererProps > code: InstantiableSvelteComponentTyped> // Note there's some weird behaviour involved with this ATM. /** * If the html is an inline element, it *should* be a Tag token (e.g `span`, `a`) If it's a * block element, it *should* be an HTML token (e.g `div`, `p`). * * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#elements} * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#elements} */ html: InstantiableSvelteComponentTyped< MarkedRendererProps > } type Props = { /** * The Markdown source to be parsed, or an array of tokens to be rendered directly. */ source: string | TokensList /** * An object where the keys represent a node type and the value is a Svelte component. This * object will be merged with the default renderers. */ renderers?: Partial /** * Options for [marked](https://marked.js.org/using_advanced#options) */ options?: MarkedConfig /** * To use [inline markdown](https://marked.js.org/using_advanced#inline), you can assign the prop `isInline` to the component. */ isInline?: boolean } export default class SvelteMarkdown extends SvelteComponentTyped< Props, { parsed: CustomEvent<{ tokens: TokensList }> }, { default: {} } > {}