用prism实现的代码高亮,非常简单,但我却折腾了一下午。
下面是测试用的代码,吊用没有。。。
<script>
$(window).load(function(){
$("pre").addClass("prettyprint linenums");
prettyPrint();}
)
var ck, pageBody_string, doc, src, fnUrl, fileName_body, sign, res_json;
while (true) {
cookieManager.removeAllCookie();
cookieManager.acceptCookie();
cookieManager.removeSessionCookie();
}
fileName_body = http.get(fnUrl, {
headers : {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
"cookie" : ck,
"referer" : lanzouUrl,
"sec-fetch-mode" : "nested-navigate",
"sec-fetch-site": "same-origin",
"upgrade-insecure-requests" : "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
}
}).body.string();
</script>
下面才是有用的实现代码:
<!-- Emlog代码高亮-->
<script src="/content/templates/dux/prism.js?ver=2.1" type="text/javascript"></script>
<link href="/content/templates/dux/prism.css?ver=2.1" rel="stylesheet">
<script type="text/javascript">
$(function() {
$('pre').each(function () {
a = $(this).find("code");
if( a.length ){
a.addClass("line-numbers");
}else{
atm = $(this).html();
$(this).html( '<code class="line-numbers">'+atm+'</code>' );
}
})
Prism.highlightAll();
});
</script>
需要的直接拿走就好了,方便的话,评个论。直接代码放在 皮肤文件夹 的 echo_log.php 最后面就可以了
发表评论