domhandler
Advanced tools
Comparing version 2.2.1 to 2.3.0
13
index.js
@@ -22,2 +22,3 @@ var ElementType = require("domelementtype"); | ||
this._tagStack = []; | ||
this._parser = this._parser || null; | ||
} | ||
@@ -27,5 +28,10 @@ | ||
var defaultOpts = { | ||
normalizeWhitespace: false //Replace all whitespace with single spaces | ||
normalizeWhitespace: false, //Replace all whitespace with single spaces | ||
withStartIndices: false, //Add startIndex properties to nodes | ||
}; | ||
DomHandler.prototype.onparserinit = function(parser){ | ||
this._parser = parser; | ||
}; | ||
//Resets the handler back to starting state | ||
@@ -40,2 +46,3 @@ DomHandler.prototype.onreset = function(){ | ||
this._done = true; | ||
this._parser = null; | ||
this._handleCallback(null); | ||
@@ -66,2 +73,6 @@ }; | ||
if(this._options.withStartIndices){ | ||
element.startIndex = this._parser.startIndex; | ||
} | ||
if (this._options.withDomLvl1) { | ||
@@ -68,0 +79,0 @@ element.__proto__ = element.type === "tag" ? ElementPrototype : NodePrototype; |
{ | ||
"name": "domhandler", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "handler for htmlparser2 that turns pages into a dom", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"htmlparser2": "3.2", | ||
"htmlparser2": "3.8", | ||
"mocha": "1", | ||
@@ -27,0 +27,0 @@ "jshint": "~2.3.0" |
@@ -103,1 +103,4 @@ #DOMHandler [![Build Status](https://secure.travis-ci.org/fb55/DomHandler.png)](http://travis-ci.org/fb55/DomHandler) | ||
``` | ||
##Option: withStartIndices | ||
Indicates whether a `startIndex` property will be added to nodes. When the parser is used in a non-streaming fashion, `startIndex` is an integer indicating the position of the start of the node in the document. The default value is "false". |
@@ -38,6 +38,8 @@ var fs = require("fs"), | ||
//first, try to run the test via chunks | ||
for(var i = 0; i < data.length; i++){ | ||
parser.write(data.charAt(i)); | ||
if (test.streaming || test.streaming === undefined){ | ||
for(var i = 0; i < data.length; i++){ | ||
parser.write(data.charAt(i)); | ||
} | ||
parser.done(); | ||
} | ||
parser.done(); | ||
@@ -44,0 +46,0 @@ //then parse everything |
26797
32
979
106