转载时请标明文章原始出处和作者信息, 作者: lostsnow.
http://www.lsproc.com/blog/add_coolcode_quicktag_for_wordpress/
修改 wp-includes/js/quicktags.js 文件
1. 找到
edButtons[edButtons.length] =
new edButton('ed_code'
,'code'
,'<code>'
,'</code>'
,'c'
);
在后面添加
edButtons[edButtons.length] =
new edButton('ed_coolcode'
,'coolcode'
,''
,'</coolcode>'
,'x'
);
2. 找到
else if (button.id == 'ed_link') {
document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
}
在后面添加
else if (button.id == 'ed_coolcode') {
document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertCoolcode(edCanvas, ' + i + ');" value="' + button.display + '" />');
}
3. 在文件末尾添加
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);
}
}
-- EOF --