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>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</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 type="text/html" data-help-name="markdown">
|
||||
@@ -21,16 +25,23 @@
|
||||
category: 'parser',
|
||||
color:"#DEBD5C",
|
||||
defaults: {
|
||||
name: {value:""}
|
||||
name: {value:""},
|
||||
property: {value:"payload",required:true}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "parser-markdown.png",
|
||||
label: function() {
|
||||
return this.name||"markdown";
|
||||
return this.name||("msg." + this.property)||"markdown";
|
||||
},
|
||||
labelStyle: function() {
|
||||
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>
|
||||
|
||||
@@ -3,14 +3,21 @@ module.exports = function(RED) {
|
||||
"use strict";
|
||||
var markdownNode = function(n) {
|
||||
var md = require('markdown-it')({html:true, linkify:true, typographer:true});
|
||||
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
this.property = n.property || "payload";
|
||||
var node = this;
|
||||
//<div id="nr-markdown" style="font-family:helvetica neue,arial,helvetica,sans-serif; margin:12px">';
|
||||
|
||||
node.on("input", function(msg) {
|
||||
if (msg.payload !== undefined && typeof msg.payload === "string") {
|
||||
msg.payload = md.render(msg.payload);
|
||||
}
|
||||
var value = RED.util.getMessageProperty(msg, node.property);
|
||||
|
||||
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");
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("markdown",markdownNode);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.",
|
||||
"dependencies": {
|
||||
"markdown-it": "^14.1.0"
|
||||
|
||||
Reference in New Issue
Block a user