问题
I'm trying to highlight C++ file with Prismjs https://prismjs.com/index.html file highlight plugin https://prismjs.com/plugins/file-highlight/. So I tried:
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
<link href="themes/prism.css" rel="stylesheet" />
</head>
<body>
<script src="prism.js"></script>
<pre data-src="main.cpp"></pre>
<pre><code class="language-css">p { color: red }</code></pre>
</body>
</html>
But its not working. The piece of CSS appear there but the main.cpp
(which is in the same folder as index.html
and prism.js
) don't show up. I got:
Any suggestion on were should I look?
I'm not used to html/css/js.
回答1:
You did not select the 'file highlight' plugin when you downloaded prism. Just had the same problem. Downloaded it again with it selected and it worked for me.
回答2:
As stated by @Norman Potts you need to add the file highlight plugin.
I used: https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+c+cpp+json&plugins=line-highlight+line-numbers+file-highlight+keep-markup+unescaped-markup
also you only need this
<pre data-src="main.cpp"></pre>
not this
<pre><code class="language-css">p { color: red }</code></pre>
来源:https://stackoverflow.com/questions/51947855/prismjs-highlight-file