File size: 680 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { domForHtml } from 'calypso/lib/post-normalizer/utils';

/**
 * Given a string, attempts to generate the equivalent HTMLElement
 * @param {string}      string HTML string
 * @returns {HTMLElement}        Element object representing string
 */

export default function ( string ) {
	let wrapper;
	if ( document.implementation && document.implementation.createHTMLDocument ) {
		wrapper = document.implementation.createHTMLDocument( '' ).body;
	} else {
		try {
			return domForHtml( string ).firstChild;
		} catch ( e ) {} // eslint-disable-line no-empty
	}

	wrapper = wrapper || document.createElement( 'div' );
	wrapper.innerHTML = string;
	return wrapper.firstChild;
}