mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
Add the ability to define a default language (#206)
* Add the ability to define a default language I don't want to have to add the language i'm working on to every single block nor do I want to rely on a default heuristic to find the language. This adds the ability to write ``` highlight: { defaultLang: 'xxxx' } ``` in `siteConfig.js` to force the language when not specified. I tested it without a a highlight block, without a defaultLang attribute and with one and with a wrong one. All of them work as expected. * Move comment around
This commit is contained in:
parent
ab169640d4
commit
e9c5cef664
1 changed files with 6 additions and 4 deletions
|
@ -42,21 +42,24 @@ class Remarkable extends React.Component {
|
|||
|
||||
renderMarkdown(source) {
|
||||
if (!this.md) {
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
|
||||
this.md = new Markdown({
|
||||
// Highlight.js expects hljs css classes on the code element.
|
||||
// This results in <pre><code class="hljs css javascript">
|
||||
langPrefix: 'hljs css ',
|
||||
highlight: function (str, lang) {
|
||||
lang = lang || (siteConfig.highlight && siteConfig.highlight.defaultLang);
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(lang, str).value;
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
return hljs.highlightAuto(str).value;
|
||||
} catch (err) {}
|
||||
|
||||
|
||||
return '';
|
||||
}
|
||||
});
|
||||
|
@ -65,7 +68,6 @@ class Remarkable extends React.Component {
|
|||
this.md.use(anchors);
|
||||
|
||||
// Allow client sites to register their own plugins
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
if (siteConfig.markdownPlugins) {
|
||||
siteConfig.markdownPlugins.forEach(function(plugin) {
|
||||
this.md.use(plugin);
|
||||
|
@ -96,4 +98,4 @@ Remarkable.defaultProps = {
|
|||
options: {},
|
||||
};
|
||||
|
||||
module.exports = Remarkable;
|
||||
module.exports = Remarkable;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue