AU3高亮代码转51Blog脚本

        51Blog的后台编辑器支持" 插入代码",但 语法高亮却做的不够好。因此,我写了下面这个简单脚本,将SciTE编辑器中的高亮代码转换到51blog编辑器源码中,以方便大家阅读。
        使用方法:将SciTE编辑器中代码输出为 HTML文档,再用本脚本将HTML文档转换为 TXT文档,把TXT文档代码复制粘贴到51blog编辑器源码中即可。
#include <IE.au3>
#include <GUIConstants.au3>

$Form1 = GUICreate ( "AU3→51Blog代码转换器" , 251 , 41 , 283 , 154 )
$Button1 = GUICtrlCreateButton ( "读取HTML文件并转换为TXT" , 40 , 8 , 171 , 25 , 0 )
GUISetState ( @SW_SHOW )

While 1
    $nMsg = GUIGetMsg ()
    Sleep ( 100 )
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
            Button1Click ()
    EndSwitch
WEnd

Func Button1Click ()
$OpenFile = FileOpenDialog ( "读取HTML文件" , "" , "网页,全部(*.htm;*.html)" , 1 + 2 )
$RepalaceFile = "<div><div style=""border-right: #cccccc 1px solid; padding-right: 4px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 10pt; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; color: #000000; word-break: break-all; line-height: 16px; padding-top: 4px; border-bottom: #cccccc 1px solid; font-family: verdana,宋体; background-color: #eeeeee"">"
$oIE = _IECreate ( $OpenFile , 0 , 0 )
$sHTML = _IEDocReadHTML ( $oIE )
$sHTML = StringRegExpReplace ( $sHTML , "\r\n" , "" )
$sHTML = StringRegExpReplace ( $sHTML , "<HTML.*?bgColor=#ffffff><SPAN>" , $RepalaceFile )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S0>" , "<font color=#000000>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S1>" , "<font color=#009933>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S3>" , "<font color=#AC00A9>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S4>" , "<font color=#000090>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S5>" , "<font color=#0000FF>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S6>" , "<font color=#FF33FF>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S7>" , "<font color=#9999CC>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S8>" , "<font color=#FF0000>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S9>" , "<font color=#AA0000>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S11>" , "<font color=#F000FF>" )
$sHTML = StringReplace ( $sHTML , "<SPAN class=S12>" , "<font color=#A00FF0>" )
$sHTML = StringReplace ( $sHTML , "</SPAN>" , "</font>" )
$sHTML = StringReplace ( $sHTML , "</BODY></HTML>" , "</div></div>" )
If FileExists ( @DesktopDir & "\au3to51blog.txt" ) Then
    FileDelete ( @DesktopDir & "\au3to51blog.txt" )
EndIf
    FileWrite ( @DesktopDir & "\au3to51blog.txt" , $sHTML )
Exit
EndFunc
还差几个颜色代码,分别是S2、S10、S13、S14等,如果谁发现了,麻烦发给我,谢谢!
 
 
2010年AutoIt语法高亮51CTO博客专用代码更新(上面代码继续可用):
 
#include <IE.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;GUI事件响应模式

GUICreate("AutoIt高亮代码工具", 400, 70,  -1,  -1, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateLabel("请将需转换的Html文件拖放到下面的输入框", 20, 10)
$Input = GUICtrlCreateInput("", 20, 30, 270, 20)
GUICtrlSetState(-1, $GUI_ACCEPTFILES) ;支持拖放
$Button = GUICtrlCreateButton("转换", 306, 18, 80, 40, 0)
GUISetState(@SW_SHOW)

GUICtrlSetOnEvent($Button, "Gui")
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")

While 1
    sleep(1000)
WEnd

Func Gui()
  Switch @GUI_CtrlId
    Case $GUI_EVENT_CLOSE
        Exit
    Case $Button
       $FileName = GUICtrlRead($Input) ;获取文件路径
        $Suffix = StringRight($FileName, 5) ;取文件的后缀名
        If $Suffix <> ".html" Then
           MsgBox(16,"警告(只支持Html文件)","没有拖放文件到输入框或文件不是Html格式!!!")
        Else
         $RepalaceFile='<div id="code" style="border-right: #cccccc 1px solid; padding-right: 4px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 10pt; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; color: #000000; word-break: break-all; line-height: 16px; padding-top: 4px; border-bottom: #cccccc 1px solid; font-family: verdana,宋体; background-color: #eeeeee">'
          $oIE=_IECreate($FileName,0,0)
          $sHTML=_IEDocReadHTML($oIE)
          $sHTML=StringRegExpReplace ($sHTML, "\r\n", "")
          $sHTML=StringRegExpReplace($sHTML, "<HTML.*?bgColor=#ffffff>",$RepalaceFile)
          $sHTML=StringReplace($sHTML, "<SPAN class=S0>", "<font color=#000000>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S1>", "<font color=#009933>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S2>", "<font color=#669900>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S3>", "<font color=#AC00A9>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S4>", "<font color=#000090>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S5>", "<font color=#0000FF>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S6>", "<font color=#FF33FF>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S7>", "<font color=#9999CC>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S8>", "<font color=#FF0000>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S9>", "<font color=#AA0000>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S10>", "<font color=#FF8800>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S11>", "<font color=#F000FF>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S12>", "<font color=#A00FF0>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S13>", "<font color=#A00FF0>") ;未找到对应的颜色
          $sHTML=StringReplace($sHTML, "<SPAN class=S14>", "<font color=#0000FF>")
          $sHTML=StringReplace($sHTML, "<SPAN class=S15>", "<font color=#0080FF>")
          $sHTML=StringReplace($sHTML, "</SPAN>", "</font>")
          $sHTML=StringReplace($sHTML, "</BODY></HTML>", "</div></div>")
          If FileExists(@ScriptDir&"\au3to51blog.txt") Then
            FileDelete(@ScriptDir&"\au3to51blog.txt")
          EndIf
         FileWrite(@ScriptDir&"\au3to51blog.txt",$sHTML)
        EndIf
        Exit
  EndSwitch
EndFunc

你可能感兴趣的:(代码,职场,休闲,autoit,au3)