|
| 1 | +// Minimum TypeScript Version: 3.2 |
| 2 | +import {Definition} from 'mdast' |
| 3 | +import {DefinitionCache} from 'mdast-util-definitions' |
| 4 | +import {Node} from 'unist' |
| 5 | + |
| 6 | +declare namespace toHast { |
| 7 | + interface H { |
| 8 | + dangerous?: boolean |
| 9 | + definition: DefinitionCache |
| 10 | + footNoteById: Definition |
| 11 | + footnoreOrder: string[] |
| 12 | + handlers: Handlers |
| 13 | + unknownHandler: Handler |
| 14 | + (node: Node, tagName: string, props?: object, children?: Node[]): Node |
| 15 | + augment(left: Node, right: Node): Node |
| 16 | + } |
| 17 | + |
| 18 | + type Handler = (h: H, node: Node) => any |
| 19 | + |
| 20 | + interface Handlers { |
| 21 | + [type: string]: Handler |
| 22 | + } |
| 23 | + |
| 24 | + interface Options { |
| 25 | + /** |
| 26 | + * Whether to allow [`html`](https://github.com/syntax-tree/mdast#html) nodes and inject them as raw HTML |
| 27 | + * |
| 28 | + * Only do this when using [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html) |
| 29 | + * ([`rehype-stringify`](https://github.com/rehypejs/rehype/tree/master/packages/rehype-stringify)) or |
| 30 | + * [`hast-util-raw`](https://github.com/syntax-tree/hast-util-raw) |
| 31 | + * ([`rehype-raw`](https://github.com/rehypejs/rehype-raw)) later: `raw` nodes are not a standard part of |
| 32 | + * [hast](https://github.com/syntax-tree/hast). |
| 33 | + * |
| 34 | + * @default false |
| 35 | + */ |
| 36 | + allowDangerousHtml?: boolean |
| 37 | + |
| 38 | + /** |
| 39 | + * Set to `true` to prefer the first when duplicate definitions are found. |
| 40 | + * |
| 41 | + * The default behavior is to prefer the last duplicate definition. |
| 42 | + * |
| 43 | + * @default false |
| 44 | + */ |
| 45 | + commonmark?: boolean |
| 46 | + |
| 47 | + /** |
| 48 | + * Object mapping [mdast](https://github.com/syntax-tree/mdast) |
| 49 | + * [nodes](https://github.com/syntax-tree/mdast#nodes) to functions handling them. |
| 50 | + * Take a look at |
| 51 | + * [`lib/handlers/`](https://github.com/syntax-tree/mdast-util-to-hast/blob/master/lib/handlers) |
| 52 | + * for examples. |
| 53 | + */ |
| 54 | + handlers?: Handlers |
| 55 | + |
| 56 | + /** |
| 57 | + * Handler for all unknown nodes. |
| 58 | + * |
| 59 | + * Default behavior: |
| 60 | + * |
| 61 | + * * Unknown nodes with [`children`][child] are transformed to `div` elements |
| 62 | + * * Unknown nodes with `value` are transformed to [`text`][hast-text] nodes |
| 63 | + */ |
| 64 | + unknownHandler?: Handler |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * Transform the given [mdast](https://github.com/syntax-tree/mdast) |
| 70 | + * [tree](https://github.com/syntax-tree/unist#tree) to a |
| 71 | + * [hast](https://github.com/syntax-tree/hast) [tree](https://github.com/syntax-tree/unist#tree). |
| 72 | + */ |
| 73 | +declare function toHast(node: Node, options?: toHast.Options): Node |
| 74 | + |
| 75 | +export = toHast |
0 commit comments