|
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = documentOuterHTML;
-
- var _doctypeToString = require('doctype-to-string');
-
- var _doctypeToString2 = _interopRequireDefault(_doctypeToString);
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
-
- function documentOuterHTML(document) {
- if (!document || document.nodeType === undefined || document.nodeType !== document.DOCUMENT_NODE) {
- throw new TypeError('Expected a Document');
- }
- var html = [].concat(_toConsumableArray(document.childNodes)).map(function (node) {
- return nodeToString(node);
- }).join('\n');
- return html;
- }
-
- function nodeToString(node) {
- switch (node.nodeType) {
- case node.ELEMENT_NODE:
- return node.outerHTML;
- case node.TEXT_NODE:
- return node.textContent;
- case node.COMMENT_NODE:
- return '<!--' + node.textContent + '-->';
- case node.DOCUMENT_TYPE_NODE:
- return (0, _doctypeToString2.default)(node);
- default:
- throw new TypeError('Unexpected node type: ' + node.nodeType);
- }
- }
|