react-styleguidist
Version:
React components style guide generator
20 lines (18 loc) • 349 B
JavaScript
const hljs = require('highlight.js');
/**
* Highlight code.
*
* @param {string} code
* @param {string} [lang]
* @returns {string}
*/
module.exports = function highlightCode(code, lang) {
try {
if (lang) {
return hljs.highlight(lang, code).value;
}
return hljs.highlightAuto(code).value;
} catch (err) {
return err.message;
}
};