marked.d.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. declare module "Tokens" {
  2. 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) & {
  3. loose?: boolean;
  4. tokens?: Token[];
  5. };
  6. export namespace Tokens {
  7. interface Space {
  8. type: 'space';
  9. raw: string;
  10. }
  11. interface Code {
  12. type: 'code';
  13. raw: string;
  14. codeBlockStyle?: 'indented' | undefined;
  15. lang?: string | undefined;
  16. text: string;
  17. escaped?: boolean;
  18. }
  19. interface Heading {
  20. type: 'heading';
  21. raw: string;
  22. depth: number;
  23. text: string;
  24. tokens: Token[];
  25. }
  26. interface Table {
  27. type: 'table';
  28. raw: string;
  29. align: Array<'center' | 'left' | 'right' | null>;
  30. header: TableCell[];
  31. rows: TableCell[][];
  32. }
  33. interface TableCell {
  34. text: string;
  35. tokens?: Token[];
  36. }
  37. interface Hr {
  38. type: 'hr';
  39. raw: string;
  40. }
  41. interface Blockquote {
  42. type: 'blockquote';
  43. raw: string;
  44. text: string;
  45. tokens: Token[];
  46. }
  47. interface List {
  48. type: 'list';
  49. raw: string;
  50. ordered: boolean;
  51. start: number | '';
  52. loose: boolean;
  53. items: ListItem[];
  54. }
  55. interface ListItem {
  56. type: 'list_item';
  57. raw: string;
  58. task: boolean;
  59. checked?: boolean | undefined;
  60. loose: boolean;
  61. text: string;
  62. tokens?: Token[];
  63. }
  64. interface Paragraph {
  65. type: 'paragraph';
  66. raw: string;
  67. pre?: boolean | undefined;
  68. text: string;
  69. tokens: Token[];
  70. }
  71. interface HTML {
  72. type: 'html';
  73. raw: string;
  74. pre: boolean;
  75. text: string;
  76. block: boolean;
  77. }
  78. interface Text {
  79. type: 'text';
  80. raw: string;
  81. text: string;
  82. tokens?: Token[];
  83. }
  84. interface Def {
  85. type: 'def';
  86. raw: string;
  87. tag: string;
  88. href: string;
  89. title: string;
  90. }
  91. interface Escape {
  92. type: 'escape';
  93. raw: string;
  94. text: string;
  95. }
  96. interface Tag {
  97. type: 'text' | 'html';
  98. raw: string;
  99. inLink: boolean;
  100. inRawBlock: boolean;
  101. text: string;
  102. block: boolean;
  103. }
  104. interface Link {
  105. type: 'link';
  106. raw: string;
  107. href: string;
  108. title?: string | null;
  109. text: string;
  110. tokens: Token[];
  111. }
  112. interface Image {
  113. type: 'image';
  114. raw: string;
  115. href: string;
  116. title: string | null;
  117. text: string;
  118. }
  119. interface Strong {
  120. type: 'strong';
  121. raw: string;
  122. text: string;
  123. tokens: Token[];
  124. }
  125. interface Em {
  126. type: 'em';
  127. raw: string;
  128. text: string;
  129. tokens: Token[];
  130. }
  131. interface Codespan {
  132. type: 'codespan';
  133. raw: string;
  134. text: string;
  135. }
  136. interface Br {
  137. type: 'br';
  138. raw: string;
  139. }
  140. interface Del {
  141. type: 'del';
  142. raw: string;
  143. text: string;
  144. tokens: Token[];
  145. }
  146. interface Generic {
  147. [index: string]: any;
  148. type: string;
  149. raw: string;
  150. tokens?: Token[] | undefined;
  151. }
  152. }
  153. export type Links = Record<string, Pick<Tokens.Link | Tokens.Image, 'href' | 'title'>>;
  154. export type TokensList = Token[] & {
  155. links: Links;
  156. };
  157. }
  158. declare module "Tokenizer" {
  159. import type { _Lexer } from "Lexer";
  160. import type { Links, Tokens } from "Tokens";
  161. import type { MarkedOptions } from "MarkedOptions";
  162. /**
  163. * Tokenizer
  164. */
  165. export class _Tokenizer {
  166. options: MarkedOptions;
  167. rules: any;
  168. lexer: _Lexer;
  169. constructor(options?: MarkedOptions);
  170. space(src: string): Tokens.Space | undefined;
  171. code(src: string): Tokens.Code | undefined;
  172. fences(src: string): Tokens.Code | undefined;
  173. heading(src: string): Tokens.Heading | undefined;
  174. hr(src: string): Tokens.Hr | undefined;
  175. blockquote(src: string): Tokens.Blockquote | undefined;
  176. list(src: string): Tokens.List | undefined;
  177. html(src: string): Tokens.HTML | Tokens.Paragraph | undefined;
  178. def(src: string): Tokens.Def | undefined;
  179. table(src: string): Tokens.Table | undefined;
  180. lheading(src: string): Tokens.Heading | undefined;
  181. paragraph(src: string): Tokens.Paragraph | undefined;
  182. text(src: string): Tokens.Text | undefined;
  183. escape(src: string): Tokens.Escape | undefined;
  184. tag(src: string): Tokens.Tag | undefined;
  185. link(src: string): Tokens.Link | Tokens.Image | undefined;
  186. reflink(src: string, links: Links): Tokens.Link | Tokens.Image | Tokens.Text | undefined;
  187. emStrong(src: string, maskedSrc: string, prevChar?: string): Tokens.Em | Tokens.Strong | undefined;
  188. codespan(src: string): Tokens.Codespan | undefined;
  189. br(src: string): Tokens.Br | undefined;
  190. del(src: string): Tokens.Del | undefined;
  191. autolink(src: string, mangle: (cap: string) => string): Tokens.Link | undefined;
  192. url(src: string, mangle: (cap: string) => string): Tokens.Link | undefined;
  193. inlineText(src: string, smartypants: (cap: string) => string): Tokens.Text | undefined;
  194. }
  195. }
  196. declare module "rules" {
  197. export type Rule = RegExp | string;
  198. export interface Rules {
  199. [ruleName: string]: Pick<RegExp, 'exec'> | Rule | Rules;
  200. }
  201. type BlockRuleNames = 'newline' | 'code' | 'fences' | 'hr' | 'heading' | 'blockquote' | 'list' | 'html' | 'def' | 'lheading' | '_paragraph' | 'text' | '_label' | '_title' | 'bullet' | 'listItemStart' | '_tag' | '_comment' | 'paragraph' | 'uote';
  202. type BlockSubRuleNames = 'normal' | 'gfm' | 'pedantic';
  203. type InlineRuleNames = 'escape' | 'autolink' | 'tag' | 'link' | 'reflink' | 'nolink' | 'reflinkSearch' | 'code' | 'br' | 'text' | '_punctuation' | 'punctuation' | 'blockSkip' | 'escapedEmSt' | '_comment' | '_escapes' | '_scheme' | '_email' | '_attribute' | '_label' | '_href' | '_title' | 'strong' | '_extended_email' | '_backpedal';
  204. type InlineSubRuleNames = 'gfm' | 'emStrong' | 'normal' | 'pedantic' | 'breaks';
  205. /**
  206. * Block-Level Grammar
  207. */
  208. export const block: Record<BlockRuleNames, Rule> & Record<BlockSubRuleNames, Rules> & Rules;
  209. /**
  210. * Inline-Level Grammar
  211. */
  212. export const inline: Record<InlineRuleNames, Rule> & Record<InlineSubRuleNames, Rules> & Rules;
  213. }
  214. declare module "Lexer" {
  215. import type { Token, TokensList } from "Tokens";
  216. import type { MarkedOptions } from "MarkedOptions";
  217. import type { Rules } from "rules";
  218. /**
  219. * Block Lexer
  220. */
  221. export class _Lexer {
  222. tokens: TokensList;
  223. options: MarkedOptions;
  224. state: {
  225. inLink: boolean;
  226. inRawBlock: boolean;
  227. top: boolean;
  228. };
  229. private tokenizer;
  230. private inlineQueue;
  231. constructor(options?: MarkedOptions);
  232. /**
  233. * Expose Rules
  234. */
  235. static get rules(): Rules;
  236. /**
  237. * Static Lex Method
  238. */
  239. static lex(src: string, options?: MarkedOptions): TokensList;
  240. /**
  241. * Static Lex Inline Method
  242. */
  243. static lexInline(src: string, options?: MarkedOptions): Token[];
  244. /**
  245. * Preprocessing
  246. */
  247. lex(src: string): TokensList;
  248. /**
  249. * Lexing
  250. */
  251. blockTokens(src: string, tokens?: Token[]): Token[];
  252. blockTokens(src: string, tokens?: TokensList): TokensList;
  253. inline(src: string, tokens?: Token[]): Token[];
  254. /**
  255. * Lexing/Compiling
  256. */
  257. inlineTokens(src: string, tokens?: Token[]): Token[];
  258. }
  259. }
  260. declare module "TextRenderer" {
  261. /**
  262. * TextRenderer
  263. * returns only the textual part of the token
  264. */
  265. export class _TextRenderer {
  266. strong(text: string): string;
  267. em(text: string): string;
  268. codespan(text: string): string;
  269. del(text: string): string;
  270. html(text: string): string;
  271. text(text: string): string;
  272. link(href: string, title: string | null | undefined, text: string): string;
  273. image(href: string, title: string | null, text: string): string;
  274. br(): string;
  275. }
  276. }
  277. declare module "Slugger" {
  278. import type { SluggerOptions } from "MarkedOptions";
  279. /**
  280. * Slugger generates header id
  281. */
  282. export class _Slugger {
  283. seen: {
  284. [slugValue: string]: number;
  285. };
  286. constructor();
  287. serialize(value: string): string;
  288. /**
  289. * Finds the next safe (unique) slug to use
  290. */
  291. getNextSafeSlug(originalSlug: string, isDryRun: boolean | undefined): string;
  292. /**
  293. * Convert string to unique id
  294. */
  295. slug(value: string, options?: SluggerOptions): string;
  296. }
  297. }
  298. declare module "Instance" {
  299. import { _Lexer } from "Lexer";
  300. import { _Parser } from "Parser";
  301. import { _Hooks } from "Hooks";
  302. import { _Renderer } from "Renderer";
  303. import { _Tokenizer } from "Tokenizer";
  304. import { _TextRenderer } from "TextRenderer";
  305. import { _Slugger } from "Slugger";
  306. import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
  307. import type { Token, TokensList } from "Tokens";
  308. export type ResultCallback = (error: Error | null, parseResult?: string) => undefined | void;
  309. export class Marked {
  310. #private;
  311. defaults: MarkedOptions;
  312. options: (opt: MarkedOptions) => this;
  313. parse: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
  314. parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | undefined | null, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
  315. Parser: typeof _Parser;
  316. parser: typeof _Parser.parse;
  317. Renderer: typeof _Renderer;
  318. TextRenderer: typeof _TextRenderer;
  319. Lexer: typeof _Lexer;
  320. lexer: typeof _Lexer.lex;
  321. Tokenizer: typeof _Tokenizer;
  322. Slugger: typeof _Slugger;
  323. Hooks: typeof _Hooks;
  324. constructor(...args: MarkedExtension[]);
  325. /**
  326. * Run callback for every token
  327. */
  328. walkTokens<T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]): T[];
  329. use(...args: MarkedExtension[]): this;
  330. setOptions(opt: MarkedOptions): this;
  331. }
  332. }
  333. declare module "helpers" {
  334. import type { MarkedOptions } from "MarkedOptions";
  335. import type { ResultCallback } from "Instance";
  336. import type { Rule } from "rules";
  337. export function escape(html: string, encode?: boolean): string;
  338. export function unescape(html: string): string;
  339. export function edit(regex: Rule, opt?: string): {
  340. replace: (name: string | RegExp, val: string | RegExp) => any;
  341. getRegex: () => RegExp;
  342. };
  343. export function cleanUrl(sanitize: boolean | undefined, base: string | undefined | null, href: string): string | null;
  344. export function resolveUrl(base: string, href: string): string;
  345. export const noopTest: {
  346. exec: () => null;
  347. };
  348. export function splitCells(tableRow: string, count?: number): string[];
  349. /**
  350. * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
  351. * /c*$/ is vulnerable to REDOS.
  352. *
  353. * @param str
  354. * @param c
  355. * @param invert Remove suffix of non-c chars instead. Default falsey.
  356. */
  357. export function rtrim(str: string, c: string, invert?: boolean): string;
  358. export function findClosingBracket(str: string, b: string): number;
  359. export function checkDeprecations(opt: MarkedOptions, callback?: ResultCallback): void;
  360. }
  361. declare module "Renderer" {
  362. import type { MarkedOptions } from "MarkedOptions";
  363. import type { _Slugger } from "Slugger";
  364. /**
  365. * Renderer
  366. */
  367. export class _Renderer {
  368. options: MarkedOptions;
  369. constructor(options?: MarkedOptions);
  370. code(code: string, infostring: string | undefined, escaped: boolean): string;
  371. blockquote(quote: string): string;
  372. html(html: string, block?: boolean): string;
  373. heading(text: string, level: number, raw: string, slugger: _Slugger): string;
  374. hr(): string;
  375. list(body: string, ordered: boolean, start: number | ''): string;
  376. listitem(text: string, task: boolean, checked: boolean): string;
  377. checkbox(checked: boolean): string;
  378. paragraph(text: string): string;
  379. table(header: string, body: string): string;
  380. tablerow(content: string): string;
  381. tablecell(content: string, flags: {
  382. header: boolean;
  383. align: 'center' | 'left' | 'right' | null;
  384. }): string;
  385. /**
  386. * span level renderer
  387. */
  388. strong(text: string): string;
  389. em(text: string): string;
  390. codespan(text: string): string;
  391. br(): string;
  392. del(text: string): string;
  393. link(href: string, title: string | null | undefined, text: string): string;
  394. image(href: string, title: string | null, text: string): string;
  395. text(text: string): string;
  396. }
  397. }
  398. declare module "Parser" {
  399. import { _Renderer } from "Renderer";
  400. import { _TextRenderer } from "TextRenderer";
  401. import { _Slugger } from "Slugger";
  402. import type { Token } from "Tokens";
  403. import type { MarkedOptions } from "MarkedOptions";
  404. /**
  405. * Parsing & Compiling
  406. */
  407. export class _Parser {
  408. options: MarkedOptions;
  409. renderer: _Renderer;
  410. textRenderer: _TextRenderer;
  411. slugger: _Slugger;
  412. constructor(options?: MarkedOptions);
  413. /**
  414. * Static Parse Method
  415. */
  416. static parse(tokens: Token[], options?: MarkedOptions): string;
  417. /**
  418. * Static Parse Inline Method
  419. */
  420. static parseInline(tokens: Token[], options?: MarkedOptions): string;
  421. /**
  422. * Parse Loop
  423. */
  424. parse(tokens: Token[], top?: boolean): string;
  425. /**
  426. * Parse Inline Tokens
  427. */
  428. parseInline(tokens: Token[], renderer?: _Renderer | _TextRenderer): string;
  429. }
  430. }
  431. declare module "MarkedOptions" {
  432. import type { Token, Tokens, TokensList } from "Tokens";
  433. import type { _Parser } from "Parser";
  434. import type { _Lexer } from "Lexer";
  435. import type { _Renderer } from "Renderer";
  436. import type { _Tokenizer } from "Tokenizer";
  437. export interface SluggerOptions {
  438. /** Generates the next unique slug without updating the internal accumulator. */
  439. dryrun?: boolean;
  440. }
  441. export interface TokenizerThis {
  442. lexer: _Lexer;
  443. }
  444. export interface TokenizerExtension {
  445. name: string;
  446. level: 'block' | 'inline';
  447. start?: ((this: TokenizerThis, src: string) => number | void) | undefined;
  448. tokenizer: (this: TokenizerThis, src: string, tokens: Token[] | TokensList) => Tokens.Generic | undefined;
  449. childTokens?: string[] | undefined;
  450. }
  451. export interface RendererThis {
  452. parser: _Parser;
  453. }
  454. export type RendererExtensionFunction = (this: RendererThis, token: Tokens.Generic) => string | false | undefined;
  455. export interface RendererExtension {
  456. name: string;
  457. renderer: RendererExtensionFunction;
  458. }
  459. export type TokenizerAndRendererExtension = TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension);
  460. type RendererApi = Omit<_Renderer, 'constructor' | 'options'>;
  461. type RendererObject = {
  462. [K in keyof RendererApi]?: (...args: Parameters<RendererApi[K]>) => ReturnType<RendererApi[K]> | false;
  463. };
  464. type TokenizerApi = Omit<_Tokenizer, 'constructor' | 'options' | 'rules' | 'lexer'>;
  465. type TokenizerObject = {
  466. [K in keyof TokenizerApi]?: (...args: Parameters<TokenizerApi[K]>) => ReturnType<TokenizerApi[K]> | false;
  467. };
  468. export interface MarkedExtension {
  469. /**
  470. * True will tell marked to await any walkTokens functions before parsing the tokens and returning an HTML string.
  471. */
  472. async?: boolean;
  473. /**
  474. * A prefix URL for any relative link.
  475. * @deprecated Deprecated in v5.0.0 use marked-base-url to prefix url for any relative link.
  476. */
  477. baseUrl?: string | undefined | null;
  478. /**
  479. * Enable GFM line breaks. This option requires the gfm option to be true.
  480. */
  481. breaks?: boolean | undefined;
  482. /**
  483. * Add tokenizers and renderers to marked
  484. */
  485. extensions?: TokenizerAndRendererExtension[] | undefined | null;
  486. /**
  487. * Enable GitHub flavored markdown.
  488. */
  489. gfm?: boolean | undefined;
  490. /**
  491. * Include an id attribute when emitting headings.
  492. * @deprecated Deprecated in v5.0.0 use marked-gfm-heading-id to include an id attribute when emitting headings (h1, h2, h3, etc).
  493. */
  494. headerIds?: boolean | undefined;
  495. /**
  496. * Set the prefix for header tag ids.
  497. * @deprecated Deprecated in v5.0.0 use marked-gfm-heading-id to add a string to prefix the id attribute when emitting headings (h1, h2, h3, etc).
  498. */
  499. headerPrefix?: string | undefined;
  500. /**
  501. * A function to highlight code blocks. The function can either be
  502. * synchronous (returning a string) or asynchronous (callback invoked
  503. * with an error if any occurred during highlighting and a string
  504. * if highlighting was successful)
  505. * @deprecated Deprecated in v5.0.0 use marked-highlight to add highlighting to code blocks.
  506. */
  507. highlight?: ((code: string, lang: string | undefined, callback?: (error: Error, code?: string) => void) => string | void) | null;
  508. /**
  509. * Hooks are methods that hook into some part of marked.
  510. * preprocess is called to process markdown before sending it to marked.
  511. * postprocess is called to process html after marked has finished parsing.
  512. */
  513. hooks?: {
  514. preprocess: (markdown: string) => string | Promise<string>;
  515. postprocess: (html: string) => string | Promise<string>;
  516. options?: MarkedOptions;
  517. } | null;
  518. /**
  519. * Set the prefix for code block classes.
  520. * @deprecated Deprecated in v5.0.0 use marked-highlight to prefix the className in a <code> block. Useful for syntax highlighting.
  521. */
  522. langPrefix?: string | undefined;
  523. /**
  524. * Mangle autolinks (<email@domain.com>).
  525. * @deprecated Deprecated in v5.0.0 use marked-mangle to mangle email addresses.
  526. */
  527. mangle?: boolean | undefined;
  528. /**
  529. * Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
  530. */
  531. pedantic?: boolean | undefined;
  532. /**
  533. * Type: object Default: new Renderer()
  534. *
  535. * An object containing functions to render tokens to HTML.
  536. */
  537. renderer?: RendererObject | undefined | null;
  538. /**
  539. * Sanitize the output. Ignore any HTML that has been input. If true, sanitize the HTML passed into markdownString with the sanitizer function.
  540. * @deprecated Warning: This feature is deprecated and it should NOT be used as it cannot be considered secure. Instead use a sanitize library, like DOMPurify (recommended), sanitize-html or insane on the output HTML!
  541. */
  542. sanitize?: boolean | undefined;
  543. /**
  544. * Optionally sanitize found HTML with a sanitizer function.
  545. * @deprecated A function to sanitize the HTML passed into markdownString.
  546. */
  547. sanitizer?: ((html: string) => string) | null;
  548. /**
  549. * Shows an HTML error message when rendering fails.
  550. */
  551. silent?: boolean | undefined;
  552. /**
  553. * Use smarter list behavior than the original markdown. May eventually be default with the old behavior moved into pedantic.
  554. */
  555. smartLists?: boolean | undefined;
  556. /**
  557. * Use "smart" typograhic punctuation for things like quotes and dashes.
  558. * @deprecated Deprecated in v5.0.0 use marked-smartypants to use "smart" typographic punctuation for things like quotes and dashes.
  559. */
  560. smartypants?: boolean | undefined;
  561. /**
  562. * The tokenizer defines how to turn markdown text into tokens.
  563. */
  564. tokenizer?: TokenizerObject | undefined | null;
  565. /**
  566. * The walkTokens function gets called with every token.
  567. * Child tokens are called before moving on to sibling tokens.
  568. * Each token is passed by reference so updates are persisted when passed to the parser.
  569. * The return value of the function is ignored.
  570. */
  571. walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
  572. /**
  573. * Generate closing slash for self-closing tags (<br/> instead of <br>)
  574. * @deprecated Deprecated in v5.0.0 use marked-xhtml to emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.
  575. */
  576. xhtml?: boolean | undefined;
  577. }
  578. export interface MarkedOptions extends Omit<MarkedExtension, 'extensions' | 'renderer' | 'tokenizer' | 'walkTokens'> {
  579. /**
  580. * Type: object Default: new Renderer()
  581. *
  582. * An object containing functions to render tokens to HTML.
  583. */
  584. renderer?: Omit<_Renderer, 'constructor'> | undefined | null;
  585. /**
  586. * The tokenizer defines how to turn markdown text into tokens.
  587. */
  588. tokenizer?: Omit<_Tokenizer, 'constructor'> | undefined | null;
  589. /**
  590. * The walkTokens function gets called with every token.
  591. * Child tokens are called before moving on to sibling tokens.
  592. * Each token is passed by reference so updates are persisted when passed to the parser.
  593. * The return value of the function is ignored.
  594. */
  595. walkTokens?: ((token: Token) => void | Promise<void> | Array<void | Promise<void>>) | undefined | null;
  596. /**
  597. * Add tokenizers and renderers to marked
  598. */
  599. extensions?: (TokenizerAndRendererExtension[] & {
  600. renderers: Record<string, RendererExtensionFunction>;
  601. childTokens: Record<string, string[]>;
  602. block: any[];
  603. inline: any[];
  604. startBlock: Array<(this: TokenizerThis, src: string) => number | void>;
  605. startInline: Array<(this: TokenizerThis, src: string) => number | void>;
  606. }) | undefined | null;
  607. }
  608. }
  609. declare module "defaults" {
  610. import type { MarkedOptions } from "MarkedOptions";
  611. /**
  612. * Gets the original marked default options.
  613. */
  614. export function _getDefaults(): MarkedOptions;
  615. export let _defaults: MarkedOptions;
  616. export function changeDefaults(newDefaults: MarkedOptions): void;
  617. }
  618. declare module "Hooks" {
  619. import type { MarkedOptions } from "MarkedOptions";
  620. export class _Hooks {
  621. options: MarkedOptions;
  622. constructor(options?: MarkedOptions);
  623. static passThroughHooks: Set<string>;
  624. /**
  625. * Process markdown before marked
  626. */
  627. preprocess(markdown: string): string;
  628. /**
  629. * Process HTML after marked is finished
  630. */
  631. postprocess(html: string): string;
  632. }
  633. }
  634. declare module "marked" {
  635. import { _Lexer } from "Lexer";
  636. import { _Parser } from "Parser";
  637. import { _Tokenizer } from "Tokenizer";
  638. import { _Renderer } from "Renderer";
  639. import { _TextRenderer } from "TextRenderer";
  640. import { _Slugger } from "Slugger";
  641. import { _Hooks } from "Hooks";
  642. import { _getDefaults } from "defaults";
  643. import type { MarkedExtension, MarkedOptions } from "MarkedOptions";
  644. import type { Token, TokensList } from "Tokens";
  645. import type { ResultCallback } from "Instance";
  646. /**
  647. * Compiles markdown to HTML asynchronously.
  648. *
  649. * @param src String of markdown source to be compiled
  650. * @param options Hash of options, having async: true
  651. * @return Promise of string of compiled HTML
  652. */
  653. export function marked(src: string, options: MarkedOptions & {
  654. async: true;
  655. }): Promise<string>;
  656. /**
  657. * Compiles markdown to HTML synchronously.
  658. *
  659. * @param src String of markdown source to be compiled
  660. * @param options Optional hash of options
  661. * @return String of compiled HTML
  662. */
  663. export function marked(src: string, options?: MarkedOptions): string;
  664. /**
  665. * Compiles markdown to HTML asynchronously with a callback.
  666. *
  667. * @param src String of markdown source to be compiled
  668. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  669. */
  670. export function marked(src: string, callback: ResultCallback): void;
  671. /**
  672. * Compiles markdown to HTML asynchronously with a callback.
  673. *
  674. * @param src String of markdown source to be compiled
  675. * @param options Hash of options
  676. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  677. */
  678. export function marked(src: string, options: MarkedOptions, callback: ResultCallback): void;
  679. /**
  680. * Compiles markdown to HTML asynchronously with a callback.
  681. *
  682. * @param src String of markdown source to be compiled
  683. * @param options Hash of options
  684. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  685. */
  686. export namespace marked {
  687. var options: (options: MarkedOptions) => typeof marked;
  688. var setOptions: (options: MarkedOptions) => typeof marked;
  689. var getDefaults: typeof _getDefaults;
  690. var defaults: MarkedOptions;
  691. var use: (...args: MarkedExtension[]) => typeof marked;
  692. var walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
  693. var parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
  694. var Parser: typeof _Parser;
  695. var parser: typeof _Parser.parse;
  696. var Renderer: typeof _Renderer;
  697. var TextRenderer: typeof _TextRenderer;
  698. var Lexer: typeof _Lexer;
  699. var lexer: typeof _Lexer.lex;
  700. var Tokenizer: typeof _Tokenizer;
  701. var Slugger: typeof _Slugger;
  702. var Hooks: typeof _Hooks;
  703. var parse: typeof marked;
  704. }
  705. export const options: (options: MarkedOptions) => typeof marked;
  706. export const setOptions: (options: MarkedOptions) => typeof marked;
  707. export const use: (...args: MarkedExtension[]) => typeof marked;
  708. export const walkTokens: <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) => T[];
  709. export const parseInline: (src: string, optOrCallback?: MarkedOptions | ResultCallback | null | undefined, callback?: ResultCallback | undefined) => string | Promise<string | undefined> | undefined;
  710. export const parse: typeof marked;
  711. export const parser: typeof _Parser.parse;
  712. export const lexer: typeof _Lexer.lex;
  713. export { _defaults as defaults, _getDefaults as getDefaults } from "defaults";
  714. export { _Lexer as Lexer } from "Lexer";
  715. export { _Parser as Parser } from "Parser";
  716. export { _Tokenizer as Tokenizer } from "Tokenizer";
  717. export { _Renderer as Renderer } from "Renderer";
  718. export { _TextRenderer as TextRenderer } from "TextRenderer";
  719. export { _Slugger as Slugger } from "Slugger";
  720. export { _Hooks as Hooks } from "Hooks";
  721. export { Marked } from "Instance";
  722. export type * from "MarkedOptions";
  723. export type * from "rules";
  724. export type * from "Tokens";
  725. }