在 上文 中,我发布了一个在WLW中插入语法高亮代码的插件,该插件使用table的HTML 标记来分隔代码与行号。这样做的一个问题是,针对不同的博客主题,行 号列的宽度可能需要手动调整,而且大量的<td></td>标记使得博客文章变得很大。为此,我修改了插件源代码,使用空格来分隔代码与行号。这样做其实也有弊端,比如代码折行的时候,折行后的第一个字符会与行号的第一个字符同列,这会使行号与代码变得混淆难以分辨。此外,在读者Ctrl+C复制代码的时候,会连同行号一起复制过去。
您可以点击 这里 下载这个更新后的语法高亮插件,在下载后,直接解压到WLW的Plugins目录下,重启WLW即可使用。注意,在复制的时候要先退出WLW,否则会出现文件替代的共享冲突。
下面的代码就是通过该插件插入的代码片段,展示于此给读者参考。
- C#
1 using System;
2 using System . Reflection;
3 using System . IO;
4 using System . Collections . Generic;
5 using System . Linq;
6 using System . Text;
7
8 namespace ConsoleApplication3
9 {
10 class TGeneric < T >
11 {
12 public T Get ( T _t )
13 {
14 return _t;
15 }
16 }
17
18 class TGeneric < T, U >
19 { }
20
21 class Program
22 {
23 static string GetGenericTypeSignature ( Type genType )
24 {
25 if ( ! genType . IsGenericType )
26 return genType . Name;
27 StringBuilder result = new StringBuilder ( ) ;
28 result . Append ( genType . Name . Substring ( 0 , genType . Name . IndexOf ( ' ` ' ) ) ) ;
29 result . Append ( " < " ) ;
30 Type [ ] genericArguments = genType . GetGenericArguments ( ) ;
31 for ( int i = 0 ; i < genericArguments . Length; i + + )
32 {
33 result . Append ( genericArguments [ i ] . Name ) ;
34 if ( i ! = genericArguments . Length - 1 )
35 result . Append ( " , " ) ;
36 }
37 result . Append ( " > " ) ;
38 return result . ToString ( ) ;
39 }
40 static void Main ( string [ ] args )
41 {
42 foreach ( Type type in Assembly . GetExecutingAssembly ( ) . GetTypes ( ) )
43 {
44 if ( type . IsGenericType )
45 {
46 Console . WriteLine ( GetGenericTypeSignature ( type ) ) ;
47 }
48 }
49 }
50 }
51 }
52
- Borland Delphi
1 unit uMain;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, ComCtrls, Menus, ToolWin, ExtCtrls, ActnList;
8
9 type
10 TfrmMain = class (TForm)
11 StatusBar : TStatusBar;
12 MainMenu : TMainMenu;
13 F1 : TMenuItem;
14 CoolBar : TCoolBar;
15 MainToolBar : TToolBar;
16 ToolButton1 : TToolButton;
17 ObjectTree : TTreeView;
18 Splitter1 : TSplitter;
19 ActionList : TActionList;
20 ac_New : TAction;
21 New1 : TMenuItem;
22 procedure ac_NewExecute(Sender : TObject);
23 private
24 { Private declarations }
25 public
26 { Public declarations }
27 end ;
28
29 var
30 frmMain : TfrmMain;
31
32 implementation
33
34 uses uNewList, uGlobal, uDataDictionary;
35
36 { $R *.dfm }
37 procedure TfrmMain . ac_NewExecute(Sender : TObject);
38 var iRet : Integer;
39 dd : TDataDictionary;
40 begin
41 frmNewList . ShowModal;
42 iRet : = frmNewList . GetModuleResult;
43 if iRet = MODRES_CANCEL then Exit;
44 dd : = TDataDictionary . Create(frmNewList . GetConnectionString);
45 try
46 dd . BuildDataDictionary;
47 except
48 on E : Exception do MessageDlg (E . Message, mtError, [mbOK], 0 );
49 end ;
50 dd . Destroy;
51 end ;
52
53 end .
54
在使用的过程中有什么问题,请直接回复本帖联系我,谢谢您的支持!