Prismjs highlight file

↘锁芯ラ 提交于 2020-08-05 17:04:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!