|
@@ -1,5 +1,5 @@
|
|
|
declare module "Tokens" {
|
|
|
- export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del) & {
|
|
|
+ export type Token = (Tokens.Space | Tokens.Code | Tokens.Heading | Tokens.Table | Tokens.Hr | Tokens.Blockquote | Tokens.List | Tokens.ListItem | Tokens.Paragraph | Tokens.HTML | Tokens.Text | Tokens.Def | Tokens.Escape | Tokens.Tag | Tokens.Image | Tokens.Link | Tokens.Strong | Tokens.Em | Tokens.Codespan | Tokens.Br | Tokens.Del | Tokens.Generic) & {
|
|
|
loose?: boolean;
|
|
|
tokens?: Token[];
|
|
|
};
|
|
@@ -25,7 +25,7 @@ declare module "Tokens" {
|
|
|
}
|
|
|
interface Table {
|
|
|
type: 'table';
|
|
|
- raw?: string;
|
|
|
+ raw: string;
|
|
|
align: Array<'center' | 'left' | 'right' | null>;
|
|
|
header: TableCell[];
|
|
|
rows: TableCell[][];
|
|
@@ -156,7 +156,7 @@ declare module "Tokens" {
|
|
|
};
|
|
|
}
|
|
|
declare module "Tokenizer" {
|
|
|
- import { _Lexer } from "Lexer";
|
|
|
+ import type { _Lexer } from "Lexer";
|
|
|
import type { Links, Tokens } from "Tokens";
|
|
|
import type { MarkedOptions } from "MarkedOptions";
|
|
|
/**
|
|
@@ -309,7 +309,7 @@ declare module "Instance" {
|
|
|
export class Marked {
|
|
|
#private;
|
|
|
defaults: MarkedOptions;
|
|
|
- options: (opt: any) => this;
|
|
|
+ options: (opt: MarkedOptions) => this;
|
|
|
parse: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
|
parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
|
Parser: typeof _Parser;
|
|
@@ -327,7 +327,7 @@ declare module "Instance" {
|
|
|
*/
|
|
|
walkTokens<T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]): T[];
|
|
|
use(...args: MarkedExtension[]): this;
|
|
|
- setOptions(opt: any): this;
|
|
|
+ setOptions(opt: MarkedOptions): this;
|
|
|
}
|
|
|
}
|
|
|
declare module "helpers" {
|
|
@@ -345,7 +345,7 @@ declare module "helpers" {
|
|
|
export const noopTest: {
|
|
|
exec: () => null;
|
|
|
};
|
|
|
- export function splitCells(tableRow: string, count: number): string[];
|
|
|
+ export function splitCells(tableRow: string, count?: number): string[];
|
|
|
/**
|
|
|
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
|
|
* /c*$/ is vulnerable to REDOS.
|
|
@@ -358,101 +358,9 @@ declare module "helpers" {
|
|
|
export function findClosingBracket(str: string, b: string): number;
|
|
|
export function checkDeprecations(opt: MarkedOptions, callback?: ResultCallback): void;
|
|
|
}
|
|
|
-declare module "marked" {
|
|
|
- import { _Lexer } from "Lexer";
|
|
|
- import { _Parser } from "Parser";
|
|
|
- import { _Tokenizer } from "Tokenizer";
|
|
|
- import { _Renderer } from "Renderer";
|
|
|
- import { _TextRenderer } from "TextRenderer";
|
|
|
- import { _Slugger } from "Slugger";
|
|
|
- import { _Hooks } from "Hooks";
|
|
|
- import { _getDefaults } from "defaults";
|
|
|
- import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
|
|
|
- import type { Token, TokensList } from "Tokens";
|
|
|
- import type { ResultCallback } from "Instance";
|
|
|
- /**
|
|
|
- * Compiles markdown to HTML asynchronously.
|
|
|
- *
|
|
|
- * @param src String of markdown source to be compiled
|
|
|
- * @param options Hash of options, having async: true
|
|
|
- * @return Promise of string of compiled HTML
|
|
|
- */
|
|
|
- export function marked(src: string, options: MarkedOptions & {
|
|
|
- async: true;
|
|
|
- }): Promise<string>;
|
|
|
- /**
|
|
|
- * Compiles markdown to HTML synchronously.
|
|
|
- *
|
|
|
- * @param src String of markdown source to be compiled
|
|
|
- * @param options Optional hash of options
|
|
|
- * @return String of compiled HTML
|
|
|
- */
|
|
|
- export function marked(src: string, options?: MarkedOptions): string;
|
|
|
- /**
|
|
|
- * Compiles markdown to HTML asynchronously with a callback.
|
|
|
- *
|
|
|
- * @param src String of markdown source to be compiled
|
|
|
- * @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
|
- */
|
|
|
- export function marked(src: string, callback: ResultCallback): void;
|
|
|
- /**
|
|
|
- * Compiles markdown to HTML asynchronously with a callback.
|
|
|
- *
|
|
|
- * @param src String of markdown source to be compiled
|
|
|
- * @param options Hash of options
|
|
|
- * @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
|
- */
|
|
|
- export function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
|
|
|
- /**
|
|
|
- * Compiles markdown to HTML asynchronously with a callback.
|
|
|
- *
|
|
|
- * @param src String of markdown source to be compiled
|
|
|
- * @param options Hash of options
|
|
|
- * @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
|
- */
|
|
|
- export namespace marked {
|
|
|
- var options: (options: MarkedOptions) => typeof marked;
|
|
|
- var setOptions: (options: MarkedOptions) => typeof marked;
|
|
|
- var getDefaults: typeof _getDefaults;
|
|
|
- var defaults: MarkedOptions;
|
|
|
- var use: (...args: MarkedExtension[]) => typeof marked;
|
|
|
- var walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
|
- var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
|
- var Parser: typeof _Parser;
|
|
|
- var parser: typeof _Parser.parse;
|
|
|
- var Renderer: typeof _Renderer;
|
|
|
- var TextRenderer: typeof _TextRenderer;
|
|
|
- var Lexer: typeof _Lexer;
|
|
|
- var lexer: typeof _Lexer.lex;
|
|
|
- var Tokenizer: typeof _Tokenizer;
|
|
|
- var Slugger: typeof _Slugger;
|
|
|
- var Hooks: typeof _Hooks;
|
|
|
- var parse: typeof marked;
|
|
|
- }
|
|
|
- export const options: (options: MarkedOptions) => typeof marked;
|
|
|
- export const setOptions: (options: MarkedOptions) => typeof marked;
|
|
|
- export const use: (...args: MarkedExtension[]) => typeof marked;
|
|
|
- export const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
|
- export const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
|
- export const parse: typeof marked;
|
|
|
- export const parser: typeof _Parser.parse;
|
|
|
- export const lexer: typeof _Lexer.lex;
|
|
|
- export { _defaults as defaults, _getDefaults as getDefaults } from "defaults";
|
|
|
- export { _Lexer as Lexer } from "Lexer";
|
|
|
- export { _Parser as Parser } from "Parser";
|
|
|
- export { _Tokenizer as Tokenizer } from "Tokenizer";
|
|
|
- export { _Renderer as Renderer } from "Renderer";
|
|
|
- export { _TextRenderer as TextRenderer } from "TextRenderer";
|
|
|
- export { _Slugger as Slugger } from "Slugger";
|
|
|
- export { _Hooks as Hooks } from "Hooks";
|
|
|
- export { Marked } from "Instance";
|
|
|
- export type * from "MarkedOptions";
|
|
|
- export type * from "rules";
|
|
|
- export type * from "Tokens";
|
|
|
-}
|
|
|
declare module "Renderer" {
|
|
|
import type { MarkedOptions } from "MarkedOptions";
|
|
|
- import { Slugger } from "marked";
|
|
|
+ import type { _Slugger } from "Slugger";
|
|
|
/**
|
|
|
* Renderer
|
|
|
*/
|
|
@@ -462,7 +370,7 @@ declare module "Renderer" {
|
|
|
code(code: string, infostring: string | undefined, escaped: boolean): string;
|
|
|
blockquote(quote: string): string;
|
|
|
html(html: string, block?: boolean): string;
|
|
|
- heading(text: string, level: number, raw: string, slugger: Slugger): string;
|
|
|
+ heading(text: string, level: number, raw: string, slugger: _Slugger): string;
|
|
|
hr(): string;
|
|
|
list(body: string, ordered: boolean, start: number | ''): string;
|
|
|
listitem(text: string, task: boolean, checked: boolean): string;
|
|
@@ -522,10 +430,10 @@ declare module "Parser" {
|
|
|
}
|
|
|
declare module "MarkedOptions" {
|
|
|
import type { Token, Tokens, TokensList } from "Tokens";
|
|
|
- import { _Parser } from "Parser";
|
|
|
- import { _Lexer } from "Lexer";
|
|
|
- import { _Renderer } from "Renderer";
|
|
|
- import { _Tokenizer } from "Tokenizer";
|
|
|
+ import type { _Parser } from "Parser";
|
|
|
+ import type { _Lexer } from "Lexer";
|
|
|
+ import type { _Renderer } from "Renderer";
|
|
|
+ import type { _Tokenizer } from "Tokenizer";
|
|
|
export interface SluggerOptions {
|
|
|
/** Generates the next unique slug without updating the internal accumulator. */
|
|
|
dryrun?: boolean;
|
|
@@ -537,15 +445,16 @@ declare module "MarkedOptions" {
|
|
|
name: string;
|
|
|
level: 'block' | 'inline';
|
|
|
start?: ((this: TokenizerThis, src: string) => number | void) | undefined;
|
|
|
- tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic | void;
|
|
|
+ tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic | undefined;
|
|
|
childTokens?: string[] | undefined;
|
|
|
}
|
|
|
export interface RendererThis {
|
|
|
parser: _Parser;
|
|
|
}
|
|
|
+ export type RendererExtensionFunction = (this: RendererThis, token: Tokens.Generic) => string | false | undefined;
|
|
|
export interface RendererExtension {
|
|
|
name: string;
|
|
|
- renderer: (this: RendererThis, token: Tokens.Generic) => string | false | undefined;
|
|
|
+ renderer: RendererExtensionFunction;
|
|
|
}
|
|
|
export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
|
|
|
type RendererApi = Omit<_Renderer, 'constructor' | 'options'>;
|
|
@@ -602,8 +511,8 @@ declare module "MarkedOptions" {
|
|
|
* postprocess is called to process html after marked has finished parsing.
|
|
|
*/
|
|
|
hooks?: {
|
|
|
- preprocess: (markdown: string) => string;
|
|
|
- postprocess: (html: string | undefined) => string | undefined;
|
|
|
+ preprocess: (markdown: string) => string | Promise<string>;
|
|
|
+ postprocess: (html: string) => string | Promise<string>;
|
|
|
options?: MarkedOptions;
|
|
|
} | null;
|
|
|
/**
|
|
@@ -688,7 +597,7 @@ declare module "MarkedOptions" {
|
|
|
* Add tokenizers and renderers to marked
|
|
|
*/
|
|
|
extensions?: (TokenizerAndRendererExtension[] & {
|
|
|
- renderers: Record<string, (this: RendererThis, token: Tokens.Generic) => string | false | undefined>;
|
|
|
+ renderers: Record<string, RendererExtensionFunction>;
|
|
|
childTokens: Record<string, string[]>;
|
|
|
block: any[];
|
|
|
inline: any[];
|
|
@@ -719,6 +628,98 @@ declare module "Hooks" {
|
|
|
/**
|
|
|
* Process HTML after marked is finished
|
|
|
*/
|
|
|
- postprocess(html: string | undefined): string | undefined;
|
|
|
+ postprocess(html: string): string;
|
|
|
}
|
|
|
}
|
|
|
+declare module "marked" {
|
|
|
+ import { _Lexer } from "Lexer";
|
|
|
+ import { _Parser } from "Parser";
|
|
|
+ import { _Tokenizer } from "Tokenizer";
|
|
|
+ import { _Renderer } from "Renderer";
|
|
|
+ import { _TextRenderer } from "TextRenderer";
|
|
|
+ import { _Slugger } from "Slugger";
|
|
|
+ import { _Hooks } from "Hooks";
|
|
|
+ import { _getDefaults } from "defaults";
|
|
|
+ import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
|
|
|
+ import type { Token, TokensList } from "Tokens";
|
|
|
+ import type { ResultCallback } from "Instance";
|
|
|
+ /**
|
|
|
+ * Compiles markdown to HTML asynchronously.
|
|
|
+ *
|
|
|
+ * @param src String of markdown source to be compiled
|
|
|
+ * @param options Hash of options, having async: true
|
|
|
+ * @return Promise of string of compiled HTML
|
|
|
+ */
|
|
|
+ export function marked(src: string, options: MarkedOptions & {
|
|
|
+ async: true;
|
|
|
+ }): Promise<string>;
|
|
|
+ /**
|
|
|
+ * Compiles markdown to HTML synchronously.
|
|
|
+ *
|
|
|
+ * @param src String of markdown source to be compiled
|
|
|
+ * @param options Optional hash of options
|
|
|
+ * @return String of compiled HTML
|
|
|
+ */
|
|
|
+ export function marked(src: string, options?: MarkedOptions): string;
|
|
|
+ /**
|
|
|
+ * Compiles markdown to HTML asynchronously with a callback.
|
|
|
+ *
|
|
|
+ * @param src String of markdown source to be compiled
|
|
|
+ * @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
|
+ */
|
|
|
+ export function marked(src: string, callback: ResultCallback): void;
|
|
|
+ /**
|
|
|
+ * Compiles markdown to HTML asynchronously with a callback.
|
|
|
+ *
|
|
|
+ * @param src String of markdown source to be compiled
|
|
|
+ * @param options Hash of options
|
|
|
+ * @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
|
+ */
|
|
|
+ export function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
|
|
|
+ /**
|
|
|
+ * Compiles markdown to HTML asynchronously with a callback.
|
|
|
+ *
|
|
|
+ * @param src String of markdown source to be compiled
|
|
|
+ * @param options Hash of options
|
|
|
+ * @param callback Function called when the markdownString has been fully parsed when using async highlighting
|
|
|
+ */
|
|
|
+ export namespace marked {
|
|
|
+ var options: (options: MarkedOptions) => typeof marked;
|
|
|
+ var setOptions: (options: MarkedOptions) => typeof marked;
|
|
|
+ var getDefaults: typeof _getDefaults;
|
|
|
+ var defaults: MarkedOptions;
|
|
|
+ var use: (...args: MarkedExtension[]) => typeof marked;
|
|
|
+ var walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
|
+ var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
|
+ var Parser: typeof _Parser;
|
|
|
+ var parser: typeof _Parser.parse;
|
|
|
+ var Renderer: typeof _Renderer;
|
|
|
+ var TextRenderer: typeof _TextRenderer;
|
|
|
+ var Lexer: typeof _Lexer;
|
|
|
+ var lexer: typeof _Lexer.lex;
|
|
|
+ var Tokenizer: typeof _Tokenizer;
|
|
|
+ var Slugger: typeof _Slugger;
|
|
|
+ var Hooks: typeof _Hooks;
|
|
|
+ var parse: typeof marked;
|
|
|
+ }
|
|
|
+ export const options: (options: MarkedOptions) => typeof marked;
|
|
|
+ export const setOptions: (options: MarkedOptions) => typeof marked;
|
|
|
+ export const use: (...args: MarkedExtension[]) => typeof marked;
|
|
|
+ export const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
|
|
|
+ export const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
|
|
|
+ export const parse: typeof marked;
|
|
|
+ export const parser: typeof _Parser.parse;
|
|
|
+ export const lexer: typeof _Lexer.lex;
|
|
|
+ export { _defaults as defaults, _getDefaults as getDefaults } from "defaults";
|
|
|
+ export { _Lexer as Lexer } from "Lexer";
|
|
|
+ export { _Parser as Parser } from "Parser";
|
|
|
+ export { _Tokenizer as Tokenizer } from "Tokenizer";
|
|
|
+ export { _Renderer as Renderer } from "Renderer";
|
|
|
+ export { _TextRenderer as TextRenderer } from "TextRenderer";
|
|
|
+ export { _Slugger as Slugger } from "Slugger";
|
|
|
+ export { _Hooks as Hooks } from "Hooks";
|
|
|
+ export { Marked } from "Instance";
|
|
|
+ export type * from "MarkedOptions";
|
|
|
+ export type * from "rules";
|
|
|
+ export type * from "Tokens";
|
|
|
+}
|