diff --git a/nodes/core/parsers/70-HTML.js b/nodes/core/parsers/70-HTML.js
index c453a56d5..5bb391a00 100644
--- a/nodes/core/parsers/70-HTML.js
+++ b/nodes/core/parsers/70-HTML.js
@@ -31,6 +31,11 @@ module.exports = function(RED) {
try {
var $ = cheerio.load(msg.payload);
var pay = [];
+ var count = 0;
+ $(tag).each(function() {
+ count++;
+ });
+ var index = 0;
$(tag).each(function() {
if (node.as === "multi") {
var pay2 = null;
@@ -41,6 +46,13 @@ module.exports = function(RED) {
/* istanbul ignore else */
if (pay2) {
msg.payload = pay2;
+ msg.parts = {
+ id: msg._msgid,
+ index: index,
+ count: count,
+ type: "string",
+ ch: ""
+ };
node.send(msg);
}
}
@@ -50,6 +62,7 @@ module.exports = function(RED) {
if (node.ret === "attr") { pay.push( this.attribs ); }
//if (node.ret === "val") { pay.push( $(this).val() ); }
}
+ index++;
});
if ((node.as === "single") && (pay.length !== 0)) {
msg.payload = pay;
diff --git a/test/nodes/core/parsers/70-HTML_spec.js b/test/nodes/core/parsers/70-HTML_spec.js
index 9382c6cf1..c518c0d35 100644
--- a/test/nodes/core/parsers/70-HTML_spec.js
+++ b/test/nodes/core/parsers/70-HTML_spec.js
@@ -207,12 +207,29 @@ describe('html node', function() {
describe('multiple messages', function(){
var cnt = 0;
+ var parts_id = undefined;
afterEach(function() {
cnt.should.be.exactly(2);
cnt = 0;
+ parts_id = undefined;
});
+ function check_parts(msg, index, count) {
+ msg.should.have.property('parts');
+ msg.parts.should.have.property('id');
+ if(parts_id === undefined) {
+ parts_id = msg.parts.id;
+ }
+ else {
+ msg.parts.should.have.property('id', parts_id);
+ }
+ msg.parts.should.have.property('index', index);
+ msg.parts.should.have.property('count', count);
+ msg.parts.should.have.property('type', 'string');
+ msg.parts.should.have.property('ch', '');
+ }
+
it('should retrieve list contents as html as default with output as multiple msgs ', function(done) {
fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],tag:"ul",as:"multi"},
@@ -224,6 +241,7 @@ describe('html node', function() {
n2.on("input", function(msg) {
cnt++;
msg.should.have.property('topic', 'bar');
+ check_parts(msg, cnt -1, 2);
if (cnt !== 1 && cnt !== 2) {
return false;
}
@@ -252,6 +270,7 @@ describe('html node', function() {
n2.on("input", function(msg) {
cnt++;
msg.should.have.property('topic', 'bar');
+ check_parts(msg, cnt -1, 2);
if (cnt !== 1 && cnt !== 2) {
return false;
}
@@ -281,6 +300,7 @@ describe('html node', function() {
msg.should.have.property('payload');
msg.payload.should.have.property('src','foo.png');
msg.should.have.property('topic', 'bar');
+ check_parts(msg, 0, 1);
cnt = 2; // frig the answer as only one img tag
done();
});