mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
add tests for markdown node
This commit is contained in:
parent
fef734486f
commit
84abd4bcb6
@ -40,6 +40,7 @@
|
|||||||
"grunt-simple-mocha": "^0.4.1",
|
"grunt-simple-mocha": "^0.4.1",
|
||||||
"imap": "^0.8.19",
|
"imap": "^0.8.19",
|
||||||
"mailparser-mit": "^1.0.0",
|
"mailparser-mit": "^1.0.0",
|
||||||
|
"markdown-it": "^8.4.2",
|
||||||
"mocha": "^6.1.4",
|
"mocha": "^6.1.4",
|
||||||
"msgpack-lite": "^0.1.26",
|
"msgpack-lite": "^0.1.26",
|
||||||
"multilang-sentiment": "^1.2.0",
|
"multilang-sentiment": "^1.2.0",
|
||||||
|
@ -8,8 +8,12 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-help-name="markdown">
|
<script type="text/x-red" data-help-name="markdown">
|
||||||
<p>A function that converts the <code>msg.payload</code> in markdown format to html.</p>
|
<p>A function that converts the <code>msg.payload</code> in markdown format to html.</p>
|
||||||
<p>If the input is a string it tries to convert it to html.</p>
|
<p>If the input is a string it converts it to html.</p>
|
||||||
<p>All other message types are ignored.</p>
|
<p>All other message types are ignored.</p>
|
||||||
|
<p>Uses the markdown-it library - You can see a demo
|
||||||
|
<a href="https://markdown-it.github.io/">here</a>.</p>
|
||||||
|
<p>It is configured with html, linkify and typographer options turned on.</p>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
module.exports = function(RED) {
|
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});
|
var md = require('markdown-it')({html:true, linkify:true, typographer:true});
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
var node = this;
|
var node = this;
|
||||||
//<div id="nr-markdown" style="font-family:helvetica neue,arial,helvetica,sans-serif; margin:12px">';
|
//<div id="nr-markdown" style="font-family:helvetica neue,arial,helvetica,sans-serif; margin:12px">';
|
||||||
|
@ -6,7 +6,7 @@ A <a href="http://nodered.org" target="_new">Node-RED</a> node to convert a mark
|
|||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Run the following command in your Node-RED user directory - typically `~/.node-red`
|
Either use the `Node-RED Menu - Manage Palette - Install`, or run the following command in your Node-RED user directory - typically `~/.node-red`
|
||||||
|
|
||||||
npm install node-red-node-markdown
|
npm install node-red-node-markdown
|
||||||
|
|
||||||
@ -14,3 +14,7 @@ Usage
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
If the input is a string it tries to convert it into an html string.
|
If the input is a string it tries to convert it into an html string.
|
||||||
|
|
||||||
|
Uses the markdown-it library - You can see a demo <a href="https://markdown-it.github.io/" target="_new">here</a>.
|
||||||
|
|
||||||
|
It is configured with html, linkify and typographer options turned on.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-markdown",
|
"name" : "node-red-node-markdown",
|
||||||
"version" : "0.0.1",
|
"version" : "0.1.0",
|
||||||
"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": "^8.4.2"
|
"markdown-it": "^8.4.2"
|
||||||
|
109
test/parsers/markdown/70-markdown_spec.js
Normal file
109
test/parsers/markdown/70-markdown_spec.js
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
|
||||||
|
var should = require("should");
|
||||||
|
var helper = require("node-red-node-test-helper");
|
||||||
|
var testNode = require('../../../parsers/markdown/70-markdown.js');
|
||||||
|
|
||||||
|
describe('markdown node', function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
beforeEach(function(done) {
|
||||||
|
helper.startServer(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function(done) {
|
||||||
|
helper.unload().then(function() {
|
||||||
|
helper.stopServer(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be loaded with correct defaults", function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"markdown", "name":"markdown1", "wires":[[]]}];
|
||||||
|
helper.load(testNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
n1.should.have.property("name", "markdown1");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var buf;
|
||||||
|
|
||||||
|
it('should convert a string to html', function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"markdown", wires:[["n2"]] },
|
||||||
|
{id:"n2", type:"helper"} ];
|
||||||
|
helper.load(testNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
msg.should.have.a.property("payload");
|
||||||
|
msg.payload.should.be.a.String;
|
||||||
|
msg.payload.should.equal('<p><strong>BOLD</strong> <em>italic</em></p>\n<hr>\n<p>™\n<code>code</code></p>\n');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
n1.emit("input", {payload:"**BOLD** *italic*\n***\n\n(TM)\n`code`"});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore other types - object', function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"markdown", wires:[["n2"]] },
|
||||||
|
{id:"n2", type:"helper"} ];
|
||||||
|
helper.load(testNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
msg.should.have.a.property("payload");
|
||||||
|
msg.payload.should.be.a.Object;
|
||||||
|
msg.payload.a.should.equal("object");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
n1.emit("input", {payload:{a:"object"}});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore other types - number', function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"markdown", wires:[["n2"]] },
|
||||||
|
{id:"n2", type:"helper"} ];
|
||||||
|
helper.load(testNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
msg.should.have.a.property("payload");
|
||||||
|
msg.payload.should.be.a.number;
|
||||||
|
msg.payload.should.equal(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
n1.emit("input", {payload:1});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore other types - boolean', function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"markdown", wires:[["n2"]] },
|
||||||
|
{id:"n2", type:"helper"} ];
|
||||||
|
helper.load(testNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
msg.should.have.a.property("payload");
|
||||||
|
msg.payload.should.be.a.boolean;
|
||||||
|
msg.payload.should.equal(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
n1.emit("input", {payload:true});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore other types - array', function(done) {
|
||||||
|
var flow = [{"id":"n1", "type":"markdown", wires:[["n2"]] },
|
||||||
|
{id:"n2", type:"helper"} ];
|
||||||
|
helper.load(testNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
msg.should.have.a.property("payload");
|
||||||
|
msg.payload.should.be.an.object;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
n1.emit("input", {payload:[1,2,"a","b"]});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user