Prism should resolve aliases for hooks
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13k
- Forks
- 1.4k
- Avg merge
- 15h 36m
- Merged PRs (30d)
- 3
Description
Motivation
When adding language-specific hooks the first line of the callback function is usually the language check. The problem here is that every language-specific hook has to know all the aliases of the target language.
For languages like Markup, this is quite a number of even for languages with just one alias this can cause problems.
Description
To solve this, we could add a function like this:
Prism.languages.addAlias = function (id, ...aliases) {
for (const alias of aliases) {
aliasMap[alias] = id;
Prism.languages[alias] = Prism.languages[id];
}
}
aliasMap is just a private variable which does what the name suggests. We would then use the map here and here to resolve the aliases for our hooks.
The class name of highlighted elements remains unchanged. (Or should we resolve this as well?)
Alternative
We could also use the order of the entries in Prism.languages. Aliases are always added after the language definition. This means that we can resolve aliases by looking for the first key in Prism.languages with the same value.
A bit hacky but we wouldn't have to change any of the existing language definitions.
Edit: Added alternative
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading components/prism-core.js at the two linked hook locations and the proposed Prism.languages.addAlias API. Trace how language aliases are currently represented, then resolve the open question of whether highlighted class names remain unchanged. Done means language-specific hooks consistently resolve aliases, with the chosen behavior documented and validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100