Debian Codegraph @

mixmark-io-domino/lib/index.js

raw symbols SCIP
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 // Previous API couldn't let you pass '' as a document, and that
13 // yields a slightly different document than createHTMLDocument('')
14 // does. The new `force` parameter lets you pass '' if you want to.
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 /** API for incremental parser. */
26 return {
27 /** Provide an additional chunk of text to be parsed. */
28 write: function(s) {
29 if (s.length > 0) {
30 parser.parse(s, false, function() { return true; });
31 }
32 },
33 /**
34 * Signal that we are done providing input text, optionally
35 * providing one last chunk as a parameter.
36 */
37 end: function(s) {
38 parser.parse(s || '', true, function() { return true; });
39 },
40 /**
41 * Performs a chunk of parsing work, returning at the end of
42 * the next token as soon as shouldPauseFunc() returns true.
43 * Returns true iff there is more work to do.
44 *
45 * For example:
46 * ```
47 * var incrParser = domino.createIncrementalHTMLParser();
48 * incrParser.end('...long html document...');
49 * while (true) {
50 * // Pause every 10ms
51 * var start = Date.now();
52 * var pauseIn10 = function() { return (Date.now() - start) >= 10; };
53 * if (!incrParser.process(pauseIn10)) {
54 * break;
55 * }
56 * ...yield to other tasks, do other housekeeping, etc...
57 * }
58 * ```
59 */
60 process: function(shouldPauseFunc) {
61 return parser.parse('', false, shouldPauseFunc);
62 },
63 /**
64 * Returns the result of the incremental parse. Valid after
65 * `this.end()` has been called and `this.process()` has returned
66 * false.
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;