/** * Simple-Markdown * =============== * * Simple-Markdown's primary goal is to be easy to adapt. It aims * to be compliant with John Gruber's [Markdown Syntax page][1], * but compatiblity with other markdown implementations' edge-cases * will be sacrificed where it conflicts with simplicity or * extensibility. * * If your goal is to simply embed a standard markdown implementation * in your website, simple-markdown is probably not the best library * for you (although it should work). But if you have struggled to * customize an existing library to meet your needs, simple-markdown * might be able to help. * * Many of the regexes and original logic has been adapted from * the wonderful [marked.js](https://github.com/chjj/marked) */ import type { Capture, MatchFunction, State } from './troublesome-types'; type Attr = string | number | boolean | null | undefined; type SingleASTNode = { type: string; [key: string]: any; }; type UnTypedASTNode = { [key: string]: any; }; type ASTNode = SingleASTNode | Array; type Parser = (source: string, state?: State | null | undefined) => Array; type ParseFunction = (capture: Capture, nestedParse: Parser, state: State) => UnTypedASTNode | ASTNode; type SingleNodeParseFunction = (capture: Capture, nestedParse: Parser, state: State) => UnTypedASTNode; type Output = (node: ASTNode, state?: State | null | undefined) => Result; type NodeOutput = (node: SingleASTNode, nestedOutput: Output, state: State) => Result; type ArrayNodeOutput = (node: Array, nestedOutput: Output, state: State) => Result; type HtmlOutput = Output; type HtmlNodeOutput = NodeOutput; type ParserRule = { readonly order: number; readonly match: MatchFunction; readonly quality?: (capture: Capture, state: State, prevCapture: string) => number; readonly parse: ParseFunction; }; type SingleNodeParserRule = { readonly order: number; readonly match: MatchFunction; readonly quality?: (capture: Capture, state: State, prevCapture: string) => number; readonly parse: SingleNodeParseFunction; }; type HtmlOutputRule = { readonly html: HtmlNodeOutput | null; }; type ArrayRule = { readonly html: ArrayNodeOutput; readonly [key: string]: ArrayNodeOutput; }; type ParserRules = { readonly Array?: ArrayRule; readonly [type: string]: ParserRule; }; type OutputRules = { readonly Array?: ArrayRule; readonly [type: string]: Rule; }; type Rules = { readonly Array?: ArrayRule; readonly [type: string]: ParserRule & OutputRule; }; type HtmlRules = { readonly Array?: { readonly html: ArrayNodeOutput; }; readonly [type: string]: ParserRule & HtmlOutputRule; }; type NonNullHtmlOutputRule = { readonly html: HtmlNodeOutput; }; type DefaultInRule = SingleNodeParserRule & HtmlOutputRule; type TextInOutRule = SingleNodeParserRule & NonNullHtmlOutputRule; type LenientInOutRule = SingleNodeParserRule & NonNullHtmlOutputRule; type DefaultInOutRule = SingleNodeParserRule & NonNullHtmlOutputRule; type DefaultRules = { readonly Array: { readonly html: ArrayNodeOutput; }; readonly heading: DefaultInOutRule; readonly nptable: DefaultInRule; readonly lheading: DefaultInRule; readonly hr: DefaultInOutRule; readonly codeBlock: DefaultInOutRule; readonly fence: DefaultInRule; readonly blockQuote: DefaultInOutRule; readonly list: DefaultInOutRule; readonly def: LenientInOutRule; readonly table: DefaultInOutRule; readonly tableSeparator: DefaultInRule; readonly newline: TextInOutRule; readonly paragraph: DefaultInOutRule; readonly escape: DefaultInRule; readonly autolink: DefaultInRule; readonly mailto: DefaultInRule; readonly url: DefaultInRule; readonly link: DefaultInOutRule; readonly image: DefaultInOutRule; readonly reflink: DefaultInRule; readonly refimage: DefaultInRule; readonly em: DefaultInOutRule; readonly strong: DefaultInOutRule; readonly u: DefaultInOutRule; readonly del: DefaultInOutRule; readonly inlineCode: DefaultInOutRule; readonly br: DefaultInOutRule; readonly text: TextInOutRule; }; type Exports = { readonly defaultRules: DefaultRules; readonly parserFor: (rules: ParserRules, defaultState?: State | null | undefined) => Parser; readonly outputFor: (rules: OutputRules, param: keyof Rule, defaultState?: State | null | undefined) => Output; readonly ruleOutput: (rules: OutputRules, param: keyof Rule) => NodeOutput; readonly htmlFor: (arg1: HtmlNodeOutput) => HtmlOutput; readonly inlineRegex: (regex: RegExp) => MatchFunction; readonly blockRegex: (regex: RegExp) => MatchFunction; readonly anyScopeRegex: (regex: RegExp) => MatchFunction; readonly parseInline: (parse: Parser, content: string, state: State) => ASTNode; readonly parseBlock: (parse: Parser, content: string, state: State) => ASTNode; readonly markdownToHtml: (source: string, state?: State | null | undefined) => string; readonly defaultRawParse: (source: string, state?: State | null | undefined) => Array; readonly defaultBlockParse: (source: string, state?: State | null | undefined) => Array; readonly defaultInlineParse: (source: string, state?: State | null | undefined) => Array; readonly defaultImplicitParse: (source: string, state?: State | null | undefined) => Array; readonly defaultHtmlOutput: HtmlOutput; readonly preprocess: (source: string) => string; readonly sanitizeText: (text: Attr) => string; readonly sanitizeUrl: (url?: string | null | undefined) => string | null | undefined; readonly unescapeUrl: (url: string) => string; readonly htmlTag: (tagName: string, content: string, attributes?: Partial> | null | undefined, isClosed?: boolean | null | undefined) => string; /** * defaultParse is deprecated, please use `defaultImplicitParse` * @deprecated */ readonly defaultParse: (...args: any[]) => any; /** * defaultOutput is deprecated, please use `defaultReactOutput` * @deprecated */ readonly defaultOutput: (...args: any[]) => any; }; export type { State, Parser, Output, HtmlOutput, Capture, MatchFunction, ParseFunction, NodeOutput, ArrayNodeOutput, ParserRule, HtmlOutputRule, ParserRules, OutputRules, Rules, HtmlRules, SingleASTNode, }; declare var SimpleMarkdown: Exports; export default SimpleMarkdown;