UNPKG

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