diff --git a/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts b/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts index a91d36bc3260..2b8fdce6aa02 100644 --- a/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts +++ b/packages/docusaurus-theme-classic/src/theme/prism-include-languages.ts @@ -23,6 +23,8 @@ export default function prismIncludeLanguages( // avoid polluting global namespace. // You can mutate PrismObject: registering plugins, deleting languages... As // long as you don't re-assign it + + const PrismBefore = globalThis.Prism; globalThis.Prism = PrismObject; additionalLanguages.forEach((lang) => { @@ -34,5 +36,9 @@ export default function prismIncludeLanguages( require(`prismjs/components/prism-${lang}`); }); + // Clean up and eventually restore former globalThis.Prism object (if any) delete (globalThis as Optional).Prism; + if (typeof PrismBefore !== 'undefined') { + globalThis.Prism = PrismObject; + } }