index.js 686 B

1234567891011121314151617181920212223242526
  1. /**
  2. * @typedef {import('hast').Root} Root
  3. *
  4. * @typedef {Pick<import('hast-util-from-html').Options, 'fragment'>} Options
  5. */
  6. import {fromHtml} from 'hast-util-from-html'
  7. import {removePosition} from 'unist-util-remove-position'
  8. /**
  9. * Turn HTML into a syntax tree, using browser APIs when available, so it has
  10. * a smaller bundle size there.
  11. *
  12. * @param {string} value
  13. * Serialized HTML to parse.
  14. * @param {Options | null | undefined} [options]
  15. * Configuration (optional).
  16. * @returns {Root}
  17. * Tree.
  18. */
  19. export function fromHtmlIsomorphic(value, options) {
  20. const tree = fromHtml(value, options)
  21. removePosition(tree, {force: true})
  22. delete tree.data
  23. return tree
  24. }