parseHtml.ts 388 B

12345678910111213
  1. import { child } from '../child/child';
  2. /**
  3. * Parses the provided HTML string and returns the first element.
  4. *
  5. * @param html - An HTML string to parse.
  6. *
  7. * @return An Element on success, or otherwise `undefined`.
  8. */
  9. export function parseHtml<E extends HTMLElement>( html: string ): E | undefined {
  10. return child<E>( new DOMParser().parseFromString( html, 'text/html' ).body );
  11. }