index.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /**
  2. * Turn markdown into HTML.
  3. *
  4. * ##### Notes
  5. *
  6. * ###### Signature
  7. *
  8. * * if a processor is given,
  9. * runs the (rehype) plugins used on it with a hast tree,
  10. * then discards the result (*bridge mode*)
  11. * * otherwise,
  12. * returns a hast tree,
  13. * the plugins used after `remarkRehype` are rehype plugins (*mutate mode*)
  14. *
  15. * > 👉 **Note**:
  16. * > It’s highly unlikely that you want to pass a `processor`.
  17. *
  18. * ###### HTML
  19. *
  20. * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
  21. * as semistandard `raw` nodes.
  22. * Most plugins ignore `raw` nodes but two notable ones don’t:
  23. *
  24. * * `rehype-stringify` also has an option `allowDangerousHtml` which will
  25. * output the raw HTML.
  26. * This is typically discouraged as noted by the option name but is useful if
  27. * you completely trust authors
  28. * * `rehype-raw` can handle the raw embedded HTML strings by parsing them
  29. * into standard hast nodes (`element`, `text`, etc);
  30. * this is a heavy task as it needs a full HTML parser,
  31. * but it is the only way to support untrusted content
  32. *
  33. * ###### Footnotes
  34. *
  35. * Many options supported here relate to footnotes.
  36. * Footnotes are not specified by CommonMark,
  37. * which we follow by default.
  38. * They are supported by GitHub,
  39. * so footnotes can be enabled in markdown with `remark-gfm`.
  40. *
  41. * The options `footnoteBackLabel` and `footnoteLabel` define natural language
  42. * that explains footnotes,
  43. * which is hidden for sighted users but shown to assistive technology.
  44. * When your page is not in English,
  45. * you must define translated values.
  46. *
  47. * Back references use ARIA attributes,
  48. * but the section label itself uses a heading that is hidden with an
  49. * `sr-only` class.
  50. * To show it to sighted users,
  51. * define different attributes in `footnoteLabelProperties`.
  52. *
  53. * ###### Clobbering
  54. *
  55. * Footnotes introduces a problem,
  56. * as it links footnote calls to footnote definitions on the page through `id`
  57. * attributes generated from user content,
  58. * which results in DOM clobbering.
  59. *
  60. * DOM clobbering is this:
  61. *
  62. * ```html
  63. * <p id=x></p>
  64. * <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
  65. * ```
  66. *
  67. * Elements by their ID are made available by browsers on the `window` object,
  68. * which is a security risk.
  69. * Using a prefix solves this problem.
  70. *
  71. * More information on how to handle clobbering and the prefix is explained in
  72. * *Example: headings (DOM clobbering)* in `rehype-sanitize`.
  73. *
  74. * ###### Unknown nodes
  75. *
  76. * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
  77. * The default behavior for unknown nodes is:
  78. *
  79. * * when the node has a `value`
  80. * (and doesn’t have `data.hName`, `data.hProperties`, or `data.hChildren`,
  81. * see later),
  82. * create a hast `text` node
  83. * * otherwise,
  84. * create a `<div>` element (which could be changed with `data.hName`),
  85. * with its children mapped from mdast to hast as well
  86. *
  87. * This behavior can be changed by passing an `unknownHandler`.
  88. *
  89. * @overload
  90. * @param {Processor} processor
  91. * @param {Readonly<Options> | null | undefined} [options]
  92. * @returns {TransformBridge}
  93. *
  94. * @overload
  95. * @param {Readonly<Options> | null | undefined} [options]
  96. * @returns {TransformMutate}
  97. *
  98. * @overload
  99. * @param {Readonly<Options> | Processor | null | undefined} [destination]
  100. * @param {Readonly<Options> | null | undefined} [options]
  101. * @returns {TransformBridge | TransformMutate}
  102. *
  103. * @param {Readonly<Options> | Processor | null | undefined} [destination]
  104. * Processor or configuration (optional).
  105. * @param {Readonly<Options> | null | undefined} [options]
  106. * When a processor was given,
  107. * configuration (optional).
  108. * @returns {TransformBridge | TransformMutate}
  109. * Transform.
  110. */
  111. export default function remarkRehype(processor: Processor, options?: Readonly<Options> | null | undefined): TransformBridge;
  112. /**
  113. * Turn markdown into HTML.
  114. *
  115. * ##### Notes
  116. *
  117. * ###### Signature
  118. *
  119. * * if a processor is given,
  120. * runs the (rehype) plugins used on it with a hast tree,
  121. * then discards the result (*bridge mode*)
  122. * * otherwise,
  123. * returns a hast tree,
  124. * the plugins used after `remarkRehype` are rehype plugins (*mutate mode*)
  125. *
  126. * > 👉 **Note**:
  127. * > It’s highly unlikely that you want to pass a `processor`.
  128. *
  129. * ###### HTML
  130. *
  131. * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
  132. * as semistandard `raw` nodes.
  133. * Most plugins ignore `raw` nodes but two notable ones don’t:
  134. *
  135. * * `rehype-stringify` also has an option `allowDangerousHtml` which will
  136. * output the raw HTML.
  137. * This is typically discouraged as noted by the option name but is useful if
  138. * you completely trust authors
  139. * * `rehype-raw` can handle the raw embedded HTML strings by parsing them
  140. * into standard hast nodes (`element`, `text`, etc);
  141. * this is a heavy task as it needs a full HTML parser,
  142. * but it is the only way to support untrusted content
  143. *
  144. * ###### Footnotes
  145. *
  146. * Many options supported here relate to footnotes.
  147. * Footnotes are not specified by CommonMark,
  148. * which we follow by default.
  149. * They are supported by GitHub,
  150. * so footnotes can be enabled in markdown with `remark-gfm`.
  151. *
  152. * The options `footnoteBackLabel` and `footnoteLabel` define natural language
  153. * that explains footnotes,
  154. * which is hidden for sighted users but shown to assistive technology.
  155. * When your page is not in English,
  156. * you must define translated values.
  157. *
  158. * Back references use ARIA attributes,
  159. * but the section label itself uses a heading that is hidden with an
  160. * `sr-only` class.
  161. * To show it to sighted users,
  162. * define different attributes in `footnoteLabelProperties`.
  163. *
  164. * ###### Clobbering
  165. *
  166. * Footnotes introduces a problem,
  167. * as it links footnote calls to footnote definitions on the page through `id`
  168. * attributes generated from user content,
  169. * which results in DOM clobbering.
  170. *
  171. * DOM clobbering is this:
  172. *
  173. * ```html
  174. * <p id=x></p>
  175. * <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
  176. * ```
  177. *
  178. * Elements by their ID are made available by browsers on the `window` object,
  179. * which is a security risk.
  180. * Using a prefix solves this problem.
  181. *
  182. * More information on how to handle clobbering and the prefix is explained in
  183. * *Example: headings (DOM clobbering)* in `rehype-sanitize`.
  184. *
  185. * ###### Unknown nodes
  186. *
  187. * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
  188. * The default behavior for unknown nodes is:
  189. *
  190. * * when the node has a `value`
  191. * (and doesn’t have `data.hName`, `data.hProperties`, or `data.hChildren`,
  192. * see later),
  193. * create a hast `text` node
  194. * * otherwise,
  195. * create a `<div>` element (which could be changed with `data.hName`),
  196. * with its children mapped from mdast to hast as well
  197. *
  198. * This behavior can be changed by passing an `unknownHandler`.
  199. *
  200. * @overload
  201. * @param {Processor} processor
  202. * @param {Readonly<Options> | null | undefined} [options]
  203. * @returns {TransformBridge}
  204. *
  205. * @overload
  206. * @param {Readonly<Options> | null | undefined} [options]
  207. * @returns {TransformMutate}
  208. *
  209. * @overload
  210. * @param {Readonly<Options> | Processor | null | undefined} [destination]
  211. * @param {Readonly<Options> | null | undefined} [options]
  212. * @returns {TransformBridge | TransformMutate}
  213. *
  214. * @param {Readonly<Options> | Processor | null | undefined} [destination]
  215. * Processor or configuration (optional).
  216. * @param {Readonly<Options> | null | undefined} [options]
  217. * When a processor was given,
  218. * configuration (optional).
  219. * @returns {TransformBridge | TransformMutate}
  220. * Transform.
  221. */
  222. export default function remarkRehype(options?: Readonly<Options> | null | undefined): TransformMutate;
  223. /**
  224. * Turn markdown into HTML.
  225. *
  226. * ##### Notes
  227. *
  228. * ###### Signature
  229. *
  230. * * if a processor is given,
  231. * runs the (rehype) plugins used on it with a hast tree,
  232. * then discards the result (*bridge mode*)
  233. * * otherwise,
  234. * returns a hast tree,
  235. * the plugins used after `remarkRehype` are rehype plugins (*mutate mode*)
  236. *
  237. * > 👉 **Note**:
  238. * > It’s highly unlikely that you want to pass a `processor`.
  239. *
  240. * ###### HTML
  241. *
  242. * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
  243. * as semistandard `raw` nodes.
  244. * Most plugins ignore `raw` nodes but two notable ones don’t:
  245. *
  246. * * `rehype-stringify` also has an option `allowDangerousHtml` which will
  247. * output the raw HTML.
  248. * This is typically discouraged as noted by the option name but is useful if
  249. * you completely trust authors
  250. * * `rehype-raw` can handle the raw embedded HTML strings by parsing them
  251. * into standard hast nodes (`element`, `text`, etc);
  252. * this is a heavy task as it needs a full HTML parser,
  253. * but it is the only way to support untrusted content
  254. *
  255. * ###### Footnotes
  256. *
  257. * Many options supported here relate to footnotes.
  258. * Footnotes are not specified by CommonMark,
  259. * which we follow by default.
  260. * They are supported by GitHub,
  261. * so footnotes can be enabled in markdown with `remark-gfm`.
  262. *
  263. * The options `footnoteBackLabel` and `footnoteLabel` define natural language
  264. * that explains footnotes,
  265. * which is hidden for sighted users but shown to assistive technology.
  266. * When your page is not in English,
  267. * you must define translated values.
  268. *
  269. * Back references use ARIA attributes,
  270. * but the section label itself uses a heading that is hidden with an
  271. * `sr-only` class.
  272. * To show it to sighted users,
  273. * define different attributes in `footnoteLabelProperties`.
  274. *
  275. * ###### Clobbering
  276. *
  277. * Footnotes introduces a problem,
  278. * as it links footnote calls to footnote definitions on the page through `id`
  279. * attributes generated from user content,
  280. * which results in DOM clobbering.
  281. *
  282. * DOM clobbering is this:
  283. *
  284. * ```html
  285. * <p id=x></p>
  286. * <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
  287. * ```
  288. *
  289. * Elements by their ID are made available by browsers on the `window` object,
  290. * which is a security risk.
  291. * Using a prefix solves this problem.
  292. *
  293. * More information on how to handle clobbering and the prefix is explained in
  294. * *Example: headings (DOM clobbering)* in `rehype-sanitize`.
  295. *
  296. * ###### Unknown nodes
  297. *
  298. * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
  299. * The default behavior for unknown nodes is:
  300. *
  301. * * when the node has a `value`
  302. * (and doesn’t have `data.hName`, `data.hProperties`, or `data.hChildren`,
  303. * see later),
  304. * create a hast `text` node
  305. * * otherwise,
  306. * create a `<div>` element (which could be changed with `data.hName`),
  307. * with its children mapped from mdast to hast as well
  308. *
  309. * This behavior can be changed by passing an `unknownHandler`.
  310. *
  311. * @overload
  312. * @param {Processor} processor
  313. * @param {Readonly<Options> | null | undefined} [options]
  314. * @returns {TransformBridge}
  315. *
  316. * @overload
  317. * @param {Readonly<Options> | null | undefined} [options]
  318. * @returns {TransformMutate}
  319. *
  320. * @overload
  321. * @param {Readonly<Options> | Processor | null | undefined} [destination]
  322. * @param {Readonly<Options> | null | undefined} [options]
  323. * @returns {TransformBridge | TransformMutate}
  324. *
  325. * @param {Readonly<Options> | Processor | null | undefined} [destination]
  326. * Processor or configuration (optional).
  327. * @param {Readonly<Options> | null | undefined} [options]
  328. * When a processor was given,
  329. * configuration (optional).
  330. * @returns {TransformBridge | TransformMutate}
  331. * Transform.
  332. */
  333. export default function remarkRehype(destination?: Readonly<Options> | Processor | null | undefined, options?: Readonly<Options> | null | undefined): TransformBridge | TransformMutate;
  334. export type Options = Omit<ToHastOptions, "file">;
  335. /**
  336. * Bridge-mode.
  337. *
  338. * Runs the destination with the new hast tree.
  339. * Discards result.
  340. */
  341. export type TransformBridge = (tree: MdastRoot, file: VFile) => Promise<undefined>;
  342. /**
  343. * Mutate-mode.
  344. *
  345. * Further transformers run on the hast tree.
  346. */
  347. export type TransformMutate = (tree: MdastRoot, file: VFile) => HastRoot;
  348. import type { Processor } from 'unified';
  349. import type { Options as ToHastOptions } from 'mdast-util-to-hast';
  350. import type { Root as MdastRoot } from 'mdast';
  351. import type { VFile } from 'vfile';
  352. import type { Root as HastRoot } from 'hast';
  353. //# sourceMappingURL=index.d.ts.map