mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-03 00:39:45 +02:00
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:
parent
70ba0a4bc7
commit
5226767caf
4 changed files with 60 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue