UNPKG

1.98 kBTypeScriptView Raw
1import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
2import { type DefaultTreeAdapterMap } from '../tree-adapters/default.js';
3export interface SerializerOptions<T extends TreeAdapterTypeMap> {
4 /**
5 * Specifies input tree format.
6 *
7 * @default `treeAdapters.default`
8 */
9 treeAdapter?: TreeAdapter<T>;
10 /**
11 * The [scripting flag](https://html.spec.whatwg.org/multipage/parsing.html#scripting-flag). If set
12 * to `true`, `noscript` element content will not be escaped.
13 *
14 * @default `true`
15 */
16 scriptingEnabled?: boolean;
17}
18/**
19 * Serializes an AST node to an HTML string.
20 *
21 * @example
22 *
23 * ```js
24 * const parse5 = require('parse5');
25 *
26 * const document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');
27 *
28 * // Serializes a document.
29 * const html = parse5.serialize(document);
30 *
31 * // Serializes the <html> element content.
32 * const str = parse5.serialize(document.childNodes[1]);
33 *
34 * console.log(str); //> '<head></head><body>Hi there!</body>'
35 * ```
36 *
37 * @param node Node to serialize.
38 * @param options Serialization options.
39 */
40export declare function serialize<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(node: T['parentNode'], options?: SerializerOptions<T>): string;
41/**
42 * Serializes an AST element node to an HTML string, including the element node.
43 *
44 * @example
45 *
46 * ```js
47 * const parse5 = require('parse5');
48 *
49 * const document = parse5.parseFragment('<div>Hello, <b>world</b>!</div>');
50 *
51 * // Serializes the <div> element.
52 * const html = parse5.serializeOuter(document.childNodes[0]);
53 *
54 * console.log(str); //> '<div>Hello, <b>world</b>!</div>'
55 * ```
56 *
57 * @param node Node to serialize.
58 * @param options Serialization options.
59 */
60export declare function serializeOuter<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(node: T['node'], options?: SerializerOptions<T>): string;
61//# sourceMappingURL=index.d.ts.map
\No newline at end of file