Skip to content

Commit

Permalink
chore: add cjs and mjs aliases for code block syntax highlighting (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored Dec 19, 2023
1 parent b5ae7eb commit c53cf78
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/theme/prism-include-languages.js
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;
}

0 comments on commit c53cf78

Please sign in to comment.