欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

為SyntaxHighlighter添加新語言的方法

 更新時間:2013年10月16日 22:30:48   作者:  
因為經(jīng)常要在博客里貼一些Lua代碼,但是所使用的SyntaxHighlighter插件默認(rèn)不支持Lua語言,所以去研究了一下如何為SyntaxHighlighter添加并激活一個新的語言,這里將過程和有同樣需求的童鞋分享
因為經(jīng)常要在博客里貼一些Lua代碼,但是所使用的SyntaxHighlighter插件默認(rèn)不支持Lua語言,所以去研究了一下如何為SyntaxHighlighter添加并激活一個新的語言,這里將過程和有同樣需求的童鞋分享。(因為我添加的是Lua語言,下面的過程描述會以Lua為例,在添加你所需要的語言時,你只要將相應(yīng)的項更換為你的自定義設(shè)置即可)

1. 從這篇博客里尋找所需要的語言:http://www.undermyhat.org/blog/2009/09/list-of-brushes-syntaxhighligher/;
2. 下載對應(yīng)的shBrushXXX.js腳本,比如我下載的是shBrushLua.js,它看起來像這樣:


復(fù)制代碼 代碼如下:

SyntaxHighlighter.brushes.Lua = function()
{
 var keywords = 'break do end else elseif function if local nil not or repeat return and then until while this';
 var funcs = 'math\\.\\w+ string\\.\\w+ os\\.\\w+ debug\\.\\w+ io\\.\\w+ error fopen dofile coroutine\\.\\w+ arg getmetatable ipairs loadfile loadlib loadstring longjmp print rawget rawset seek setmetatable assert tonumber tostring';

 this.regexList = [
  { regex: new RegExp('--\\[\\[[\\s\\S]*\\]\\]--', 'gm'),  css: 'comments' },
  { regex: new RegExp('--[^\\[]{2}.*$', 'gm'),       css: 'comments' }, // one line comments
  { regex: SyntaxHighlighter.regexLib.doubleQuotedString,     css: 'string' },    // strings
  { regex: SyntaxHighlighter.regexLib.singleQuotedString,     css: 'string' },    // strings
  { regex: new RegExp(this.getKeywords(keywords), 'gm'),  css: 'keyword' }, // keyword
  { regex: new RegExp(this.getKeywords(funcs), 'gm'),      css: 'func' },  // functions
  ];
}

SyntaxHighlighter.brushes.Lua.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Lua.aliases = ['lua'];

3. 使用FTP工具登陸到WordPress空間,進(jìn)入到wp-content/plugins目錄,新建一個目錄,取一個有意義的名字,比如syntaxhighlighter-lua;
4. 將shBrushLua.js上傳到新創(chuàng)建的目錄;
5. 在該目錄創(chuàng)建一個另一個shBrushLua.php文件,添加如下內(nèi)容:

復(fù)制代碼 代碼如下:

<?php
/*
Plugin Name: SyntaxHighlighter Evolved: Lua
Description: Adds support for the Lua language to the SyntaxHighlighter Evolved plugin.
Author: Benny
Version: 1.0.0
*/

// SyntaxHighlighter Evolved doesn't do anything until early in the "init" hook, so best to wait until after that
add_action( 'init', 'syntaxhighlighter_lua_regscript' );

// Tell SyntaxHighlighter Evolved about this new language/brush
add_filter( 'syntaxhighlighter_brushes', 'syntaxhighlighter_lua_addlang' );

// Register the brush file with WordPress
function syntaxhighlighter_lua_regscript() {
    wp_register_script( 'syntaxhighlighter-brush-lua', plugins_url( 'shBrushLua.js', __FILE__ ), array('syntaxhighlighter-core'), '1.1.1' );
}

// Filter SyntaxHighlighter Evolved's language array
function syntaxhighlighter_lua_addlang( $brushes ) {
    $brushes['lua'] = 'lua';
    return $brushes;
}
?>

6. 文件都準(zhǔn)備完了,OK,進(jìn)入到WordPress后臺管理的Plugins下,應(yīng)該能看到新添加的一項syntaxhighlighter-lua,激活它。

Done! It should work now!

其實新添加的js和php文件也可以放到SyntaxHighlighter插件本身的目錄下,但是讓它獨(dú)立成插件的好處是,當(dāng)SyntaxHighlighter升級時,你的個人配置不會因為覆蓋而丟失。

相關(guān)文章

最新評論