1
0
mirror of synced 2025-02-20 20:21:24 +01:00

Merge branch 'render-markdown' of https://github.com/j433866/CyberChef into j433866-render-markdown

This commit is contained in:
n1474335 2019-08-30 15:33:47 +01:00
commit e129425d8d
2 changed files with 70 additions and 0 deletions

View File

@ -126,6 +126,7 @@
"lodash": "^4.17.15",
"loglevel": "^1.6.3",
"loglevel-message-prefix": "^3.0.0",
"markdown-it": "^9.0.0",
"moment": "^2.24.0",
"moment-timezone": "^0.5.25",
"ngeohash": "^0.6.3",

View File

@ -0,0 +1,69 @@
/**
* @author j433866 [j433866@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import MarkdownIt from "markdown-it";
import hljs from "highlight.js";
/**
* Render Markdown operation
*/
class RenderMarkdown extends Operation {
/**
* RenderMarkdown constructor
*/
constructor() {
super();
this.name = "Render Markdown";
this.module = "Default";
this.description = "Renders input 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: "Enable syntax highlighting",
type: "boolean",
value: true
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {html}
*/
run(input, args) {
const [convertLinks, enableHighlighting] = args,
md = new MarkdownIt({
linkify: convertLinks,
html: false, // Explicitly disable HTML rendering
highlight: function(str, lang) {
if (lang && hljs.getLanguage(lang) && enableHighlighting) {
try {
return hljs.highlight(lang, str).value;
} catch (__) {}
}
return "";
}
}),
rendered = md.render(input);
return `<div style="font-family: var(--primary-font-family)">${rendered}</div>`;
}
}
export default RenderMarkdown;