Skip to content

Instantly share code, notes, and snippets.

@Aqours
Created November 7, 2017 12:18
Show Gist options
  • Save Aqours/ba9e1679e52da400100b6efc1ce6a990 to your computer and use it in GitHub Desktop.
Save Aqours/ba9e1679e52da400100b6efc1ce6a990 to your computer and use it in GitHub Desktop.
解析文档字符串
/**
* 解析文档字符串
*
* @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