forked from webpack/webpack.js.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight.js
32 lines (23 loc) · 812 Bytes
/
highlight.js
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
32
'use strict';
if(typeof document !== "undefined") {
// disable automatic highlight on content loaded
var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
script.setAttribute("data-manual", "");
}
var Prism = require('prismjs');
var languages = require('prism-languages');
var highlight = Prism.highlight;
module.exports = function(code, language) {
language = language || 'bash';
if (language === 'sh' || language === 'text' || language === 'shell') {
language = 'bash';
}
try {
return highlight(code, languages[language]);
} catch (error) {
if (!languages[language]) {
console.warn('Prism does not support this language: ', language);
} else console.warn('Prism failed to highlight: ', error);
}
return code;
};