mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 19:03:38 +02:00
* Prettify all JavaScript files * Make trailingComma all * Delete v2/.prettierignore * Remove v2 Prettier commands in package.json
22 lines
556 B
JavaScript
22 lines
556 B
JavaScript
const hljs = require('highlight.js');
|
|
const chalk = require('chalk');
|
|
const escapeHtml = require('escape-html');
|
|
|
|
export default (str, rawLang) => {
|
|
if (rawLang === 'text' || !rawLang) {
|
|
return escapeHtml(str);
|
|
}
|
|
const lang = rawLang.toLowerCase();
|
|
try {
|
|
if (hljs.getLanguage(lang)) {
|
|
return hljs.highlight(lang, str).value;
|
|
}
|
|
} catch (e) {
|
|
console.error(
|
|
chalk.yellow(
|
|
`Highlight.js syntax highlighting for language "${lang}" is not supported.`,
|
|
),
|
|
);
|
|
}
|
|
return hljs.highlightAuto(str).value;
|
|
};
|