Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prism should resolve aliases for hooks #2000

Open
RunDevelopment opened this issue Jul 24, 2019 · 0 comments
Open

Prism should resolve aliases for hooks #2000

RunDevelopment opened this issue Jul 24, 2019 · 0 comments

Comments

@RunDevelopment
Copy link
Member

RunDevelopment commented Jul 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant