3

I was toying around with Prism.js and for some reason, highlighting typescript code is not working as intended. Prism.js couldn't event tokenize the snippet...

Here is a demo within codesandbox

Any help/idea is appreciated.

kelsny
  • 23,009
  • 3
  • 19
  • 48
Riadh Adrani
  • 486
  • 2
  • 5
  • 16

1 Answers1

4

When imported as a module, Prism by default does not include all languages (otherwise the bundle would be very large). Prism only includes the common/popular/most used languages like HTML, CSS, JavaScript, and even Markdown.

To add TypeScript, you have to import the component like this:

import Prism from "prismjs";
import "prismjs/themes/prism-twilight.css";
import "prismjs/components/prism-typescript";

Codesandbox

kelsny
  • 23,009
  • 3
  • 19
  • 48