我试图突出一些使用谷歌美化的语法,但到目前为止,它没有用。
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
<body onload="prettyPrint()" bgcolor="white">
<pre class="prettyprint">
<code class="language-css">
// Some source code
class Foo {
public int Bar { get; set; }
}
</code>
</pre>
是否有一个解决方案可以使这项工作不会过多地使用bootstrap中的pre标签?
答案 0 :(得分:25)
编辑,它在2.1.x下工作正常
使用这两个文件,而不是使用文档中描述的方法。
http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css
http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js
这对我有用
<!DOCTYPE html>
<html lang="en">
<head>
<link href="css/bootstrap.css" type="text/css" rel="stylesheet" />
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
</head>
<body onload="prettyPrint()" bgcolor="white">
<pre class="prettyprint linenums languague-css">
// Some source code
class Foo {
public int Bar { get; set; }
}
</pre>
</body>
</html>
答案 1 :(得分:3)
不确定为什么不建议修改:
<script>
// Activate Google Prettify in this page
addEventListener('load', prettyPrint, false);
$(document).ready(function(){
// Add prettyprint class to pre elements
$('pre').addClass('prettyprint');
}); // end document.ready
</script>
答案 2 :(得分:2)
链接到2个文件prettify.css后,prettify.js将此代码添加到页脚
<script>
// @prettify
!function ($) {
$(function(){
window.prettyPrint && prettyPrint()
})
}(window.jQuery);
// #prettify
</script>