UNPKG

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