Windows Live Writer插件:在WLW中插入语法高亮代码(二)

    在 上文 中,我发布了一个在WLW中插入语法高亮代码的插件,该插件使用tablimagee的HTML 标记来分隔代码与行号。这样做的一个问题是,针对不同的博客主题,行 号列的宽度可能需要手动调整,而且大量的<td></td>标记使得博客文章变得很大。为此,我修改了插件源代码,使用空格来分隔代码与行号。这样做其实也有弊端,比如代码折行的时候,折行后的第一个字符会与行号的第一个字符同列,这会使行号与代码变得混淆难以分辨。此外,在读者Ctrl+C复制代码的时候,会连同行号一起复制过去。

    您可以点击 这里 下载这个更新后的语法高亮插件,在下载后,直接解压到WLW的Plugins目录下,重启WLW即可使用。注意,在复制的时候要先退出WLW,否则会出现文件替代的共享冲突。

    下面的代码就是通过该插件插入的代码片段,展示于此给读者参考。

  • C#

    using   System;
    using   System . Reflection;
    using   System . IO;
    using   System . Collections . Generic;
    using   System . Linq;
    using   System . Text;

    namespace   ConsoleApplication3
    {
    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

    unit   uMain;

    interface

    uses
        Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
        Dialogs,   ComCtrls,   Menus,   ToolWin,   ExtCtrls,   ActnList;

    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

 

    在使用的过程中有什么问题,请直接回复本帖联系我,谢谢您的支持!

转载于:https://www.cnblogs.com/daxnet/archive/2009/05/06/1686982.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值