Add render markdown operation

This commit is contained in:
j433866 2019-07-12 09:33:13 +01:00
parent 897dc0fb97
commit 7f168d49a6
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,59 @@
/**
* @author j433866 [j433866@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation";
import MarkdownIt from "markdown-it";
/**
* Render Markdown operation
*/
class RenderMarkdown extends Operation {
/**
* RenderMarkdown constructor
*/
constructor() {
super();
this.name = "Render Markdown";
this.module = "Default";
this.description = "Renders Markdown as HTML.";
this.infoURL = "https://wikipedia.org/wiki/Markdown";
this.inputType = "string";
this.outputType = "html";
this.args = [
{
name: "Autoconvert URLs to links",
type: "boolean",
value: false
},
{
name: "Convert \\n to <br>",
type: "boolean",
value: false
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {html}
*/
run(input, args) {
const [convertLinks, convertNewLine] = args,
md = new MarkdownIt({
breaks: convertNewLine,
linkify: convertLinks
}),
rendered = md.render(input);
return `<div style="font-family: var(--primary-font-family)">${rendered}</div>`;
}
}
export default RenderMarkdown;