-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,25 +63,63 @@ Make sure to use `remark-math >= 5` and `rehype-katex >= 6` for Docusaurus v3 (u | |
|
||
::: | ||
|
||
Those 2 plugins are now only available as ESM packages, and you will need to import them dynamically. | ||
Those 2 plugins are now [**only available as ES Modules**](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). To simplify usage, it is recommended to use an [**ES Modules**](https://flaviocopes.com/es-modules/) config file: | ||
|
||
First, turn your site config into an async config creator function: | ||
```js title="ES module docusaurus.config.js" | ||
// highlight-start | ||
import remarkMath from 'remark-math'; | ||
import rehypeKatex from 'rehype-katex'; | ||
// highlight-end | ||
|
||
```js title="docusaurus.config.js" | ||
export default async function createConfigAsync() { | ||
return { | ||
// your site config... | ||
}; | ||
} | ||
// highlight-start | ||
export default { | ||
presets: [ | ||
[ | ||
'@docusaurus/preset-classic', | ||
{ | ||
docs: { | ||
path: 'docs', | ||
// highlight-start | ||
remarkPlugins: [remarkMath], | ||
rehypePlugins: [rehypeKatex], | ||
// highlight-end | ||
}, | ||
}, | ||
], | ||
], | ||
}; | ||
``` | ||
|
||
It is now possible to import the plugins dynamically and add them to your content plugin or preset options (usually `@docusaurus/preset-classic` docs options): | ||
<details> | ||
<summary>Using a [**CommonJS**](https://nodejs.org/api/modules.html#modules-commonjs-modules) config file?</summary> | ||
|
||
```js | ||
remarkPlugins: [(await import('remark-math')).default], | ||
rehypePlugins: [(await import('rehype-katex')).default], | ||
If you decide to use a CommonJS config file, it is possible to load those ES module plugins thanks to dynamic imports and an async config creator function: | ||
|
||
```js title="CommonJS module docusaurus.config.js" | ||
// highlight-start | ||
module.exports = async function createConfigAsync() { | ||
// highlight-end | ||
return { | ||
presets: [ | ||
[ | ||
'@docusaurus/preset-classic', | ||
{ | ||
docs: { | ||
path: 'docs', | ||
// highlight-start | ||
remarkPlugins: [(await import('remark-math')).default], | ||
rehypePlugins: [(await import('rehype-katex')).default], | ||
// highlight-end | ||
}, | ||
}, | ||
], | ||
], | ||
}; | ||
}; | ||
``` | ||
|
||
</details> | ||
|
||
Include the KaTeX CSS in your config under `stylesheets`: | ||
|
||
```js | ||
|
@@ -99,37 +137,40 @@ stylesheets: [ | |
Overall the changes look like: | ||
|
||
```js title="docusaurus.config.js" | ||
export default async function createConfigAsync() { | ||
return { | ||
title: 'Docusaurus', | ||
tagline: 'Build optimized websites quickly, focus on your content', | ||
presets: [ | ||
[ | ||
'@docusaurus/preset-classic', | ||
{ | ||
docs: { | ||
path: 'docs', | ||
// highlight-start | ||
remarkPlugins: [(await import('remark-math')).default], | ||
rehypePlugins: [(await import('rehype-katex')).default], | ||
// highlight-end | ||
}, | ||
}, | ||
], | ||
], | ||
// highlight-start | ||
stylesheets: [ | ||
// highlight-start | ||
import remarkMath from 'remark-math'; | ||
import rehypeKatex from 'rehype-katex'; | ||
// highlight-end | ||
|
||
export default { | ||
title: 'Docusaurus', | ||
tagline: 'Build optimized websites quickly, focus on your content', | ||
presets: [ | ||
[ | ||
'@docusaurus/preset-classic', | ||
{ | ||
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css', | ||
type: 'text/css', | ||
integrity: | ||
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM', | ||
crossorigin: 'anonymous', | ||
docs: { | ||
path: 'docs', | ||
// highlight-start | ||
remarkPlugins: [remarkMath], | ||
rehypePlugins: [rehypeKatex], | ||
// highlight-end | ||
}, | ||
}, | ||
], | ||
// highlight-end | ||
}; | ||
} | ||
], | ||
// highlight-start | ||
stylesheets: [ | ||
{ | ||
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css', | ||
type: 'text/css', | ||
integrity: | ||
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM', | ||
crossorigin: 'anonymous', | ||
}, | ||
], | ||
// highlight-end | ||
}; | ||
``` | ||
|
||
## Self-hosting KaTeX assets {#self-hosting-katex-assets} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters