【问题标题】:Autohokey: Change clipboard format from html to textAutohotkey:将剪贴板格式从 html 更改为文本
【发布时间】:2016-04-23 13:10:03
【问题描述】:

如何在脚本末尾的几个正则表达式之后切换回富文本(这样我可以通过富文本而不是 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

非常感谢您的帮助!

【问题讨论】:

    标签: html clipboard autohotkey


    【解决方案1】:

    查看WinClip 课程。
    特别是SetHTML( html, source = "" )Paste( plainText = "" )

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 2014-01-24
      • 2010-09-25
      • 1970-01-01
      • 2015-08-08
      • 2021-06-21
      相关资源
      最近更新 更多