diff options
author | Alan Pearce | 2017-07-03 21:39:43 +0200 |
---|---|---|
committer | Alan Pearce | 2017-07-03 21:55:41 +0200 |
commit | e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f (patch) | |
tree | 027fda29fe96736d4ac641a1dfe0bfe657d3fd33 /src/modules | |
parent | a67e38d1a82c95db5bd24183e81b31438f60dd2c (diff) | |
download | homestead-e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f.tar.lz homestead-e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f.tar.zst homestead-e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f.zip |
feat: Add code block highlighting
Theme is configurable
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); |