-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add cjs and mjs aliases for code block syntax highlighting (#487)
- Loading branch information
1 parent
b5ae7eb
commit c53cf78
Showing
1 changed file
with
24 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import siteConfig from '@generated/docusaurus.config'; | ||
|
||
export default function prismIncludeLanguages(PrismObject) { | ||
const { | ||
themeConfig: { prism }, | ||
} = siteConfig; | ||
const { additionalLanguages } = prism; | ||
// Prism components work on the Prism instance on the window, while prism- | ||
// react-renderer uses its own Prism instance. We temporarily mount the | ||
// instance onto window, import components to enhance it, then remove it to | ||
// avoid polluting global namespace. | ||
// You can mutate PrismObject: registering plugins, deleting languages... As | ||
// long as you don't re-assign it | ||
globalThis.Prism = PrismObject; | ||
additionalLanguages.forEach((lang) => { | ||
require(`prismjs/components/prism-${lang}`); | ||
}); | ||
|
||
// Add JavaScript aliases | ||
PrismObject.languages.mjs = PrismObject.languages.cjs = | ||
PrismObject.languages.javascript; | ||
|
||
delete globalThis.Prism; | ||
} |