How to use rehype-highlight in ReactMarkdown? #69
-
Hopefully it's okay to post it here. I was trying to use rehype-highlight in ReactMarkdown. Btw my ReactMarkdown works just fine without plugin. Based on the doc, I should be able to use it like this: import ReactMarkdown from 'react-markdown'
import rehypeHighlight from 'rehype-highlight';
ReactDom.render(
<ReactMarkdown rehypePlugins={[rehypeHighlight]}>
This ~is not~ strikethrough, but ~~this is~~!
</ReactMarkdown>,
document.body
) but I'm getting an error in my Next.js app: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/languages/arduino' is not defined by "exports" in /xxx/node_modules/highlight.js/package.json imported from /xxx/node_modules/lowlight/lib/common.js I tried reproducing in a new Create React App project but get a different error: ./node_modules/hast-util-to-text/index.js 363:65
Module parse failed: Identifier directly after number (363:65)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| // break is the zero-width space character (U+200B), then the break is
| // removed, leaving behind the zero-width space.
> if (lines[index].charCodeAt(lines[index].length - 1) === 0x20_0b
| /* ZWSP */
| || index < lines.length - 1 && lines[index + 1].charCodeAt(0) === 0x20_0b |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
@dominicarrojado what versions of each library are you using? appears to work as expected https://codesandbox.io/s/react-markdown-rehype-highlight-32obr?file=/src/App.js. For Next.js have you enabled ESM support? https://nextjs.org/blog/next-11-1#es-modules-support For CRA what version of libraries are you using? Have you customized the browserslist by any chance? |
Beta Was this translation helpful? Give feedback.
@dominicarrojado what versions of each library are you using?
Trying out an example in codesandbox https://codesandbox.io/s/react-markdown-rehype-highlight-32obr?file=/src/App.js
With
[email protected]
[email protected]
[email protected]
[email protected]
appears to work as expected https://codesandbox.io/s/react-markdown-rehype-highlight-32obr?file=/src/App.js.
For Next.js have you enabled ESM support? https://nextjs.org/blog/next-11-1#es-modules-support
And what versions of libraries are you using?
For CRA what version of libraries are you using? Have you customized the browserslist by any chance?