import { children as wpChildren } from './gutenberg';

/**
 * Converts an HTML string to `WPBlockChildren`
 * @param {string} html - HTML string to convert
 * @returns {WPBlockChildren} converted structure
 */
const childrenFromHtml = (html) => {
  // Create a DOM element to render the HTML
  const element = document.createElement('div');
  element.innerHTML = html;

  // Parse using Gutenberg's `children` module
  return wpChildren.fromDOM(element.childNodes);
};

export default childrenFromHtml;
