feat(v2): add support specify new languages for Prism (#2250)

* feat(v2): add support specify new languages for Prism

* Do It Right

* More fix

* Fix up!

* Fixes

* Move to dev dependencies

Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2020-03-08 17:13:02 +03:00 committed by GitHub
parent 70ba0a4bc7
commit 5226767caf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 7 deletions

View file

@ -225,15 +225,22 @@ module.exports = {
By default, Docusaurus comes with this subset of [commonly used languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js).
To add syntax highlighting for any of the other [Prism supported languages](https://prismjs.com/#supported-languages), install the `prismjs` npm package, then swizzle the `CodeBlock` component and add the desired language(s) there.
To add syntax highlighting for any of the other [Prism supported languages](https://prismjs.com/#supported-languages),
define it in an array of additional languages.
For example, if you want to add highlighting for the `powershell` language:
```js
// src/theme/CodeBlock/index.js
import Prism from 'prism-react-renderer/prism';
(typeof global !== 'undefined' ? global : window).Prism = Prism;
require('prismjs/components/prism-powershell');
// docusaurus/config.js
module.exports = {
...
themeConfig: {
prism: {
additionalLanguages: ['powershell'],
},
...
},
};
```
### Line highlighting