prism-react-renderer icon indicating copy to clipboard operation
prism-react-renderer copied to clipboard

Unable to add additional languages

Open SiegeSailor opened this issue 2 years ago • 7 comments

Overview

I followed the FAQ How do I add more language highlighting support? on README.md to add additional languages other than the languages mentioned here. However, the error popped up:

Uncaught Error: Cannot find module './prism-latex'

Issue

I then went to check if the languages I wanted to add were in prism-react-renderer/prism, but none of them were found:

  • latex
  • tex
  • context

The version I am using is 1.3.1:

"dependencies": {
    "@docusaurus/core": "2.0.0-beta.15",
    "@docusaurus/preset-classic": "2.0.0-beta.15",
    "@docusaurus/theme-live-codeblock": "^2.0.0-beta.15",
    "@mdx-js/react": "^1.6.21",
    "@types/prettier": "^2.4.2",
    "clsx": "^1.1.1",
    "hast-util-is-element": "^1.1.0",
    "prettier": "^2.5.1",
    "prism-react-renderer": "^1.3.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "rehype-katex": "^4.0.0",
    "remark-math": "^3.0.1",
    "remark-mermaid-dataurl": "^1.0.2"
  },
  "devDependencies": {
    "@docusaurus/module-type-aliases": "2.0.0-beta.15",
    "@tsconfig/docusaurus": "^1.0.4",
    "typescript": "^4.5.2"
  },

I use prism-react-renderer in docusaurus. Here is my code in .md:

```latex
f(x)=
\left\{
\begin{matrix}
    x^{2} + 1, x \geq 0 \\
    x^{2} + 2, x < 0
\end{matrix}
\right.
```

Expected Behavior

Add syntax highlighting support for latex, tex, and context (They are basically the same though).

SiegeSailor avatar Feb 13 '22 18:02 SiegeSailor

@SiegeSailor Docusaurus offers a special API to declare additional languages. Please see our docs: https://docusaurus.io/docs/markdown-features/code-blocks#supported-languages

Josh-Cena avatar Feb 16 '22 03:02 Josh-Cena

@Josh-Cena Thank you for your response. However, I did use the special API to declare additional languages. The error message Uncaught Error: Cannot find module './prism-latex' comes after I add languages such as latex to docusaurus.config.js.

SiegeSailor avatar Feb 16 '22 17:02 SiegeSailor

Sorry, I can't reproduce it.

themeConfig: {
  prism: {
    additionalLanguages: ['latex'],
  },
}
```latex
\textit{Hello world!}
```
image

Could you look into node_modules/prismjs/components and see if prism-latex exists?

Josh-Cena avatar Feb 26 '22 13:02 Josh-Cena

@Josh-Cena Thank you for further research.

It looks like that prism-latex does exist in node_modules/prismjs/components: Screen Shot 2022-02-27 at 03 00 20

But Uncaught Error: Cannot find module './prism-latex' pops up when I use the following config:

Screen Shot 2022-02-27 at 23 42 16 Screen Shot 2022-02-27 at 23 48 01

If I don't set up latex in themeConfig, then the syntax wouldn't be highlighted:

```latex
f(x)=
\left\{
\begin{matrix}
    x^{2} + 1, x \geq 0 \\
    x^{2} + 2, x < 0
\end{matrix}
\right.
```
Screen Shot 2022-02-27 at 23 44 57

SiegeSailor avatar Feb 27 '22 15:02 SiegeSailor

Do you have a reproduction demo? Like your GitHub repo.

Josh-Cena avatar Feb 27 '22 22:02 Josh-Cena

@Josh-Cena Here is the repository I am using Docusaurus.

SiegeSailor avatar Mar 03 '22 16:03 SiegeSailor

Hi, @Josh-Cena.

Sorry for bothering you. Is there any update?

SiegeSailor avatar Mar 24 '22 08:03 SiegeSailor

Unable to reproduce this, please reopen in the docusaurus repo if needed.

carbonrobot avatar Feb 07 '24 15:02 carbonrobot