export interface StringFormat { strong?: boolean; emphasis?: boolean; strike?: boolean; pre?: boolean; } interface NewlineToken extends StringFormat { type: 'newline'; text: string; } interface WhitespaceToken extends StringFormat { type: 'whitespace'; text: string; } interface TextToken extends StringFormat { type: 'text'; text: string; } interface DelimeterToken extends StringFormat { type: 'delimeter'; text: string; left_flanking?: boolean; right_flanking?: boolean; char: string; length: number; } type Token = NewlineToken | WhitespaceToken | TextToken | DelimeterToken; /** * this external type only has text information */ export interface FormattedString extends StringFormat { text: string; } /** * utility for formatting markdown strings. we split text into tokens * by format. implemented as a factory/singleton, stateless. * * note: in case it's not clear, where I reference MD rules, I mean * CommonMark. we may add some GFM as well (strike?). * * UPDATE: moving into the parser lib, since it's a parser. even though * it's totally independent. (has no deps, though, nice). */ export declare class MDParser { private static _instance; protected constructor(); static get instance(): MDParser; /** * given some formatted text (output of the `Parse` method), return HTML. * FIXME: is this used outside of testing? seems like we're wasting bytes. * * also the way this works adds extra tags if you have nested styles. not * an issue if it's just for testing though. * * update to optionally not add breaking spaces (
). we need this for * containers that are set to white-space: pre-line, where we will already * get a linebreak. * */ HTML(formatted: FormattedString[][], options?: { br?: boolean; }): string; /** * this is a replacement for the Parse() method, if you don't actually * want to parse markdown. the aim is to have a unified result format, * even if we're not handling md. */ Dummy(text?: string): FormattedString[][]; /** * given some input text, creates a set of text tokens with * emphasis/strong emphasis applied. splits into lines (the * outer array). whitespace (other than newlines) is preserved. */ Parse(text?: string): FormattedString[][]; /** is this worth a function call? will it get inlined? */ protected IsWhitespace(char: string): boolean; /** is this worth a function call? will it get inlined? */ protected IsNewline(char: string): boolean; /** is this worth a function call? will it get inlined? */ protected IsDelimeter(char: string): boolean; /** * consolidate text with common formatting. splits into lines (newlines are not rendered). */ protected Consolidate(tokens: Token[]): TextToken[][]; /** * */ protected ApplyFormatting(tokens: Token[], open?: DelimeterToken): { index: number; token?: DelimeterToken; }; /** * */ protected Tokenize(text?: string): Token[]; } export {};