首先我们要强烈地谴责小T,在集成代码高亮时把Delphi高亮功能给去掉了,本来highlighter有这个功能的,他居然把选项给丢了,谴责、谴责、再谴责。
虽然对PHP不精通,但是还是看的懂的,呵呵,在网上也找了highlighter的代码,发现boblog都加了Delphi代码高亮的,为啥SA就歧视偶们Borland Fans呢,居然把Delphi代码高亮给去掉了,郁闷中,其实要给某种编程语言加上代码高亮也不是什么难事,因为highlighter已经有这种功能,只需要把关键字加上就OK了。
今天有空偶好好看了一下编辑高亮的代码,发现admin\editor\plugins\insertcode\fckplugin.js 文件里有Delphi代码转换的函数,如下代码
JavaScript代码
- /* Delphi brush is contributed by Eddie Shipman */
- dp.sh.Brushes.Delphi = function()
- {
- var keywords = 'abs addr and ansichar ansistring array as asm begin boolean byte cardinal ' +
- 'case char class comp const constructor currency destructor div do double ' +
- 'downto else end except exports extended false file finalization finally ' +
- 'for function goto if implementation in inherited int64 initialization ' +
- 'integer interface is label library longint longword mod nil not object ' +
- 'of on or packed pansichar pansistring pchar pcurrency pdatetime pextended ' +
- 'pint64 pointer private procedure program property pshortstring pstring ' +
- 'pvariant pwidechar pwidestring protected public published raise real real48 ' +
- 'record repeat set shl shortint shortstring shr single smallint string then ' +
- 'threadvar to true try type unit until uses val var varirnt while widechar ' +
- 'widestring with word write writeln xor';
- this.regexList = [
- { regex: new RegExp('\\(\\*[\\s\\S]*?\\*\\)', 'gm'), css: 'comment' }, // multiline comments (* *)
- { regex: new RegExp('{(?!\\$)[\\s\\S]*?}', 'gm'), css: 'comment' }, // multiline comments { }
- { regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment' }, // one line
- { regex: dp.sh.RegexLib.SingleQuotedString, css: 'string' }, // strings
- { regex: new RegExp('\\{\\$[a-zA-Z]+ .+\\}', 'g'), css: 'directive' }, // Compiler Directives and Region tags
- { regex: new RegExp('\\b[\\d\\.]+\\b', 'g'), css: 'number' }, // numbers 12345
- { regex: new RegExp('\\$[a-zA-Z0-9]+\\b', 'g'), css: 'number' }, // numbers $F5D3
- { regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword' } // keyword
- ];
- this.CssClass = 'dp-delphi';
- this.Style = '.dp-delphi .number { color: blue; }' +
- '.dp-delphi .directive { color: #008284; }' +
- '.dp-delphi .vars { color: #000; }';
- }
- dp.sh.Brushes.Delphi.prototype = new dp.sh.Highlighter();
- dp.sh.Brushes.Delphi.Aliases = ['delphi', 'pascal'];
对应其它的函数,这个功能是齐全的,但是为什么Delphi代码就不能高亮呢,原来高亮接口文件fck_insertcode.html没有Delphi这个选项(小T啊小T,你可害苦我了)
XML/HTML代码
- <select id="icLan">
- <option value="xhtml">XML/HTML</option>
- <option value="javascript">JavaScript</option>
- <option value="css">CSS</option>
- <option value="csharp">C#</option>
- <option value="cpp">C++</option>
- <option value="java">Java</option>
- <option value="php">PHP</option>
- <option value="python">Python</option>
- <option value="ruby">Ruby</option>
- <option value="sql">SQL</option>
- <option value="vb">ASP/Visual Basic</option>
- </select>
凭直觉偶把select里多加了一个选项,代码如下:
XML/HTML代码
- <option value="delphi">delphi</option>
复制了一段Delphi代码进去,哈哈,搞定了,如下代码演示,最后我们再谴责一下小T和小A把偶们的最爱Delphi给去掉了。
最后偶把fck_insertcode.html文件发出来,你可以直接覆盖原admin\editor\plugins\insertcode\下的fck_insertcode.html即可,或者自己加上代码也行,说了这么多,还是感谢一下小T给Sablog加了代码高亮插件!
delphi代码
- unit u17288;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, OleCtrls, SHDocVw, StdCtrls,mshtml, AppEvnts, ExtCtrls;
- type
- TFrm_main = class(TForm)
- wb1: TWebBrowser;
- pnl1: TPanel;
- lbl1: TLabel;
- ApplicationEvents1: TApplicationEvents;
- procedure wb1DocumentComplete(Sender: TObject; const pDisp: IDispatch;
- var URL: OleVariant);
- procedure ApplicationEvents1Message(var Msg: tagMSG;
- var Handled: Boolean);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Frm_main: TFrm_main;
- implementation
- {$R *.dfm}
- procedure TFrm_main.wb1DocumentComplete(Sender: TObject;
- const pDisp: IDispatch; var URL: OleVariant);
- var doc:IHTMLDocument2;
- begin
- doc:=IHTMLDocument2(wb1.Document);
- if(doc<>nil) and (doc.body<>nil) then
- begin
- doc.body.style.borderstyle:='none';
- end;
- try
- wb1.oleobject.Document.body.Scroll := 'no';
- except
- end;
- end;
- procedure TFrm_main.ApplicationEvents1Message(var Msg: tagMSG;
- var Handled: Boolean);
- var
- p: TPoint;
- begin
- if Msg.message = WM_MOUSEMOVE then
- begin
- p := ScreenToClient(Msg.pt);
- lbl1.Caption := Inttostr(p.x) + ', ' + Inttostr(p.y);
- end;
- {如果要取得 WebBrowser 的点击坐标,这么写:
- if (Msg.hwnd = WebBrowser1.Handle) and (Msg.message = WM_LBUTTONDOWN) then
- begin
- p := ScreenToClient(Msg.pt);
- ShowMessage(Inttostr(p.x) + ', ' + Inttostr(p.y));
- end;}
- end;
- procedure TFrm_main.FormCreate(Sender: TObject);
- begin
- wb1.Navigate('http://ha.17288.com');
- end;
- end.
4 条评论
试试这个:无需代码插件在blog中做代码高亮
代码发芽网:http://www.fayaa.com/code/
支持近百种编程语言的
不错,可惜我不懂Delphi。
我的是在admin/editor/editor/plugins/insertcode下
太谢谢了我也喜欢Delphi
我每次插入delphi代码 自己修改了上面标题的名字~~~
有段时间我也想要能选择项里面有Delphi
一直没去研究 看了你的文章 就给马上行动 给我的sa加delphi高亮啊哈啊谢拉