I am experimenting with utilizing the Prism.js syntax highlighter on the client side as a dependency through npm
, rather than loading it via <script src="...">
tags. Below is the reference to Prism in my package.json file:
{
"dependencies": {
"prismjs": "^1.5.1"
}
}
This is how I am attempting to integrate it into my code:
import Prism from 'prismjs'
Prism.highlightAll();
The outcome of this implementation is as follows:
- Tokenizing functions properly for basic languages like HTML and JavaScript.
- However, tokenizing fails for certain specific languages such as Lua and Handlebars.
- Additionally, syntax coloring does not apply across all languages (suggesting that the CSS file may not be loading).
As a result, I have some questions:
- Are there separate language-specific packages available (e.g., prismjs-handlebars)?
- Can theme-specific packages be used (like prism-okaidia) to import the necessary CSS?
--
TL;DR
How can I implement Prism.js on the client side using npm
instead of script tags?