Coolcode这个我想不用介绍了,一个很强大的代码高亮插件。我想很多人都在用或者用过吧。
但用起来确那么点麻烦。每次都要手动去添加代码,添加语言、行号是不是关闭这些。一个两个还好办。多了就麻烦了。下面来介绍下怎么样添加一个按钮放到WP的编缉器上。
一:找到:
edButtons[edButtons.length] =
new edButton('ed_code'
,'code'
,' '
'
,'
,'c'
);
在后面添加:
edButtons[edButtons.length] =
new edButton('ed_coolcode'
,'coolcode'
,''
,'< \coolcode>'
//注意上面的\应替换成/
,'x'
);
二:找到:
else if (button.id == 'ed_link') {
document.write('
');
}
在后面添加:
else if (button.id == 'ed_coolcode') {
document.write('
');
}
三:在文件末尾添加:
function edInsertCoolcode(myField, i, defaultLang, defaultLine) {
if (!defaultLang) {
defaultLang = 'php';
}
if (!defaultLine) {
defaultLine = 'off';
}
if (!edCheckOpenTags(i)) {
var codeLang = prompt('输入需要加亮的程序语言', defaultLang);
var codeLine = prompt('是否显示行号(on, off)', defaultLine);
edButtons[i].tagStart = '< ' + 'coolcode';
if (codeLang) {
edButtons[i].tagStart = edButtons[i].tagStart + ' lang="'
+ codeLang + '"'
}
if (codeLine) {
edButtons[i].tagStart = edButtons[i].tagStart + ' linenum="'
+ codeLine + '"';
}
edButtons[i].tagStart = edButtons[i].tagStart + '>';
edInsertTag(myField, i);
}
else {
edInsertTag(myField, i);
}
}
行了。以后要加亮代码的时候点一下按钮,然后填上你要显示的语言、选择是不是显示行号就OK了。非常方便,赶快试试吧!~
![]() |
0人
|
了这篇文章 |