load-parse.js 1.3 KB

12345678910111213141516171819202122232425262728
  1. import { getLoad } from './load.js';
  2. import { getParse } from './parse.js';
  3. import { renderWithParse5, parseWithParse5 } from './parsers/parse5-adapter.js';
  4. import renderWithHtmlparser2 from 'dom-serializer';
  5. import { parseDocument as parseWithHtmlparser2 } from 'htmlparser2';
  6. const parse = getParse((content, options, isDocument, context) => options._useHtmlParser2
  7. ? parseWithHtmlparser2(content, options)
  8. : parseWithParse5(content, options, isDocument, context));
  9. // Duplicate docs due to https://github.com/TypeStrong/typedoc/issues/1616
  10. /**
  11. * Create a querying function, bound to a document created from the provided
  12. * markup.
  13. *
  14. * Note that similar to web browser contexts, this operation may introduce
  15. * `<html>`, `<head>`, and `<body>` elements; set `isDocument` to `false` to
  16. * switch to fragment mode and disable this.
  17. *
  18. * @category Loading
  19. * @param content - Markup to be loaded.
  20. * @param options - Options for the created instance.
  21. * @param isDocument - Allows parser to be switched to fragment mode.
  22. * @returns The loaded document.
  23. * @see {@link https://cheerio.js.org#loading} for additional usage information.
  24. */
  25. export const load = getLoad(parse, (dom, options) => options._useHtmlParser2
  26. ? renderWithHtmlparser2(dom, options)
  27. : renderWithParse5(dom));
  28. //# sourceMappingURL=load-parse.js.map