1 | const visit = require('unist-util-visit');
|
2 | const hljs = require('highlight.js');
|
3 |
|
4 | /**
|
5 | * Adapted from remark-highlight.js
|
6 | * https://github.com/ben-eb/remark-highlight.js
|
7 | * @param {Object} node AST node
|
8 | * @returns {undefined} modifies the node by reference
|
9 | * @private
|
10 | */
|
11 | function visitor(node) {
|
12 | if (node.lang) {
|
13 | node.type = 'html';
|
14 | node.value =
|
15 | "<pre class='hljs'>" +
|
16 | hljs.highlightAuto(node.value, [node.lang]).value +
|
17 | '</pre>';
|
18 | }
|
19 | }
|
20 |
|
21 | module.exports = function(ast) {
|
22 | visit(ast, 'code', visitor);
|
23 | return ast;
|
24 | };
|