index.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import type { TreeAdapter, TreeAdapterTypeMap } from '../tree-adapters/interface.js';
  2. import { type DefaultTreeAdapterMap } from '../tree-adapters/default.js';
  3. export 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. */
  40. export 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 str = 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. */
  60. export declare function serializeOuter<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap>(node: T['node'], options?: SerializerOptions<T>): string;