Browse Source

Adjust dom parser for HTML type

pull/3691/head
Artur Arseniev 5 years ago
parent
commit
2b705caf6b
  1. 13
      src/parser/model/BrowserParserHtml.js

13
src/parser/model/BrowserParserHtml.js

@ -1,3 +1,5 @@
import { each } from 'underscore';
const htmlType = 'text/html';
// const defaultType = 'application/xml';
const defaultType = htmlType;
@ -11,7 +13,16 @@ export default (str, config = {}) => {
let res;
if (toHTML) {
res = doc.body;
// Replicate the old parser in order to avoid breaking changes
const { head, body } = doc;
// Move all scripts at the bottom of the page
const scripts = head.querySelectorAll('script');
each(scripts, node => body.appendChild(node));
// Move inside body all head children
const hEls = [];
each(head.children, n => hEls.push(n));
each(hEls, (node, i) => body.insertBefore(node, body.children[i]));
res = body;
} else {
res = doc.firstChild;
}

Loading…
Cancel
Save