Skip to content

Commit

Permalink
Restore former globalThis.Prism
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 25, 2024
1 parent d723a1e commit 047ce0e
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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<typeof globalThis, 'Prism'>).Prism;
if (typeof PrismBefore !== 'undefined') {
globalThis.Prism = PrismObject;
}
}

0 comments on commit 047ce0e

Please sign in to comment.