Skip to content

Fenced code blocks with js language tag not syntax highlighted #446

@JohanRonstrom

Description

@JohanRonstrom

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
var x = 1;
```

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. tstypescript, pypython, rbruby, shbash).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions