4

Lately I've noticed the syntax highlighting for questions is not applying when the code fence hint

```ts

or

```lang-ts

is used.

Example question - How to have TypeScript show computed/simplified type

Dark Mode Light Mode
dark mode screenshot light mode screenshot

The question (at the time of posting) is tagged correctly and also uses code fences

```ts
export type UnionExpanded<$Union> = $Union

export type HandleReturn2<$Data> = UnionExpanded<$Data | 2>
```

Using lang-ts also fails but updating even one code fence to use lang-typescript seems to fix all code blocks.

Removing the hint and letting the tag take priority also works.


This always used to work and is also listed in What is syntax highlighting and how does it work?

  • TypeScript: lang-typescript, (lang-ts, lang-tsx, lang-mts, lang-cts)
8
  • 3
    meta.stackexchange.com/questions/403526/… Commented Oct 14, 2024 at 1:07
  • Are ts and lang-ts even recognized? The name of the tag is typescript, and the tag wiki indicates that the syntax highlighting language is lang-js, not lang-ts. Commented Oct 14, 2024 at 1:55
  • @Anerdw they always used to work Commented Oct 14, 2024 at 2:20
  • Upon further inspection, it does look like lang-ts is officially supported. ts isn't a synonym for typescript, though - why did that one used to work? Commented Oct 14, 2024 at 2:23
  • 1
    I'm not going to mark this [status-review] since the post on MSE that Kevin B linked is already in that state. As outlined in that post there are two issues, (1) it appears the staff changes to highlighting logic did not update the front-end preview window at all to use the new logic and (2) that the backend logic doesn't account for any of the supported HLJS aliases. Commented Oct 14, 2024 at 2:56
  • 3
    For the moment either typescript to pull in the JavaScript highlighting or lang-typescript will (should) function as expected. Somewhat relatedly, with the new behaviour, it might also be time to take a second look at Change Default Syntax Highlighting for [typescript] from lang-js to lang-typescript Commented Oct 14, 2024 at 3:00
  • 1
    @Anerdw "why did that one used to work?" - well I presume because "ts" is a known alias that highlight.js supports - highlightjs.readthedocs.io/en/latest/supported-languages.html. Commented Oct 15, 2024 at 12:27
  • 1
    I just encountered this because lang-ts DOES correctly highlight while writing a post (it took about 3 sec for the syntax to be highlighted in the preview), but then upon posting the syntax is no longer highlighted. Commented Feb 14 at 9:29

1 Answer 1

4

This was fixed in Syntax highlighting when using a lang-* alias (and some "main" language codes) is broken

Thanks for reporting!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.