mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
|
/**
|
||
|
* @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;
|