Highlight.js lets you use aliases for languages. It's list of aliases is 
[available 
here](https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html#language-names-and-aliases).


According to it, both of the following code blocks are similar

```
```javascript
```

```
```js
```

But in TW, `js` does not work for javascript, or any alias for other 
languages.

I looked into the [source code of highlight.js plugin in 
TW](https://github.com/Jermolene/TiddlyWiki5/blob/master/plugins/tiddlywiki/highlight/files/highlight.pack.js).

After prettifying it, it was clear that aliases for each language were 
defined in the highlight.js source code.

Then I looked up the code of 
[highlightblock.js](https://github.com/Jermolene/TiddlyWiki5/blob/master/plugins/tiddlywiki/highlight/highlightblock.js).

What I understand, this line of code is used to see if language is 
supported by the plugin or not

```js
if(language && hljs.listLanguages().indexOf(language) !== -1) {
```

`listLanguages()` method does not support aliases. It only returns a list 
of full name of supported languages.

Its API has another method 
[getLanguage()](https://highlightjs.readthedocs.io/en/latest/api.html#getlanguage-name)
 
that supports aliases. So

```
hljs.getLanguage('javascript') // Object
hljs.getLanguage('js') // Object
hljs.getLanguage('blahblah') // undefined
```

So changing the offending line with 

```js
if(language && hljs.getLanguage(language)) {
```

fixed the issue in my tests. I have submitted a PR with this patch

https://github.com/Jermolene/TiddlyWiki5/pull/3898/files

I am writing it in detail in here so that if my understanding is incorrect 
then someone would correct me and suggest a proper solution.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/d5c412e8-30c9-4513-a460-c31852afc4b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to