Typecho 原版对于代码并没有做什么特殊处理,非常简洁,仅仅用 <pre><code>
包围起来,对于经常面对代码的人来说,阅读起来不是那么舒服。
ArmxMod for Typecho 集成了强大的 Prism 语法高亮显示器,作为 Stripe、React、sitepoint 等众多知名网站都采用高亮显示器,Prism 支持 HTML、PHP、Javascript、CSS、ASP 等等当下流行的高达 184 种开发语言语法。
在本主题中,只要指定要以哪种语言高亮即可,没有多余的操作要求,十分简单。
代码示例
一起来看几个示例:
HTML:
<html>
<head>
<title>HTML 高亮示例</title>
</head>
<body>
<div class="text">
<p style="display:block;">高亮使用方法很简单</p>
<span id="span">只要用 ``` 把代码包起来,指定语言即可</span>
<a href="/">如:
` ` `html
代码块
` ` `
</a>
</div>
</body>
</html>
PHP:
<?php if (!empty( Helper::options()->switch ) && in_array('Commentfirst',Helper::options()->switch)){
$db = Typecho_Db::get();
$sql = $db->select()->from('table.comments')
->where('cid = ?',$this->cid)
->where('mail = ?', $this->remember('mail',true))
->limit(1);
$result = $db->fetchAll($sql);
if($this->user->hasLogin() || $result) {
echo parseContent($this,1);
} else {
echo parseContent($this,0);
}
} else {
echo parseContent($this,1);
}
?>
对于超长代码,会收缩高度:
<script type="text/javascript">
(function () {
window.TypechoComment = {
dom : function (id) {
return document.getElementById(id);
},
create : function (tag, attr) {
var el = document.createElement(tag);
for (var key in attr) {
el.setAttribute(key, attr[key]);
}
return el;
},
reply : function (cid, coid) {
var comment = this.dom(cid), parent = comment.parentNode,
response = this.dom('respond-post-908'), input = this.dom('comment-parent'),
form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0],
textarea = response.getElementsByTagName('textarea')[0];
if (null == input) {
input = this.create('input', {
'type' : 'hidden',
'name' : 'parent',
'id' : 'comment-parent'
});
form.appendChild(input);
}
input.setAttribute('value', coid);
if (null == this.dom('comment-form-place-holder')) {
var holder = this.create('div', {
'id' : 'comment-form-place-holder'
});
response.parentNode.insertBefore(holder, response);
}
comment.appendChild(response);
this.dom('cancel-comment-reply-link').style.display = '';
if (null != textarea && 'text' == textarea.name) {
textarea.focus();
}
return false;
},
cancelReply : function () {
var response = this.dom('respond-post-908'),
holder = this.dom('comment-form-place-holder'), input = this.dom('comment-parent');
if (null != input) {
input.parentNode.removeChild(input);
}
if (null == holder) {
return true;
}
this.dom('cancel-comment-reply-link').style.display = 'none';
holder.parentNode.insertBefore(response, holder);
return false;
}
};
})();
</script>
未指定语法,不进行高亮。
高级设置
高级设置中可以配置要以哪种风格来高亮语法,如清新简洁(默认)、暗夜迷人、略施粉黛、似近黄昏等等,各个风格各有特色,可以根据主题自定义的风格来选择。
高级设置中还可以配置是否自动对代码添加行数,方便定位查阅。
Windows 10Chrome 75.0.3770.80来自 北京 的大神
QQ 头像测试
Windows 10Chrome 75.0.3770.80来自 天津 的大神
QQ 头像再次测试