'use strict';

/**
 * DOMParser.
 *
 * https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
 */
var parse;
if (typeof DOMParser === 'function') {
    var parser = new DOMParser();

    /**
     * Shorthand for `new DOMParser().parseFromString`.
     *
     * @param  {String} html - The HTML string.
     * @return {HTMLDocument}
     */
    parse = function parseFromString(html) {
        return parser.parseFromString(html, 'text/html');
    };

/**
 * DOMImplementation.
 *
 * https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
 */
} else if (typeof document.implementation === 'object') {
    var doc = document.implementation.createHTMLDocument();

    /**
     * Use document created by `document.implementation.createHTMLDocument`.
     *
     * @param  {String} html - The HTML string.
     * @return {HTMLDocument}
     */
    parse = function createHTMLDocument(html) {
        doc.documentElement.innerHTML = html;
        return doc;
    };
}

/**
 * Helper that uses the available parser supported by the browser.
 *
 * @param  {String} html      - The HTML string.
 * @param  {String} [tagName] - The tag name.
 * @return {NodeList|Array}
 */
module.exports = function domparser(html, tagName) {
    var output = parse(html);

    if (output instanceof HTMLDocument) {
        // text
        if (!tagName) {
            return output.getElementsByTagName('body')[0].childNodes;
        }

        // high-level tags
        if (['html', 'head', 'body'].indexOf(tagName) !== -1) {
            return output.getElementsByTagName(tagName);
        }

        // low-level tags
        return output.getElementsByTagName(tagName)[0].parentNode.childNodes;
    }

    return [];
};

@@ -1007,16 +1007,349 @@
 ;%0A    %7D;
+%0A%0A/**%0A * Template.%0A *%0A * https://developer.mozilla.org/docs/Web/HTML/Element/template%0A */%0A%7D else %7B%0A    var template = document.createElement('template');%0A%0A    if (template.content) %7B%0A        parse = function parseTemplate(html) %7B%0A            template.innerHTML = html;%0A            return template.content.childNodes;%0A        %7D;%0A    %7D
 %0A%7D%0A%0A/**%0A
@@ -1627,16 +1627,67 @@
 e(html);
+%0A    if (output instanceof NodeList) return output;
 %0A%0A    if

Update domparser with <template> fallback