Skip to content

Commit

Permalink
Add syntax highlighting
Browse files Browse the repository at this point in the history
Explicitly disable HTML rendering.
Updated description.
  • Loading branch information
j433866 committed Aug 29, 2019
1 parent 45fccb9 commit b94eb6a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/core/operations/RenderMarkdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* @license Apache-2.0
*/

import Operation from "../Operation";
import Operation from "../Operation.mjs";
import MarkdownIt from "markdown-it";
import hljs from "highlight.js";

/**
* Render Markdown operation
Expand All @@ -20,7 +21,7 @@ class RenderMarkdown extends Operation {

this.name = "Render Markdown";
this.module = "Default";
this.description = "Renders Markdown as HTML.";
this.description = "Renders input Markdown as HTML.";
this.infoURL = "https://wikipedia.org/wiki/Markdown";
this.inputType = "string";
this.outputType = "html";
Expand All @@ -31,9 +32,9 @@ class RenderMarkdown extends Operation {
value: false
},
{
name: "Convert \\n to <br>",
name: "Enable syntax highlighting",
type: "boolean",
value: false
value: true
}
];
}
Expand All @@ -44,10 +45,19 @@ class RenderMarkdown extends Operation {
* @returns {html}
*/
run(input, args) {
const [convertLinks, convertNewLine] = args,
const [convertLinks, enableHighlighting] = args,
md = new MarkdownIt({
breaks: convertNewLine,
linkify: convertLinks
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);

Expand Down

0 comments on commit b94eb6a

Please sign in to comment.