-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Programmatically check if a language is supported by Prism (including aliases) #2522
Comments
Object.keys(Prism.languages).filter(id => typeof Prism.languages[id] === "object") If you want all available languages, you will need to use That being said, what exactly do need Prism to be able to do?
I don't understand what you mean by that. E.g. Javascript will be in
How do you do that? We have a similar problem in #2000, so I'm interested in your approach. |
I see what you mean - the problem here is that So I guess the question is not "which languages are supported and currently loaded into Prism?" (for which
Here's a codesandbox showing what I mean: https://codesandbox.io/s/practical-cray-bruxb?file=/src/index.js Hope this clears the usecase up a bit! |
In that case, you definitely have to use We are planning to open up parts of them (#2146) eventually but I'm still thinking about the best way to do that.
Ahh, so you didn't resolve the aliases, you just wanted to know all available ones. |
It's fine - I was just concerned that I had missed some method that already existed.
Great!
Exactly. Our use case is actually around importing content - we need to validate that imported code blocks have a language supported by Prism, otherwise we strip the language. So we need to know the available languages (we don't care if they're aliases or not), but not load them/resolve them. Thanks for the help, as you're already working on this as part of #2146 I don't think it makes sense to figure out a way of putting what I've done into the Prism codebase, we'll wait for an upcoming release. Feel free to ping me if you need help on the matter. |
I want to be able to programmatically check if a language is supported by Prism. I could do this:
but this doesn't support aliases.
I've currently implemented this myself by iterating over
Prism.languages
and building a lookup map with support for alias, but I think this could be a useful part of Prism itself.The text was updated successfully, but these errors were encountered: