()
| 25 | } |
| 26 | |
| 27 | function createHtmlParser () { |
| 28 | var Parser = function () {} |
| 29 | |
| 30 | // For Node.js environments |
| 31 | if (typeof document === 'undefined') { |
| 32 | var jsdom = require('jsdom') |
| 33 | Parser.prototype.parseFromString = function (string) { |
| 34 | return jsdom.jsdom(string, { |
| 35 | features: { |
| 36 | FetchExternalResources: [], |
| 37 | ProcessExternalResources: false |
| 38 | } |
| 39 | }) |
| 40 | } |
| 41 | } else { |
| 42 | if (!shouldUseActiveX()) { |
| 43 | Parser.prototype.parseFromString = function (string) { |
| 44 | var doc = document.implementation.createHTMLDocument('') |
| 45 | doc.open() |
| 46 | doc.write(string) |
| 47 | doc.close() |
| 48 | return doc |
| 49 | } |
| 50 | } else { |
| 51 | Parser.prototype.parseFromString = function (string) { |
| 52 | var doc = new window.ActiveXObject('htmlfile') |
| 53 | doc.designMode = 'on' // disable on-page scripts |
| 54 | doc.open() |
| 55 | doc.write(string) |
| 56 | doc.close() |
| 57 | return doc |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | return Parser |
| 62 | } |
| 63 | |
| 64 | function shouldUseActiveX () { |
| 65 | var useActiveX = false |
no test coverage detected