index.d.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Transform mdast to hast.
  3. *
  4. * ##### Notes
  5. *
  6. * ###### HTML
  7. *
  8. * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
  9. * as semistandard `raw` nodes.
  10. * Most utilities ignore `raw` nodes but two notable ones don’t:
  11. *
  12. * * `hast-util-to-html` also has an option `allowDangerousHtml` which will
  13. * output the raw HTML.
  14. * This is typically discouraged as noted by the option name but is useful
  15. * if you completely trust authors
  16. * * `hast-util-raw` can handle the raw embedded HTML strings by parsing them
  17. * into standard hast nodes (`element`, `text`, etc).
  18. * This is a heavy task as it needs a full HTML parser, but it is the only
  19. * way to support untrusted content
  20. *
  21. * ###### Footnotes
  22. *
  23. * Many options supported here relate to footnotes.
  24. * Footnotes are not specified by CommonMark, which we follow by default.
  25. * They are supported by GitHub, so footnotes can be enabled in markdown with
  26. * `mdast-util-gfm`.
  27. *
  28. * The options `footnoteBackLabel` and `footnoteLabel` define natural language
  29. * that explains footnotes, which is hidden for sighted users but shown to
  30. * assistive technology.
  31. * When your page is not in English, you must define translated values.
  32. *
  33. * Back references use ARIA attributes, but the section label itself uses a
  34. * heading that is hidden with an `sr-only` class.
  35. * To show it to sighted users, define different attributes in
  36. * `footnoteLabelProperties`.
  37. *
  38. * ###### Clobbering
  39. *
  40. * Footnotes introduces a problem, as it links footnote calls to footnote
  41. * definitions on the page through `id` attributes generated from user content,
  42. * which results in DOM clobbering.
  43. *
  44. * DOM clobbering is this:
  45. *
  46. * ```html
  47. * <p id=x></p>
  48. * <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
  49. * ```
  50. *
  51. * Elements by their ID are made available by browsers on the `window` object,
  52. * which is a security risk.
  53. * Using a prefix solves this problem.
  54. *
  55. * More information on how to handle clobbering and the prefix is explained in
  56. * Example: headings (DOM clobbering) in `rehype-sanitize`.
  57. *
  58. * ###### Unknown nodes
  59. *
  60. * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
  61. * The default behavior for unknown nodes is:
  62. *
  63. * * when the node has a `value` (and doesn’t have `data.hName`,
  64. * `data.hProperties`, or `data.hChildren`, see later), create a hast `text`
  65. * node
  66. * * otherwise, create a `<div>` element (which could be changed with
  67. * `data.hName`), with its children mapped from mdast to hast as well
  68. *
  69. * This behavior can be changed by passing an `unknownHandler`.
  70. *
  71. * @param {MdastNodes} tree
  72. * mdast tree.
  73. * @param {Options | null | undefined} [options]
  74. * Configuration (optional).
  75. * @returns {HastNodes}
  76. * hast tree.
  77. */
  78. export function toHast(tree: MdastNodes, options?: Options | null | undefined): HastNodes;
  79. import type { Nodes as MdastNodes } from 'mdast';
  80. import type { Options } from './state.js';
  81. import type { Nodes as HastNodes } from 'hast';
  82. //# sourceMappingURL=index.d.ts.map