diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/markdown.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/modules/markdown.js b/src/modules/markdown.js index 9f0af45..6a0ec9d 100644 --- a/src/modules/markdown.js +++ b/src/modules/markdown.js @@ -1,12 +1,24 @@ -'use strict' +"use strict"; -const Markdown = require('markdown-it') +const highlight = require("highlight.js"); +const Markdown = require("markdown-it"); const markdownOptions = { html: true, - typographer: true -} + typographer: true, + highlight: function(str, lang) { + if (lang && highlight.getLanguage(lang)) { + try { + return ` +${highlight.highlight(lang, str).value}`; + } catch (error) { + console.error("highlighting failed", error); + } + } + return ""; + } +}; -const markdown = new Markdown(markdownOptions) +const markdown = new Markdown(markdownOptions); -module.exports = markdown.render.bind(markdown) +module.exports = markdown.render.bind(markdown); |