From f1f25f4764dd8d297a59765b0df85f55da2b39ee Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Mon, 19 Jul 2021 21:08:50 -0500 Subject: Init --- plugins/withMarkdownLoader.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 plugins/withMarkdownLoader.js (limited to 'plugins/withMarkdownLoader.js') diff --git a/plugins/withMarkdownLoader.js b/plugins/withMarkdownLoader.js new file mode 100644 index 0000000..7dd51b6 --- /dev/null +++ b/plugins/withMarkdownLoader.js @@ -0,0 +1,31 @@ +const hljs = require('highlight.js'); +const pluginFactory = require('./pluginFactory'); + +function highlight(code, lang) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + + const highlighted = hljs.highlight(code, { language }).value; + return highlighted; +} + +const withMarkdownLoader = pluginFactory((config, _options) => { + config.module.rules.push({ + test: /\.md$/, + use: [ + { + loader: 'html-loader', + options: { + esModule: true + } + }, + { + loader: 'markdown-loader', + options: { + highlight + } + } + ] + }); +}); + +module.exports = withMarkdownLoader; \ No newline at end of file -- cgit v1.2.3