From 7b01457038c7cfb758793da33f3451a11f2ee6a0 Mon Sep 17 00:00:00 2001 From: Gerrit Riessen Date: Sat, 6 Jan 2024 00:12:09 +0100 Subject: [PATCH] HTML node: add option to for attribites and content --- .../@node-red/nodes/core/parsers/70-HTML.html | 15 ++++++++++++++- .../@node-red/nodes/core/parsers/70-HTML.js | 11 +++++++++++ .../@node-red/nodes/locales/en-US/messages.json | 6 ++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.html b/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.html index 3357ae011..cda57386e 100644 --- a/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.html +++ b/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.html @@ -14,6 +14,7 @@ + @@ -28,6 +29,10 @@ +
@@ -45,7 +50,8 @@ outproperty: {value:"payload", validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true }) }, tag: {value:""}, ret: {value:"html"}, - as: {value:"single"} + as: {value:"single"}, + chr: { value: "_" } }, inputs:1, outputs:1, @@ -59,6 +65,13 @@ oneditprepare: function() { $("#node-input-property").typedInput({default:'msg',types:['msg']}); $("#node-input-outproperty").typedInput({default:'msg',types:['msg']}); + $('#node-input-ret').on( 'change', () => { + if ( $('#node-input-ret').val() == "compl" ) { + $('#html-prefix-row').show() + } else { + $('#html-prefix-row').hide() + } + }); } }); diff --git a/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.js b/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.js index 073b98689..c4485fe9b 100644 --- a/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.js +++ b/packages/node_modules/@node-red/nodes/core/parsers/70-HTML.js @@ -25,6 +25,7 @@ module.exports = function(RED) { this.tag = n.tag; this.ret = n.ret || "html"; this.as = n.as || "single"; + this.chr = n.chr || "_"; var node = this; this.on("input", function(msg,send,done) { var value = RED.util.getMessageProperty(msg,node.property); @@ -47,6 +48,11 @@ module.exports = function(RED) { if (node.ret === "attr") { pay2 = Object.assign({},this.attribs); } + if (node.ret === "compl") { + var bse = {} + bse[node.chr] = $(this).html().trim() + pay2 = Object.assign(bse, this.attribs); + } //if (node.ret === "val") { pay2 = $(this).val(); } /* istanbul ignore else */ if (pay2) { @@ -69,6 +75,11 @@ module.exports = function(RED) { var attribs = Object.assign({},this.attribs); pay.push( attribs ); } + if (node.ret === "compl") { + var bse = {} + bse[node.chr] = $(this).html().trim() + pay.push( Object.assign(bse, this.attribs) ) + } //if (node.ret === "val") { pay.push( $(this).val() ); } } index++; diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json index a7b583878..a334edc90 100644 --- a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json +++ b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json @@ -887,12 +887,14 @@ "label": { "select": "Selector", "output": "Output", - "in": "in" + "in": "in", + "prefix": "Property name for HTML content" }, "output": { "html": "the html content of the elements", "text": "only the text content of the elements", - "attr": "an object of any attributes of the elements" + "attr": "an object of any attributes of the elements", + "compl": "an object of any attributes of the elements and html contents" }, "format": { "single": "as a single message containing an array",