all repos — archive/homestead @ e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f

My future indieweb platform

feat: Add code block highlighting Theme is configurable

Alan Pearce
commit

e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f

parent

a67e38d1a82c95db5bd24183e81b31438f60dd2c

1 file changed, 18 insertions(+), 6 deletions(-)

changed files
M src/modules/markdown.jssrc/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);