首页 > 软件发布 > 分享 > WP SyntaxHighlighter添加新语言AAuto
2012
11-29

WP SyntaxHighlighter添加新语言AAuto

wp后台下载启用wp-syntaxhighlighter后,使用ftp工具将插件目录中sample文件夹下的lang-pack-for-wp-syntaxhighlighter移动至wp的plugins
目录中。lang-pack-for-wp-syntaxhighlighter是基于wp-syntaxhighlighter的语言高亮管理插件,可以向wp-syntaxhighlighter中添加新语言。
打开lang-pack-for-wp-syntaxhighlighter.php文件,向里面添加几行代码:
54行左右

$wp_sh_brush_files['AAuto'] = array($add_nl_plugin_url.'aauto/shBrushAAuto.js', 'aau aauto', 'all', 'added');

85行左右

$wp_sh_language3['aauto'] = array('AAuto', 'added');

105行左右

$wp_sh_language2['aauto'] = array('AAuto', 'added');

然后lang-pack-for-wp-syntaxhighlighter目录下新建文件夹,命名为aauto,新建shBrushAAuto.js文件,内容如下:

SyntaxHighlighter.brushes.AAuto = function() {
	var keywords =	'begin end false true if else elseif class function return while do namespace ' +
	'select case catch try for in this global self owner var def null and not or ' +
	'break continue import with ctor try catch eval import type assert assertf error ' +
	'rget loadcode , dumpcode collectgarbage call invoke tostring topointer tonumber ' +
	'sleep execute setlocale setprivilege ' 
	;

	this.regexList = [
		{ regex: /\/(\*+)((?!\1\/)[\s\S])*\1\//g, css: 'comments' },
		{ regex: /"([^"])*"/g, css: 'string' },
		{ regex: SyntaxHighlighter.regexLib.multiLineSingleQuotedString, css: 'string' },
		{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' },
		{ regex: new RegExp(this.getKeywords(keywords), 'gm'),	css: 'keyword' }
	]; 

};

SyntaxHighlighter.brushes.AAuto.prototype	= new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.AAuto.aliases	= ['aau', 'aauto' ];

重启插件。即可在语言列表中看到AAuto

AAuto代码演示:

//定时执行线程任务

import win.ui;
/*DSG{{*/
var winform = ..win.form( bottom=211;parent=...;right=349;text="使用thread.event创建定时执行任务的线程" )
winform.add( 
trackbar={ bottom=82;max=1000;right=319;left=15;top=52;z=2;min=500;cls="trackbar" };
lbTip={ bottom=103;left=26;right=100;top=85;z=3;transparent=1;cls="static" };
static={ bottom=44;align="center";right=309;left=138;top=13;center=1;z=5;edge=1;cls="static" };
btnStart={ bottom=155;text="启动定时线程";left=61;top=113;z=1;right=181;cls="button" };
btnStop={ disabled=1;bottom=155;right=312;left=192;top=113;z=4;text="结束定时线程";cls="button" }
)
/*}}*/

task_t = function(hwnd,ms){
	import win;
	import thread.event;
	
	var evt = thread.event("定时事件 GUID:32DA0FC7-A96D-4850-9A28-DA1DD4464B44")
	while( ! evt.wait(ms) ){ 
		win.setText(hwnd,tostring( time() ) )
	}
	io.print("任务已完成")
}

import thread.event;
var evtTask = thread.event("定时事件 GUID:32DA0FC7-A96D-4850-9A28-DA1DD4464B44",false)

winform.btnStart.oncommand = function(id,event){

	winform.btnStart.disabled = true;
	winform.btnStop.disabled = false;
	winform.trackbar.disabled = true;
	
	hThread = thread.create(task_t,winform.static.hwnd,winform.trackbar.pos);
	thread.waitOne(hThread)
	
	winform.btnStart.disabled = false;
	winform.btnStop.disabled = true;
	winform.trackbar.disabled = false;
}

winform.btnStop.oncommand = function(id,event){
	evtTask.set();//使事件对象切换为有信号状态,使wait函数退出
}

winform.trackbar.oncommand = function(id,event,pos){
	winform.lbTip.text = owner.pos + "毫秒"
}
 
winform.show() 
win.loopMessage();
最后编辑:
作者:NINE
这个作者貌似有点懒,什么都没有留下。

WP SyntaxHighlighter添加新语言AAuto》有 3 条评论

  1. ForEcho 说:

    按照你的步骤来 为什么没有添加成功呢?
    语言列表中没有看到AAuto
    我用的是WP SyntaxHighlighter 1.7.3版本

留下一个回复

你的email不会被公开。