mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-29 17:07:08 +02:00
v2: prepare to move
This commit is contained in:
parent
dc7ef96849
commit
45736200b0
172 changed files with 0 additions and 0 deletions
22
v2/lib/theme/Markdown/highlight.js
Normal file
22
v2/lib/theme/Markdown/highlight.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue