index.d.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { type ParserOptions } from './parser/index.js';
  2. import type { DefaultTreeAdapterMap } from './tree-adapters/default.js';
  3. import type { TreeAdapterTypeMap } from './tree-adapters/interface.js';
  4. export { type DefaultTreeAdapterMap, defaultTreeAdapter } from './tree-adapters/default.js';
  5. export type { TreeAdapter, TreeAdapterTypeMap } from './tree-adapters/interface.js';
  6. export { type ParserOptions, /** @internal */ Parser } from './parser/index.js';
  7. export { serialize, serializeOuter, type SerializerOptions } from './serializer/index.js';
  8. export { ERR as ErrorCodes, type ParserError } from './common/error-codes.js';
  9. /** @internal */
  10. export * as foreignContent from './common/foreign-content.js';
  11. /** @internal */
  12. export * as html from './common/html.js';
  13. /** @internal */
  14. export * as Token from './common/token.js';
  15. /** @internal */
  16. export { 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. */
  34. export 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. */
  58. export declare function parseFragment<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(fragmentContext: T['parentNode'] | null, html: string, options: ParserOptions<T>): T['documentFragment'];
  59. export declare function parseFragment<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(html: string, options?: ParserOptions<T>): T['documentFragment'];
  60. //# sourceMappingURL=index.d.ts.map