mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-12-26 23:16:47 +01:00
Markdown parser: add property selection (#1109)
* Update 70-markdown.html * Update 70-markdown.js * Update package.json * Update 70-markdown.html * Update 70-markdown.js
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="node-red:common.label.property"></span></label>
|
||||||
|
<input type="text" id="node-input-property" style="width:70%;"/>
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-help-name="markdown">
|
<script type="text/html" data-help-name="markdown">
|
||||||
@@ -21,16 +25,23 @@
|
|||||||
category: 'parser',
|
category: 'parser',
|
||||||
color:"#DEBD5C",
|
color:"#DEBD5C",
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""}
|
name: {value:""},
|
||||||
|
property: {value:"payload",required:true}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
icon: "parser-markdown.png",
|
icon: "parser-markdown.png",
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name||"markdown";
|
return this.name||("msg." + this.property)||"markdown";
|
||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
|
},
|
||||||
|
oneditprepare: function() {
|
||||||
|
if (this.property === undefined) {
|
||||||
|
$("#node-input-property").val("payload");
|
||||||
|
}
|
||||||
|
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -3,14 +3,21 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var markdownNode = function(n) {
|
var markdownNode = function(n) {
|
||||||
var md = require('markdown-it')({html:true, linkify:true, typographer:true});
|
var md = require('markdown-it')({html:true, linkify:true, typographer:true});
|
||||||
|
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
|
this.property = n.property || "payload";
|
||||||
var node = this;
|
var node = this;
|
||||||
//<div id="nr-markdown" style="font-family:helvetica neue,arial,helvetica,sans-serif; margin:12px">';
|
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
if (msg.payload !== undefined && typeof msg.payload === "string") {
|
var value = RED.util.getMessageProperty(msg, node.property);
|
||||||
msg.payload = md.render(msg.payload);
|
|
||||||
|
if (value !== undefined && typeof value === "string") {
|
||||||
|
RED.util.setMessageProperty(msg, node.property, md.render(value));
|
||||||
|
node.send(msg);
|
||||||
|
} else {
|
||||||
|
node.warn("No property value found");
|
||||||
}
|
}
|
||||||
node.send(msg);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("markdown",markdownNode);
|
RED.nodes.registerType("markdown",markdownNode);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-markdown",
|
"name": "node-red-node-markdown",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"description": "A Node-RED node to convert a markdown string to html.",
|
"description": "A Node-RED node to convert a markdown string to html.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"markdown-it": "^14.1.0"
|
"markdown-it": "^14.1.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user