Autohokey:将剪贴板格式从html更改为文本

时间:2016-01-18 11:18:44

标签: html clipboard autohotkey

如何在脚本末尾的几个正则表达式之后切换回富文本(因此我可以使用富文本而不是HTML)?

此脚本复制所选文本,检索HTML,格式化(删除/更改某些html标记)。所以当我最后通过剪贴板时,我有一个html格式。当我过去时,如何重新更改剪贴板的格式以获取文本格式:我希望能够将剪贴板粘贴到MSWord中,而不是仅仅在html编辑器中。

实际代码=文本格式→html格式 我要找的代码是:文本格式→html格式→文本格式 我正在寻找的代码可能看起来很奇怪,但我需要访问html标签来格式化它们。

!^+k::                  ;Alt(!) CTRL(^) shift(+) AND c
clipboard =
Send, {CTRLDOWN}c{CTRLUP}{ESC}
ClipWait
;          Change clipboard content from text to html with tag
ClipboardGet_HTML( byref Data ) { ; http://www.autohotkey.com/forum/viewtopic.php?p=392624#392624
 If CBID := DllCall( "RegisterClipboardFormat", Str,"HTML Format", UInt )
  If DllCall( "IsClipboardFormatAvailable", UInt,CBID ) <> 0
   If DllCall( "OpenClipboard", UInt,0 ) <> 0
    If hData := DllCall( "GetClipboardData", UInt,CBID, UInt )
       DataL := DllCall( "GlobalSize", UInt,hData, UInt )
     , pData := DllCall( "GlobalLock", UInt,hData, UInt )
     , Data := StrGet( pData, dataL, "UTF-8" )
     , DllCall( "GlobalUnlock", UInt,hData )
 DllCall( "CloseClipboard" )
Return dataL ? dataL : 0
}

If ClipboardGet_HTML( Data ){
;     MsgBox, % Data
     clipboard = %Data%
; parse HTML to remove tag attributes - bcoz I want to apply a style on <span id="textmark...  I first replace them with a unique string that enable me to personalize their style after the parsing
HHSpanid := RegExReplace(clipboard, "<span id=""textmark", "TO2BE2REPLACED$0")
HHSpanidclass := RegExReplace(HHSpanid, "<span class=""textmark", "TO2BE2REPLACED$0")
Replacehtmlmarker := RegexReplace(HHSpanidclass, "<(p|span|div|img|h1|h2|h3|h4|h5|h6|h7|a|label|blockquote|form|svg|path|input|header|sup|br|iframe|button|time|nav)\K [^>]+(?=>)")
RemoveImg := RegExReplace(Replacehtmlmarker, "<img>", "")
ReplaceHHSpan := RegExReplace(RemoveImg, "TO2BE2REPLACED<span>", "<span style=""color: black;background-color: #ffff00;"">")
clipboard = %ReplaceHHSpan%
ClipWait
return
     }
Else SoundBeep

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

查看WinClip课程 具体为SetHTML( html, source = "" )Paste( plainText = "" )

相关问题