Code blocks using the short alias ```js are not syntax highlighted when printing, while ```javascript works correctly.
This gets highlighted:
```javascript
var x = 1;
```
This does not:
js is the most common shorthand for JavaScript in markdown (used by GitHub, VS Code preview, etc.) and is a built-in alias in highlight.js. It seems like the language tag from the markdown fence either isn't being passed through to highlight.js, or highlight.js isn't resolving its aliases, or an old version is used.
A one-line fix would be to call hljs.registerAliases('js', { languageName: 'javascript' }) if aliases aren't already loaded, or to ensure the raw fence tag is passed directly to hljs.highlight(code, { language: tag }) which resolves aliases automatically.
This also seems to affect other common short aliases too (e.g. ts → typescript, py → python, rb → ruby, sh → bash).
Code blocks using the short alias
```jsare not syntax highlighted when printing, while```javascriptworks correctly.This gets highlighted:
This does not:
jsis the most common shorthand for JavaScript in markdown (used by GitHub, VS Code preview, etc.) and is a built-in alias in highlight.js. It seems like the language tag from the markdown fence either isn't being passed through to highlight.js, or highlight.js isn't resolving its aliases, or an old version is used.A one-line fix would be to call
hljs.registerAliases('js', { languageName: 'javascript' })if aliases aren't already loaded, or to ensure the raw fence tag is passed directly tohljs.highlight(code, { language: tag })which resolves aliases automatically.This also seems to affect other common short aliases too (e.g.
ts→typescript,py→python,rb→ruby,sh→bash).