
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
prism-code-editor
Advanced tools
Lightweight, extensible code editor component for the web using Prism
Lightweight, extensible code editor component for the web using Prism.
There are multiple fully featured code editors for the web such as Monaco, Ace, and CodeMirror. While these are awesome, they have a large footprint and are likely overkill for code examples, forms, playgrounds or anywhere you won't display large documents.
This library overlays syntax highlighted code over a <textarea>. Libraries like CodeFlask, react-simple-code-editor, and many others have been doing this for years, but this library offers some distinct advantages:
npm i prism-code-editor
If you're not using NPM and a bundler in your project, then you might be interested in this bundle builder where you can create a customized, minified bundle to use directly.
The library includes 3 different setups you can import. These will automatically import the necessary styles and scope them with a shadow root, add various extensions, and import all language specific behavior. There are also web components wrapping these setups if that's preferred.
import { minimalEditor, basicEditor, readonlyEditor } from "prism-code-editor/setups"
// Importing Prism grammars
import "prism-code-editor/prism/languages/markup"
const editor = basicEditor(
"#editor",
{
language: "html",
theme: "github-dark",
},
() => console.log("ready"),
)
Note: You might want to add display: grid to the container the editor is added to.
For more advanced usage where you have full control over styling and the added extensions, check the documentation.
This library has rewrites for both React and SolidJS. These rewrites better integrate with their respective framework than any wrapper ever could and are recommended if you're already using React or SolidJS.
height: auto without layout shiftsAll the code is tokenized each time for simplicity's sake. Even though only lines that change are updated in the DOM, the editor slows down as more code is added, although not as quickly as with zero optimizations.
Once you start exceeding 1000 LOC, the editor will start slowing down on most hardware. If you need to display that much code, consider a more robust/heavy library.
This has been tested to work in the latest desktop and mobile versions of Safari, Chrome, and Firefox. It should work in slightly older browsers too, but there will be many bugs present in browsers that don't support beforeinput events.
This library does not support any Prism plugins since Prism hooks have been removed, but behavior like the Highlight Keywords plugin is included.
Some grammars have had small changes, most notably markup tags' grammar. Prism themes will work to style the tokens, but there can be some slight differences.
In PrismJS, greedy matching is controlled by a greedy flag on the token. Here, it's instead controlled by the g flag on the pattern. When copying Prism grammars, be sure to remove the greedy flags and instead add the g flag to the regex.
Lists of aliases are not supported. To add multiple aliases to a token, separate them with spaces in a single string instead. For example, convert ["foo", "bar"] to "foo bar".
This library is made possible thanks to Prism.
Feature requests, bug reports, optimizations, and potentially new themes and extensions are all welcome.
To test your changes during development, install dependencies:
cd package
pnpm install
And run the development server:
pnpm run dev
FAQs
Lightweight, extensible code editor component for the web using Prism
The npm package prism-code-editor receives a total of 7,763 weekly downloads. As such, prism-code-editor popularity was classified as popular.
We found that prism-code-editor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.