index.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * Component to render markdown.
  3. *
  4. * This is a synchronous component.
  5. * When using async plugins,
  6. * see {@linkcode MarkdownAsync} or {@linkcode MarkdownHooks}.
  7. *
  8. * @param {Readonly<Options>} options
  9. * Props.
  10. * @returns {ReactElement}
  11. * React element.
  12. */
  13. export function Markdown(options: Readonly<Options>): ReactElement;
  14. /**
  15. * Component to render markdown with support for async plugins
  16. * through async/await.
  17. *
  18. * Components returning promises are supported on the server.
  19. * For async support on the client,
  20. * see {@linkcode MarkdownHooks}.
  21. *
  22. * @param {Readonly<Options>} options
  23. * Props.
  24. * @returns {Promise<ReactElement>}
  25. * Promise to a React element.
  26. */
  27. export function MarkdownAsync(options: Readonly<Options>): Promise<ReactElement>;
  28. /**
  29. * Component to render markdown with support for async plugins through hooks.
  30. *
  31. * This uses `useEffect` and `useState` hooks.
  32. * Hooks run on the client and do not immediately render something.
  33. * For async support on the server,
  34. * see {@linkcode MarkdownAsync}.
  35. *
  36. * @param {Readonly<HooksOptions>} options
  37. * Props.
  38. * @returns {ReactNode}
  39. * React node.
  40. */
  41. export function MarkdownHooks(options: Readonly<HooksOptions>): ReactNode;
  42. /**
  43. * Make a URL safe.
  44. *
  45. * @satisfies {UrlTransform}
  46. * @param {string} value
  47. * URL.
  48. * @returns {string}
  49. * Safe URL.
  50. */
  51. export function defaultUrlTransform(value: string): string;
  52. /**
  53. * Filter elements.
  54. */
  55. export type AllowElement = (element: Readonly<Element>, index: number, parent: Readonly<Parents> | undefined) => boolean | null | undefined;
  56. /**
  57. * Extra fields we pass.
  58. */
  59. export type ExtraProps = {
  60. /**
  61. * passed when `passNode` is on.
  62. */
  63. node?: Element | undefined;
  64. };
  65. /**
  66. * Map tag names to components.
  67. */
  68. export type Components = { [Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & ExtraProps> | keyof JSX.IntrinsicElements; };
  69. /**
  70. * Deprecation.
  71. */
  72. export type Deprecation = {
  73. /**
  74. * Old field.
  75. */
  76. from: string;
  77. /**
  78. * ID in readme.
  79. */
  80. id: string;
  81. /**
  82. * New field.
  83. */
  84. to?: keyof Options;
  85. };
  86. /**
  87. * Configuration.
  88. */
  89. export type Options = {
  90. /**
  91. * Filter elements (optional);
  92. * `allowedElements` / `disallowedElements` is used first.
  93. */
  94. allowElement?: AllowElement | null | undefined;
  95. /**
  96. * Tag names to allow (default: all tag names);
  97. * cannot combine w/ `disallowedElements`.
  98. */
  99. allowedElements?: ReadonlyArray<string> | null | undefined;
  100. /**
  101. * Markdown.
  102. */
  103. children?: string | null | undefined;
  104. /**
  105. * Map tag names to components.
  106. */
  107. components?: Components | null | undefined;
  108. /**
  109. * Tag names to disallow (default: `[]`);
  110. * cannot combine w/ `allowedElements`.
  111. */
  112. disallowedElements?: ReadonlyArray<string> | null | undefined;
  113. /**
  114. * List of rehype plugins to use.
  115. */
  116. rehypePlugins?: PluggableList | null | undefined;
  117. /**
  118. * List of remark plugins to use.
  119. */
  120. remarkPlugins?: PluggableList | null | undefined;
  121. /**
  122. * Options to pass through to `remark-rehype`.
  123. */
  124. remarkRehypeOptions?: Readonly<RemarkRehypeOptions> | null | undefined;
  125. /**
  126. * Ignore HTML in markdown completely (default: `false`).
  127. */
  128. skipHtml?: boolean | null | undefined;
  129. /**
  130. * Extract (unwrap) what’s in disallowed elements (default: `false`);
  131. * normally when say `strong` is not allowed, it and it’s children are dropped,
  132. * with `unwrapDisallowed` the element itself is replaced by its children.
  133. */
  134. unwrapDisallowed?: boolean | null | undefined;
  135. /**
  136. * Change URLs (default: `defaultUrlTransform`)
  137. */
  138. urlTransform?: UrlTransform | null | undefined;
  139. };
  140. /**
  141. * Configuration specifically for {@linkcode MarkdownHooks}.
  142. */
  143. export type HooksOptionsOnly = {
  144. /**
  145. * Content to render while the processor processing the markdown (optional).
  146. */
  147. fallback?: ReactNode | null | undefined;
  148. };
  149. /**
  150. * Configuration for {@linkcode MarkdownHooks};
  151. * extends the regular {@linkcode Options} with a `fallback` prop.
  152. */
  153. export type HooksOptions = Options & HooksOptionsOnly;
  154. /**
  155. * Transform all URLs.
  156. */
  157. export type UrlTransform = (url: string, key: string, node: Readonly<Element>) => string | null | undefined;
  158. import type { ReactElement } from 'react';
  159. import type { ReactNode } from 'react';
  160. import type { Element } from 'hast';
  161. import type { Parents } from 'hast';
  162. import type { JSX } from 'react';
  163. import type { ComponentType } from 'react';
  164. import type { PluggableList } from 'unified';
  165. import type { Options as RemarkRehypeOptions } from 'remark-rehype';
  166. //# sourceMappingURL=index.d.ts.map