注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 IB客座主编(四)美国西蒙公..
 帮助

AU3高亮代码转51Blog脚本


2008-03-30 15:25:09
 标签:代码 autoit au3   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://autoit.blog.51cto.com/228224/68972
        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等,如果谁发现了,麻烦发给我,谢谢!

本文出自 “AutoIt源码吧-编写自己的程序” 博客,请务必保留此出处http://autoit.blog.51cto.com/228224/68972


附件下载:
  Au3to51Blog源码和程序




    文章评论
 
2008-03-31 09:20:32
为什么起这个名字呢

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: