Skip to content

Commit

Permalink
Fix: Aliases weren’t resolving correctly for diff languages
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 20, 2022
1 parent c063340 commit 6bc55ad
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/PrismLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@ PrismLoader.silent = true;
const PrismAlias = require("./PrismNormalizeAlias");

module.exports = function(language) {
if(language.startsWith("diff-") && !Prism.languages.diff) {
PrismLoader("diff");
// Bundled Plugin
require("prismjs/plugins/diff-highlight/prism-diff-highlight");

return Prism.languages.diff;
let diffRemovedRawName = language;
if(language.startsWith("diff-")) {
diffRemovedRawName = language.substr("diff-".length);
}
let diffRemovedNormalizedName = PrismAlias(diffRemovedRawName);

let normalizedLanguage = PrismAlias(language);
if(!Prism.languages[ normalizedLanguage ]) {
PrismLoader(normalizedLanguage);
if(!Prism.languages[ diffRemovedNormalizedName ]) {
PrismLoader(diffRemovedNormalizedName);
}
if(!Prism.languages[normalizedLanguage]) {
if(!Prism.languages[ diffRemovedNormalizedName ]) {
throw new Error(`"${language}" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight`);
}
return Prism.languages[ normalizedLanguage ];
if(!language.startsWith("diff-")) {
return Prism.languages[ diffRemovedNormalizedName ];
}

let fullLanguageName = `diff-${diffRemovedNormalizedName}`;

if(!Prism.languages.diff) {
PrismLoader("diff");
// Bundled Plugin
require("prismjs/plugins/diff-highlight/prism-diff-highlight");
}

// Store into with aliased keys
// ts -> diff-typescript
// js -> diff-javascript
Prism.languages[ fullLanguageName ] = Prism.languages.diff;

return Prism.languages[ fullLanguageName ];
};

0 comments on commit 6bc55ad

Please sign in to comment.