-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Ignore code blocks with unsupported languages #842
Comments
You can use no-highlight class for that. |
That's a good workaround, but it means knowing in advance which languages are supported for highlighting, which can change over time as they get added. |
The alternative way to turn off autodetection is with hljs.configure({ languages: [] });
hljs.initHighlighting(); That way if the language isn't there, highlight.js doesn't try to guess the language itself. |
This is pretty much resolved so I'm closing this issue. |
Turning off autodetection would turn off autodetection completely, though - the aim of this issue is to keep autodetection enabled, but not to try to guess a different language when one is already specified. |
One problem here is that it'd be hard to solve in a good way. We could tell that a class name is a language name only if it's prefixed by "language-". However people mostly just use unprefixed names like "php", "cpp", which highlight.js can't distinguish from any other class names having nothing to do with languages. I'd say rather then put a usecase-specific code into core it's better to use custom initialization on the client side. |
If the class name is prefixed with |
Yes, I understand that. My point is that the prefix isn't used often enough to warrant a non-obvious special case condition in the core library. I may be very well wrong about it (I'm rather away from that part of code right now) so if it is easy to implement in a readable way I see no problem in fixing it. Could you try and make the fix? It should probably be somewhere around |
I've had a go at treating It's a bit less efficient, so up to you whether it makes sense to include - I'll make a pull request if it's useful. |
Okay, I've taken this change but while testing realized that it still would highlight blocks with classes like "c language-plain", so I've changed all that logic in dde27ca. |
Brilliant, thanks @isagalaev 👍 |
If a language is specified using a classname on a code block, but that language is unsupported by highlight.js (e.g.
language-yaml
), ignore this code block rather than trying to highlight it wrongly as a different language.The text was updated successfully, but these errors were encountered: