TypeError: grammar is undefined #3310
-
Why i got this error?i trying to dynamically hiligth code in prism with this code : Prism.highlight(paste.code, Prism.languages[paste.language], paste.language)
// paste.language = name of language i want to highlight it only worked for html,css,js and python(as far as i know),but when try to hilight for example rust code i got error,i already try import all error languages but still not working except when i use it individually e.g : Prism.highlight(paste.code, Prism.languages.rust, paste.language) so how to solve |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
A stack trace would have been nice. My guess is that the error occurs here. This means that the languages isn't loaded. It seems that you also changed something else when you changed While the incorrect language loading probably isn't Prism's fault, the very non-descriptive error message is. I'll add a better error. (see #3311) Btw, the reason why HTML, CSS, and JS will always work is that those 3 languages (plus one util language) are always loaded by default. Prism was originally a very web-languages-focused highlighter. |
Beta Was this translation helpful? Give feedback.
A stack trace would have been nice. My guess is that the error occurs here. This means that the languages isn't loaded.
It seems that you also changed something else when you changed
Prism.languages[paste.language]
->Prism.languages.rust
. Whatever that something was, it loaded all languages (or at least Rust) correctly.While the incorrect language loading probably isn't Prism's fault, the very non-descriptive error message is. I'll add a better error. (see #3311)
Btw, the reason why HTML, CSS, and JS will always work is that those 3 languages (plus one util language) are always loaded by default. Prism was originally a very web-languages-focused highlighter.