Setup
- Download a distribution
- Include the script and stylesheets in your document (you will need to make sure the css and js file are on your server, and adjust the paths in the scriptand link tag)
<link href="prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="prettify.js"></script>
- Add
onload="prettyPrint()"to your document's body tag. - Modify the stylesheet to get the coloring you prefer
Usage
Put code snippets in <pre class="prettyprint">...</pre> or <code class="prettyprint">...</code> and it will automatically be pretty printed.
| The original | Prettier |
|---|---|
class Voila { public: // Voila static const string VOILA = "Voila"; // will not interfere with embedded tags. } | class Voila { public: // Voila static const string VOILA = "Voila"; // will not interfere with embedded tags. } |
本文介绍如何在网页中使用Prettify.js库来自动美化代码片段,提高代码阅读体验。通过简单的步骤,可以将代码片段以更清晰、易读的形式展示,包括设置样式表和添加脚本。此外,提供了在文档中自动执行美化操作的方法,以及如何修改样式表以获得自定义的颜色方案。
428

被折叠的 条评论
为什么被折叠?



