index.d.ts
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { type ParserOptions } from './parser/index.js';
import type { DefaultTreeAdapterMap } from './tree-adapters/default.js';
import type { TreeAdapterTypeMap } from './tree-adapters/interface.js';
export { type DefaultTreeAdapterMap, defaultTreeAdapter } from './tree-adapters/default.js';
export type { TreeAdapter, TreeAdapterTypeMap } from './tree-adapters/interface.js';
export { type ParserOptions, /** @internal */ Parser } from './parser/index.js';
export { serialize, serializeOuter, type SerializerOptions } from './serializer/index.js';
export type { ParserError } from './common/error-codes.js';
/** @internal */
export * as foreignContent from './common/foreign-content.js';
/** @internal */
export * as html from './common/html.js';
/** @internal */
export * as Token from './common/token.js';
/** @internal */
export { Tokenizer, type TokenizerOptions, TokenizerMode, type TokenHandler } from './tokenizer/index.js';
/**
* Parses an HTML string.
*
* @param html Input HTML string.
* @param options Parsing options.
* @returns Document
*
* @example
*
* ```js
* const parse5 = require('parse5');
*
* const document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');
*
* console.log(document.childNodes[1].tagName); //> 'html'
*```
*/
export declare function parse<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(html: string, options?: ParserOptions<T>): T['document'];
/**
* Parses an HTML fragment.
*
* @example
*
* ```js
* const parse5 = require('parse5');
*
* const documentFragment = parse5.parseFragment('<table></table>');
*
* console.log(documentFragment.childNodes[0].tagName); //> 'table'
*
* // Parses the html fragment in the context of the parsed <table> element.
* const trFragment = parser.parseFragment(documentFragment.childNodes[0], '<tr><td>Shake it, baby</td></tr>');
*
* console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td'
* ```
*
* @param fragmentContext Parsing context element. If specified, given fragment will be parsed as if it was set to the context element's `innerHTML` property.
* @param html Input HTML fragment string.
* @param options Parsing options.
* @returns DocumentFragment
*/
export declare function parseFragment<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(fragmentContext: T['parentNode'] | null, html: string, options: ParserOptions<T>): T['documentFragment'];
export declare function parseFragment<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(html: string, options?: ParserOptions<T>): T['documentFragment'];
//# sourceMappingURL=index.d.ts.map