|
| 1 | +// TypeScript Version: 3.5 |
| 2 | + |
| 3 | +import {Node} from 'unist' |
| 4 | +import {StringifyEntitiesOptions} from 'stringify-entities' |
| 5 | + |
| 6 | +declare namespace hastUtilToHtml { |
| 7 | + interface HastUtilToHtmlOptions { |
| 8 | + /** |
| 9 | + * Whether the *root* of the *tree* is in the `'html'` or `'svg'` space. |
| 10 | + * |
| 11 | + * If an `svg` element is found in the HTML space, `toHtml` automatically switches to the SVG space when entering the element, and switches back when exiting. |
| 12 | + * |
| 13 | + * @defaultValue 'html' |
| 14 | + */ |
| 15 | + space: 'html' | 'svg' |
| 16 | + |
| 17 | + /** |
| 18 | + * Configuration for `stringify-entities`. |
| 19 | + * Do not use `escapeOnly`, `attribute`, or `subset` (`toHtml` already passes those, so they won’t work). |
| 20 | + * However, `useNamedReferences`, `useShortestReferences`, and `omitOptionalSemicolons` are all fine. |
| 21 | + * |
| 22 | + * @defaultValue {} |
| 23 | + */ |
| 24 | + entities: Partial< |
| 25 | + Omit<StringifyEntitiesOptions, 'escapeOnly' | 'attribute' | 'subset'> |
| 26 | + > |
| 27 | + |
| 28 | + /** |
| 29 | + * Tag names of *elements* to stringify without closing tag. |
| 30 | + * |
| 31 | + * Not used in the SVG space. |
| 32 | + * |
| 33 | + * @defaultValue `require('html-void-elements')` |
| 34 | + */ |
| 35 | + voids: string[] |
| 36 | + |
| 37 | + /** |
| 38 | + * Use an `<!DOCTYPE…` instead of `<!doctype…`. |
| 39 | + * Useless except for XHTML. |
| 40 | + * |
| 41 | + * @defaultValue false |
| 42 | + */ |
| 43 | + upperDoctype: boolean |
| 44 | + |
| 45 | + /** |
| 46 | + * Preferred quote to use. |
| 47 | + * |
| 48 | + * @defaultValue '"' |
| 49 | + */ |
| 50 | + quote: '"' | "'" |
| 51 | + |
| 52 | + /** |
| 53 | + * Use the other quote if that results in less bytes. |
| 54 | + * |
| 55 | + * @defaultValue false |
| 56 | + */ |
| 57 | + quoteSmart: boolean |
| 58 | + |
| 59 | + /** |
| 60 | + * Leave attributes unquoted if that results in less bytes. |
| 61 | + * |
| 62 | + * Not used in the SVG space. |
| 63 | + * |
| 64 | + * @defaultValue false |
| 65 | + */ |
| 66 | + preferUnquoted: boolean |
| 67 | + |
| 68 | + /** |
| 69 | + * Omit optional opening and closing tags. |
| 70 | + * For example, in `<ol><li>one</li><li>two</li></ol>`, both `</li>` closing tags can be omitted. |
| 71 | + * The first because it’s followed by another `li`, the last because it’s followed by nothing. |
| 72 | + * |
| 73 | + * Not used in the SVG space. |
| 74 | + * |
| 75 | + * @defaultValue false |
| 76 | + */ |
| 77 | + omitOptionalTags: boolean |
| 78 | + |
| 79 | + /** |
| 80 | + * Collapse empty attributes: `class=""` is stringified as `class` instead. |
| 81 | + * **Note**: boolean attributes, such as `hidden`, are always collapsed. |
| 82 | + * |
| 83 | + * Not used in the SVG space. |
| 84 | + * |
| 85 | + * @defaultValue false |
| 86 | + */ |
| 87 | + collapseEmptyAttributes: boolean |
| 88 | + |
| 89 | + /** |
| 90 | + * Close self-closing nodes with an extra slash (`/`): `<img />` instead of `<img>`. |
| 91 | + * See `tightSelfClosing` to control whether a space is used before the slash. |
| 92 | + * |
| 93 | + * Not used in the SVG space. |
| 94 | + * |
| 95 | + * @defaultValue false |
| 96 | + */ |
| 97 | + closeSelfClosing: boolean |
| 98 | + |
| 99 | + /** |
| 100 | + * Close SVG elements without any content with slash (`/`) on the opening tag instead of an end tag: `<circle />` instead of `<circle></circle>`. |
| 101 | + * See `tightSelfClosing` to control whether a space is used before the slash. |
| 102 | + * |
| 103 | + * Not used in the HTML space. |
| 104 | + * |
| 105 | + * @defaultValue false |
| 106 | + */ |
| 107 | + closeEmptyElements: boolean |
| 108 | + |
| 109 | + /** |
| 110 | + * Do not use an extra space when closing self-closing elements: `<img/>` instead of `<img />`. |
| 111 | + * **Note**: Only used if `closeSelfClosing: true` or `closeEmptyElements: true`. |
| 112 | + * |
| 113 | + * @defaultValue false |
| 114 | + */ |
| 115 | + tightSelfClosing: boolean |
| 116 | + |
| 117 | + /** |
| 118 | + * Join known comma-separated attribute values with just a comma (`,`), instead of padding them on the right as well (`,·`, where `·` represents a space). |
| 119 | + * |
| 120 | + * @defaultValue false |
| 121 | + */ |
| 122 | + tightCommaSeparatedLists: boolean |
| 123 | + |
| 124 | + /** |
| 125 | + * Join attributes together, without white-space, if possible: `class="a b" title="c d"` is stringified as `class="a b"title="c d"` instead to save bytes. |
| 126 | + * **Note**: creates invalid (but working) markup. |
| 127 | + * |
| 128 | + * Not used in the SVG space. |
| 129 | + * |
| 130 | + * @defaultValue false |
| 131 | + */ |
| 132 | + tightAttributes: boolean |
| 133 | + |
| 134 | + /** |
| 135 | + * Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of `<!doctype html>` to save bytes. |
| 136 | + * **Note**: creates invalid (but working) markup. |
| 137 | + * |
| 138 | + * @defaultValue false |
| 139 | + */ |
| 140 | + tightDoctype: boolean |
| 141 | + |
| 142 | + /** |
| 143 | + * Do not encode characters which cause parse errors (even though they work), to save bytes. |
| 144 | + * **Note**: creates invalid (but working) markup. |
| 145 | + * |
| 146 | + * Not used in the SVG space. |
| 147 | + * |
| 148 | + * @defaultValue false |
| 149 | + */ |
| 150 | + allowParseErrors: boolean |
| 151 | + |
| 152 | + /** |
| 153 | + * Do not encode some characters which cause XSS vulnerabilities in older browsers. |
| 154 | + * **Note**: Only set this if you completely trust the content. |
| 155 | + * |
| 156 | + * @defaultValue false |
| 157 | + */ |
| 158 | + allowDangerousCharacters: boolean |
| 159 | + |
| 160 | + /** |
| 161 | + * Allow `raw` nodes and insert them as raw HTML. |
| 162 | + * When falsey, encodes `raw` nodes. |
| 163 | + * **Note**: Only set this if you completely trust the content. |
| 164 | + * |
| 165 | + * @defaultValue false |
| 166 | + */ |
| 167 | + allowDangerousHTML: boolean |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +/** |
| 172 | + * Stringify the given **hast** *tree*. |
| 173 | + * |
| 174 | + * @param tree given hast tree |
| 175 | + * @param options configuration for stringifier |
| 176 | + */ |
| 177 | +declare function hastUtilToHtml( |
| 178 | + tree: Node, |
| 179 | + options?: Partial<hastUtilToHtml.HastUtilToHtmlOptions> |
| 180 | +): string |
| 181 | + |
| 182 | +export = hastUtilToHtml |
0 commit comments