aboutsummaryrefslogtreecommitdiff
path: root/plugins/withMarkdownLoader.js
blob: 7dd51b65b67abba3aebc824916626b8ae377c208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;