| 1 |
"use strict"; |
| 2 |
var DOMImplementation = require('./DOMImplementation'); |
| 3 |
var HTMLParser = require('./HTMLParser'); |
| 4 |
var Window = require('./Window'); |
| 5 |
var impl = require('./impl'); |
| 6 |
|
| 7 |
exports.createDOMImplementation = function() { |
| 8 |
return new DOMImplementation(null); |
| 9 |
}; |
| 10 |
|
| 11 |
exports.createDocument = function(html, force) { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
if (html || force) { |
| 16 |
var parser = new HTMLParser(); |
| 17 |
parser.parse(html || '', true); |
| 18 |
return parser.document(); |
| 19 |
} |
| 20 |
return new DOMImplementation(null).createHTMLDocument(""); |
| 21 |
}; |
| 22 |
|
| 23 |
exports.createIncrementalHTMLParser = function() { |
| 24 |
var parser = new HTMLParser(); |
| 25 |
|
| 26 |
return { |
| 27 |
|
| 28 |
write: function(s) { |
| 29 |
if (s.length > 0) { |
| 30 |
parser.parse(s, false, function() { return true; }); |
| 31 |
} |
| 32 |
}, |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
end: function(s) { |
| 38 |
parser.parse(s || '', true, function() { return true; }); |
| 39 |
}, |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
process: function(shouldPauseFunc) { |
| 61 |
return parser.parse('', false, shouldPauseFunc); |
| 62 |
}, |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
document: function() { |
| 69 |
return parser.document(); |
| 70 |
}, |
| 71 |
}; |
| 72 |
}; |
| 73 |
|
| 74 |
exports.createWindow = function(html, address) { |
| 75 |
var document = exports.createDocument(html); |
| 76 |
if (address !== undefined) { document._address = address; } |
| 77 |
return new impl.Window(document); |
| 78 |
}; |
| 79 |
|
| 80 |
exports.impl = impl; |