Created
November 7, 2017 12:18
-
-
Save Aqours/ba9e1679e52da400100b6efc1ce6a990 to your computer and use it in GitHub Desktop.
解析文档字符串
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 解析文档字符串 | |
* | |
* @param {string} html | |
* @returns {DocumentFragment} | |
*/ | |
function parseHTML(html) { | |
const parser = new DOMParser(); | |
const context = parser.parseFromString(html, "text/html"); | |
const children = context.body.children; | |
const fragment = new DocumentFragment(); | |
fragment.append(...children); | |
return fragment; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment