A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/PrismJS/prism/issues/2000 below:

Prism should resolve aliases for hooks · Issue #2000 · PrismJS/prism · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4