1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Add support of language aliases in highlight.js plugin (#3898)

listLanguages() returns a list of supported languages. It does not
return language aliases.

highlight.js has extensive support of language aliases which can be 
viewed here

https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html#language-names-and-aliases

But because of using listLanguages(), TW does not take advantage of 
alias.

getLanguage() method on the other hand supports aliases.

https://highlightjs.readthedocs.io/en/latest/api.html#getlanguage-name

To summarize, now user can use javascript, js or jsx for the code block. getLanguage() will return an object which means highlight.js supports
this language.
This commit is contained in:
Talha Mansoor 2019-04-15 22:45:46 +05:00 committed by Jeremy Ruston
parent 0513837228
commit 04a4a0f92e

View File

@ -27,7 +27,7 @@ CodeBlockWidget.prototype.postRender = function() {
if(tiddler) {
language = tiddler.fields.text || "";
}
if(language && hljs.listLanguages().indexOf(language) !== -1) {
if(language && hljs.getLanguage(language)) {
domNode.className = language.toLowerCase() + " hljs";
if($tw.browser && !domNode.isTiddlyWikiFakeDom) {
hljs.highlightBlock(domNode);