summary refs log tree commit diff stats
path: root/src/modules
diff options
context:
space:
mode:
authorAlan Pearce2017-07-03 21:39:43 +0200
committerAlan Pearce2017-07-03 21:55:41 +0200
commite7b08b1dfe3f2a2596deb6e2a72bb79805d3708f (patch)
tree027fda29fe96736d4ac641a1dfe0bfe657d3fd33 /src/modules
parenta67e38d1a82c95db5bd24183e81b31438f60dd2c (diff)
downloadhomestead-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.js24
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);