我安装了 babel-plugin-prismjs,使用以下代码制作了 .babelrc:
{
"plugins": [
["prismjs", {
"languages": ["javascript", "css", "html"],
"plugins": ["line-numbers", "show-language", "copy-to-clipboard", "toolbar", "inline-color"],
"theme": "prism-tomorrow",
"css": true
}
]
]
}
并将 Prism 导入 App.js。
这是 App.js 中的代码:
import React, { useEffect } from "react";
import Prism from "prismjs";
const code = `
const foo = 'foo';
const bar = 'bar';
console.log(foo + bar);
`.trim()
function App() {
useEffect(() =>{
Prism.highlightAll();
}, [])
return (
<pre className="line-numbers">
<code className="language-js">
{code}
</code>
</pre>
);
}
export default App;
但是该网页没有突出显示语法。我在这里想念什么?