Download wp-calypso/client/lib/media-serialization/create-element-from-string.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 680 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/media-serialization/create-element-from-string.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/media-serialization/create-element-from-string.js
-
curl -L -o create-element-from-string.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/media-serialization/create-element-from-string.js
680 Bytes
| 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; | |
| } | |