mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 15:56:16 -04:00
Add render markdown operation
This commit is contained in:
parent
897dc0fb97
commit
7f168d49a6
2 changed files with 60 additions and 0 deletions
59
src/core/operations/RenderMarkdown.mjs
Normal file
59
src/core/operations/RenderMarkdown.mjs
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue