marked.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Type definitions for Marked
  2. // Project: https://github.com/chjj/marked
  3. // Definitions by: William Orr <https://github.com/worr>
  4. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  5. interface MarkedStatic {
  6. /**
  7. * Compiles markdown to HTML.
  8. *
  9. * @param src String of markdown source to be compiled
  10. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  11. * @return String of compiled HTML
  12. */
  13. (src: string, callback: Function): string;
  14. /**
  15. * Compiles markdown to HTML.
  16. *
  17. * @param src String of markdown source to be compiled
  18. * @param options Hash of options
  19. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  20. * @return String of compiled HTML
  21. */
  22. (src: string, options?: MarkedOptions, callback?: Function): string;
  23. /**
  24. * @param src String of markdown source to be compiled
  25. * @param options Hash of options
  26. */
  27. lexer(src: string, options?: MarkedOptions): any[];
  28. /**
  29. * Compiles markdown to HTML.
  30. *
  31. * @param src String of markdown source to be compiled
  32. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  33. * @return String of compiled HTML
  34. */
  35. parse(src: string, callback: Function): string;
  36. /**
  37. * Compiles markdown to HTML.
  38. *
  39. * @param src String of markdown source to be compiled
  40. * @param options Hash of options
  41. * @param callback Function called when the markdownString has been fully parsed when using async highlighting
  42. * @return String of compiled HTML
  43. */
  44. parse(src: string, options?: MarkedOptions, callback?: Function): string;
  45. /**
  46. * @param options Hash of options
  47. */
  48. parser(src: any[], options?: MarkedOptions): string;
  49. /**
  50. * Sets the default options.
  51. *
  52. * @param options Hash of options
  53. */
  54. setOptions(options: MarkedOptions): MarkedStatic;
  55. Renderer: {
  56. new(): MarkedRenderer;
  57. }
  58. Parser: {
  59. new(options: MarkedOptions): MarkedParser;
  60. }
  61. }
  62. interface MarkedRenderer {
  63. code(code: string, language: string): string;
  64. blockquote(quote: string): string;
  65. html(html: string): string;
  66. heading(text: string, level: number, raw: string): string;
  67. hr(): string;
  68. list(body: string, ordered: boolean): string;
  69. listitem(text: string): string;
  70. paragraph(text: string): string;
  71. table(header: string, body: string): string;
  72. tablerow(content: string): string;
  73. tablecell(content: string, flags: {
  74. header: boolean,
  75. align: string
  76. }): string;
  77. strong(text: string): string;
  78. em(text: string): string;
  79. codespan(code: string): string;
  80. br(): string;
  81. del(text: string): string;
  82. link(href: string, title: string, text: string): string;
  83. image(href: string, title: string, text: string): string;
  84. text(text: string): string;
  85. }
  86. interface MarkedParser {
  87. parse(source: any[]): string
  88. }
  89. interface MarkedOptions {
  90. /**
  91. * Type: object Default: new Renderer()
  92. *
  93. * An object containing functions to render tokens to HTML.
  94. */
  95. renderer?: MarkedRenderer;
  96. /**
  97. * Enable GitHub flavored markdown.
  98. */
  99. gfm?: boolean;
  100. /**
  101. * Enable GFM tables. This option requires the gfm option to be true.
  102. */
  103. tables?: boolean;
  104. /**
  105. * Enable GFM line breaks. This option requires the gfm option to be true.
  106. */
  107. breaks?: boolean;
  108. /**
  109. * Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
  110. */
  111. pedantic?: boolean;
  112. /**
  113. * Sanitize the output. Ignore any HTML that has been input.
  114. */
  115. sanitize?: boolean;
  116. /**
  117. * Use smarter list behavior than the original markdown. May eventually be default with the old behavior moved into pedantic.
  118. */
  119. smartLists?: boolean;
  120. /**
  121. * Shows an HTML error message when rendering fails.
  122. */
  123. silent?: boolean;
  124. /**
  125. * A function to highlight code blocks. The function takes three arguments: code, lang, and callback.
  126. */
  127. highlight? (code: string, lang: string, callback?: Function): string;
  128. /**
  129. * Set the prefix for code block classes.
  130. */
  131. langPrefix?: string;
  132. /**
  133. * Use "smart" typograhic punctuation for things like quotes and dashes.
  134. */
  135. smartypants?: boolean;
  136. }
  137. declare module "marked" {
  138. export = marked;
  139. }
  140. declare var marked: MarkedStatic;