PrismJS / PrismJS/prism

React + Prism.js highlights automatically after import

Open
#3,637 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

When I import Prism.js in a React app, Prism.js automatically and immediately hightlights all code blocks.

I want to highlight the code blocks manually.

This is my React app codes:

import React from "react";
import Prism from "prismjs";
import "prismjs/themes/prism-tomorrow.css";

const code = `const App = props => {
  return (
    <div>
      <h1> React App </h1>
      <div>Awesome code</div>
    </div>
  );
};
`;

export default function App() {
  return (
    <pre>
      <code className="language-javascript">{code}</code>
    </pre>
  );
}

See the live example at Codesandbox

How can I highlight the code block manually?

Note: I've also asked this question on Stackoverflow, but got no answers.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox, especially src/App.js, and reproduce the reported behavior after importing Prism.js. Determine whether the import causes the

 block to be highlighted automatically and identify the documented way to request highlighting manually. Done means the example remains unhighlighted until highlighting is explicitly requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.