index.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import type {Position} from 'unist'
  2. import type {VFile} from 'vfile'
  3. export {fromParse5} from './lib/index.js'
  4. /**
  5. * Configuration.
  6. */
  7. export interface Options {
  8. /**
  9. * File used to add positional info to nodes (optional).
  10. *
  11. * If given, the file should represent the original HTML source.
  12. */
  13. file?: VFile | null | undefined
  14. /**
  15. * Which space the document is in (default: `'html'`).
  16. *
  17. * When an `<svg>` element is found in the HTML space, this package already
  18. * automatically switches to and from the SVG space when entering and exiting
  19. * it.
  20. */
  21. space?: Space | null | undefined
  22. /**
  23. * Whether to add extra positional info about starting tags, closing tags,
  24. * and attributes to elements (default: `false`).
  25. *
  26. * > 👉 **Note**: only used when `file` is given.
  27. */
  28. verbose?: boolean | null | undefined
  29. }
  30. /**
  31. * Namespace.
  32. */
  33. export type Space = 'html' | 'svg'
  34. // Register data on hast.
  35. declare module 'hast' {
  36. interface ElementData {
  37. position: {
  38. /**
  39. * Positional info of the start tag of an element.
  40. *
  41. * Field added by `hast-util-from-parse5` (a utility used inside
  42. * `rehype-parse` responsible for parsing HTML), when passing
  43. * `verbose: true`.
  44. */
  45. opening?: Position | undefined
  46. /**
  47. * Positional info of the end tag of an element.
  48. *
  49. * Field added by `hast-util-from-parse5` (a utility used inside
  50. * `rehype-parse` responsible for parsing HTML), when passing
  51. * `verbose: true`.
  52. */
  53. closing?: Position | undefined
  54. /**
  55. * Positional info of the properties of an element.
  56. *
  57. * Field added by `hast-util-from-parse5` (a utility used inside
  58. * `rehype-parse` responsible for parsing HTML), when passing
  59. * `verbose: true`.
  60. */
  61. properties?: Record<string, Position | undefined> | undefined
  62. }
  63. }
  64. interface RootData {
  65. /**
  66. * Whether the document was using quirksmode.
  67. *
  68. * Field added by `hast-util-from-parse5` (a utility used inside
  69. * `rehype-parse` responsible for parsing HTML).
  70. */
  71. quirksMode?: boolean | undefined
  72. }
  73. }