Jump to content

Recommended Posts

Posted (edited)

_ClipGetHTML

Seeing as how I created the _ClipPutHTML() & _ClipPutHyperlink() functions, I figured why not complete the set of available functions and finish out the HTML clipboard read/set UDFs.

The below example is included in the ZIP file on my site.

Example: HTML Clipboard Monitor

#include <Misc.au3>     ; _IsPressed()

#include <_ClipGetHTML.au3>
; ================================================================================================
; <HTMLClipBoardMonitor.au3>
;
; Simple program used to Monitor and Report on HTML formatted ClipBoard data
;
; Functions:
; MemoWrite() ; from the AutoIT documentation examples
;
; Dependencies:
; <_ClipGetHTML.au3> ; _ClipGetHTML()
;
; See also:
; <_ClipPutHTML.au3>
;
; Author: Ascend4nt, and [??] (whoever coded the AutoIT Help examples with MemoWrite())
; ================================================================================================

Global $iMemo

; MemoWrite and GUI creation courtesy of AutoIT Help Examples

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite

Local $hGUI
Local $sHTMLStrPrev="",$aHTMLData
Local $sPlainText,$aHTMLLinks

; Create GUI
$hGUI = GUICreate("HTML ClipBoard Monitor ([F5] Forces Refresh)", 600, 400)
$iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, 0x200000)    ; $WS_VSCROLL=0x00200000
GUICtrlSetLimit($iMemo,1000000)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
    
Do
    $aHTMLData=_ClipGetHTML()
    If Not @error And ($aHTMLData[0]<>$sHTMLStrPrev Or _IsPressed("74")) Then
    $sPlainText=ClipGet()
    ; Clear the Edit Control
    GUICtrlSetData($iMemo,"","")
    MemoWrite("==== New HTML Data received ("&@HOUR&':'&@MIN&":"&@SEC&") ===="&@CRLF&"Version #"&$aHTMLData[1]&@CRLF& _
    "Fragment Start:"&$aHTMLData[2]&", Fragment End:"&$aHTMLData[3]&@CRLF& _
    "Selection Start (optional [-1=unavailable]):"&$aHTMLData[4]& _
    ", Selection End (optional):"&$aHTMLData[5]&@CRLF& _
    "Source URL (optional string):"&$aHTMLData[6]&@CRLF& _
    "4 characters at Fragment Start:"&StringMid($aHTMLData[0],$aHTMLData[2],4)&@CRLF& _
    "4 characters at Fragment End:"&StringMid($aHTMLData[0],$aHTMLData[3],4)&@CRLF)
    If $aHTMLData[4]<>-1 Then
    MemoWrite("4 characters at Selection Start:"&StringMid($aHTMLData[0],$aHTMLData[4],4)&@CRLF& _
    "4 characters at Selection End:"&StringMid($aHTMLData[0],$aHTMLData[5],4))
    EndIf
    MemoWrite("---- CF_HTML Header (size="&StringLen($aHTMLData[7])&") ----"&@CRLF&$aHTMLData[7]&@CRLF)
    MemoWrite("---- RAW HTML Data (UTF-8 size="&StringLen($aHTMLData[0])&") ----"&@CRLF&BinaryToString($aHTMLData[0],4)&@CRLF)
    MemoWrite("---- Plain Text Variant (size="&StringLen($sPlainText)&") ----"&@CRLF&$sPlainText)
    
    #cs     
    ; Want to put it back just the way it came? This is one approach, but
    ; the Offsets will not be placed properly
    ;_ClipPutHTML($aHTMLData[0],$sPlainText)
    
    ; This is the proper way:

    Local $sHTMLData=$aHTMLData[7]&$aHTMLData[0]
    _ClipBoard_SendHTML($sHTMLData,$sPlainText)
    #ce

    $sHTMLStrPrev=$aHTMLData[0]
    EndIf
Until _IsPressed("1B") Or GUIGetMsg()=-3    ; $GUI_EVENT_CLOSE=-3
GUIDelete($hGUI)

Get the Code at my Site

Ascend4nt's AutoIT Code License agreement:

While I provide this source code freely, if you do use the code in your projects, all I ask is that:

  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.
*EDIT: added Memory Lock/Unlock (recommended and often-used way to ensure a successful grab of a Clipboard memory object), and added clarification on correct way to get memory block size Edited by Ascend4nt
Posted (edited)

..

Edited by Ascend4nt
Posted (edited)

..

Edited by Ascend4nt
  • 5 years later...
Posted (edited)

Autoit v3.3.10.2

Thanks for this excellent work!

There's a small bug in the URL extraction: url containing the z letter are truncated.
 

Character classes

A character classes defines a set of allowed (resp. disallowed) characters, which the next character in subject is expected to match (resp. not to match).
Inside a character classes, most metacharacters loose their meaning (like $ . or *) or mean something else (like ^).
 

[ ... ] Matches any character in the explicit set: "[aeiou]" matches any lowercase vowel. A contiguous (in Unicode codepoint increasing order) set can be defined by putting an hyphen between the starting and ending characters: "[a-z]" matches any lowercase ASCII letter. To include a hyphen (-) in a set, put it as the first or last character of the set or escape it (-).
Notice that the pattern "[A-z]" is not the same as "[A-Za-z]": the former is equivalent to "[A-Z[]^_`a-z]".
To include a closing bracket in a set, use it as the first character of the set or escape it: "[][]" and "[[]]" will both match either "[" or "]".
Note that in a character class, only d, D, h, H, p{}, P{}, s, Q...E, S, v, V, w, W, and x sequences retain their special meaning, while b means the backspace character (Chr(8)). [^ ... ] Matches any character not in the set: "[^0-9]" matches any non-digit. To include a caret (^) in a set, put it after the beginning of the set or escape it (^).

 

 

 

 So ^ rnz are not intepreted. I replaced :

Local $sSourceURL=StringRegExp($sHTMLHeader,"(?i)SourceURL:([^ \r\n\z]+)",1)

with:

Local $sSourceURL=StringRegExp($sHTMLHeader,"(?i)SourceURL:(.*)\r\n",1)
Edited by Silpark

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...