Jump to content
Sign in to follow this  
Ascend4nt

_ClipPutHTML

Recommended Posts

Ascend4nt

_ClipPutHTML

Okay, since I created the _ClipPutHyperlink() function, I figured I might as well just go one step further and open up the whole HTML Clipboard send/put interface and make it really simple to use - not only for simple Hyperlinks, but also for complete pieces of HTML code as well.

Note that 'PlainText' is the optional view of your HTML code that should be free of formatting. This is helpful when pasting to applications that don't accept HTML formatted strings, such as Notepad.

Note also that the HTML code NEEDS to be encoded in UTF-8 format. (For straight-ANSI/ASCII code, you don't need to do anything, UTF-8 encoding only comes into play for Unicode formatting).

Anyway, bundled in the ZIP is the UDF and a short example (same as the below HTMLPut Example).

Additionally, see the sample code for _ClipGetHTML().

Example 1: HyperlinkPut:

; Special Unicode text call
_ClipPutHyperlink("http://www.google.co.jp/",ChrW(0x30B0)& ChrW(0x30FC)& ChrW(0x30B0)& ChrW(0x30EB)& " (Japanese Google)")
; Regular text
_ClipPutHyperlink("http://www.google.com","Google")

- Example 'paste' Output -

Unicode Hyperlink:

グーグル (Japanese Google)

Regular Hyperlink:

Google

Example 2: HTMLPut

; Example is in 'Quote' because Code & AutoIt tags fail to handle this properly at the moment:

Local $sHTMLStr,$sPlainTextStr

$sHTMLStr='<html><head>'&@CRLF & " <title>Page Title</title>"&@CRLF & _

' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'&@CRLF & _

"</head>"&@CRLF & "<body>"&@CRLF & "<h1>Headline Text</h1>"&@CRLF & _

"<p>This is a paragraph showing the formatting possibilities using the "&@CRLF & _

'<a href="http://sites.google.com/site/ascend4ntscode/clipputhtml">_ClipPutHTML() functions</a>.'&@CRLF& _

" The regular modifiders, such as <strong>bold</strong>, <i>italics</i>, and <u>underlines</u> work as usual,"&@CRLF& _

" just like all other HTML formatting.</p>"&@CRLF & "<p>Â </p>"&@CRLF & _

"<p><strong>Here's an example list:</strong></p>"&@CRLF & "<ul>"&@CRLF & _

" <li>List <i>item</i> #1.</li>"&@CRLF & _

" <li>List <i>item</i> #2.</li>"&@CRLF & _

' <li>List <i>item</i> #3 with a <a href="http://www.google.com">Hyperlink</a></li>'&@CRLF & _

"</ul>"&@CRLF & "</body>"&@CRLF & "</html>"

$sPlainTextStr="Headline Text"&@CRLF&@CRLF& _

"This is a paragraph showing the formatting possibilities using the _ClipPutHTML() functions."& _

"The regular modifiders, such as bold, italics, and underlines work as usual, just like all other HTML formatting."&@CRLF&@CRLF& _

" Here's an example list:"&@CRLF& _

" * List item #1."&@CRLF& _

" * List item #2."&@CRLF& _

" * List item #3 with a Hyperlink"&@CRLF

_ClipPutHTML($sHTMLStr,$sPlainTextStr)

- Example 'paste' output -

Headline Text

This is a paragraph showing the formatting possibilities using the _ClipPutHTML() functions. The regular modifiders, such as bold, italics, and underlines work as usual, just like all other HTML formatting.

Here's an example list:

  • List item #1.
  • List item #2.
  • List item #3 with a Hyperlink

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.
Edited by Ascend4nt

Share this post


Link to post
Share on other sites
Ascend4nt
.. Edited by Ascend4nt

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Similar Content

    • ur
      By ur
      Is there any UDF to remove all anchor tags <a> with a particular class (and also its sub elements completely) in a html document.
      Here the classes are browse and breadcrumbs
      Like in the below image.


       
      I am not able to find that option in IE.au3
       
      Please suggest.
    • milkmoron
      By milkmoron
      I am trying to automate something in a web browser but i need some help with finding the html code to a web applet. How do I access the code.
    • Seminko
      By Seminko
      Is there a way to grab non-hardcoded but rather javascript generated data from a webpage?
      Tried a get request as well as _IEBodyReadHTML but both seem to grab the code without the javascript generated data.
      $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "link", False) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status Global $DataArray[10][5] If $oStatusCode <> 200 Then Exit MsgBox(1, "Error", "Status Code <> 200") EndIf FileWrite(@ScriptDir & "\output.txt", $oReceived) ; //////// #include <IE.au3> Local $FullLink = "link" Local $oIE = _IECreate($FullLink, 0, 0) _IELoadWait($oIE) Local $sText = _IEBodyReadHTML($oIE) FileWrite(@ScriptDir & "\output.txt", $sText)  
    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

    • therks
      By therks
      Hi there,
      So I've created this very simple "chat" program so that my brother and I can quickly and easily share text and links to other computers on the network. It just reads/writes to a text file that the script interprets/formats appropriately. I will put the script it in a shared network folder and then any of the computers can open and use it.
      For displaying the "chat" I'm currently using an embedded IE browser and formatting the text via HTML, but I've realized that this will cause problems with opening the links because it will use IE instead of the system's default browser (Chrome in our case). Any suggestions? (To be clear, I'm specifically looking for assistance on having text with clickable links that will open in the default browser.)
       
      For anyone interested, here's the code so far:
      #include <GUIConstants.au3> #include <GUIEdit.au3> #include <IE.au3> Opt('TrayIconDebug', 1) Global $CHAT_FILE = @ScriptDir & '\NetworkChat.txt' Main() Func Main() Local $hGUIMain = GUICreate('Network Chat', 500, 500, Default, Default, $WS_OVERLAPPEDWINDOW) Local $oEmbedIE = _IECreateEmbedded() Local $ob_EmbedIE = GUICtrlCreateObj($oEmbedIE, 5, 5, 490, 300) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) _IENavigate($oEmbedIE, 'about:blank') Local $dm_AccelTab = GUICtrlCreateDummy() Local $dm_AccelCtrlA = GUICtrlCreateDummy() Local $dm_AccelEnter = GUICtrlCreateDummy() Local $dm_AccelShiftEnter = GUICtrlCreateDummy() Local $dm_AccelPgUp = GUICtrlCreateDummy() Local $dm_AccelPgDn = GUICtrlCreateDummy() Local $ed_Chat = GUICtrlCreateEdit('', 5, 310, 470, 60, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT)) Local $aTabStop = [ 4 * 4 ] _GUICtrlEdit_SetTabStops($ed_Chat, $aTabStop) Local $bt_Send = GUICtrlCreateButton('>', 475, 310, 20, 60) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT)) GUICtrlSetState(-1, $GUI_DEFBUTTON) Local $ch_Timestamps = GUICtrlCreateCheckbox('Show &timestamps', 5, 370, 200, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKLEFT)) Local $ra_Enter = GUICtrlCreateRadio('&1. Enter to send / Shift+Enter for new line', 280, 370, 215, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT)) GUICtrlSetState(-1, $GUI_CHECKED) Local $ra_ShiftEnter = GUICtrlCreateRadio('&2. Shift+Enter to send / Enter for new line', 280, 390, 215, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT)) Local $aAccel = [ _ [ '{enter}', $dm_AccelEnter ], _ [ '+{enter}', $dm_AccelShiftEnter ], _ [ '{tab}', $dm_AccelTab ], _ [ '{pgup}', $dm_AccelPgUp ], _ [ '{pgdn}', $dm_AccelPgDn ], _ [ '^a', $dm_AccelCtrlA ] ] Local $aAccelSwap = $aAccel $aAccelSwap[0][0] = '+{enter}' $aAccelSwap[1][0] = '{enter}' GUISetAccelerators($aAccel) GUISetState() GUICtrlSetState($ed_Chat, $GUI_FOCUS) Local $sHTML, $aChatTime[2], $hFocused, $hIEControl = ControlGetHandle($hGUIMain, '', '[CLASS:Internet Explorer_Server; INSTANCE:1]') While 1 $hFocused = _WinAPI_GetFocus() $aChatTime[0] = FileGetTime($CHAT_FILE, 0, 1) If $aChatTime[0] <> $aChatTime[1] Then $sHTML = _LoadChat(BitAND(GUICtrlRead($ch_Timestamps), $GUI_CHECKED)) _IEDocWriteHTML($oEmbedIE, $sHTML) _IEAction($oEmbedIE, 'refresh') $oEmbedIE.document.parentwindow.scrollTo(0, $oEmbedIE.document.body.scrollHeight) $aChatTime[1] = $aChatTime[0] EndIf Local $iMsg = GUIGetMsg() If $iMsg > 0 Then ConsoleWrite($iMsg & @CRLF) Switch $iMsg Case $ch_Timestamps $aChatTime[1] = 0 Case $ra_Enter GUISetAccelerators($aAccel) Case $ra_ShiftEnter GUISetAccelerators($aAccelSwap) Case $dm_AccelPgUp $oEmbedIE.document.parentwindow.scrollBy(0, -200) Case $dm_AccelPgDn $oEmbedIE.document.parentwindow.scrollBy(0, 200) Case $dm_AccelCtrlA If $hFocused = GUICtrlGetHandle($ed_Chat) Then _GUICtrlEdit_SetSel($ed_Chat, 0, -1) Case $dm_AccelEnter If $hFocused = GUICtrlGetHandle($ed_Chat) Then If BitAND(GUICtrlRead($ra_Enter), $GUI_CHECKED) Then _SendChat($ed_Chat) Else _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF) EndIf EndIf Case $dm_AccelShiftEnter If $hFocused = GUICtrlGetHandle($ed_Chat) Then If BitAND(GUICtrlRead($ra_ShiftEnter), $GUI_CHECKED) Then _SendChat($ed_Chat) Else _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF) EndIf EndIf Case $bt_Send If $hFocused = GUICtrlGetHandle($ed_Chat) Then _SendChat($ed_Chat) Else GUICtrlSetState($ed_Chat, $GUI_FOCUS) EndIf Case $dm_AccelTab If $hFocused = GUICtrlGetHandle($ed_Chat) Then _GUICtrlEdit_ReplaceSel($ed_Chat, @TAB) Else GUICtrlSetState($ed_Chat, $GUI_FOCUS) EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc Func _EncodeForFile($sString) $sString = StringStripCR($sString) $sString = StringReplace($sString, '\', '\\') $sString = StringReplace($sString, @LF, '\n') $sString = StringReplace($sString, @TAB, '\t') Return $sString EndFunc Func _EncodeFromFile($sString) $sString = StringReplace($sString, '<', '<') $sString = StringReplace($sString, '>', '>') $sString = StringFormat($sString) $sString = StringReplace($sString, @TAB, '    ') $sString = StringReplace($sString, @LF, '<br />') $sString = StringRegExpReplace($sString, '(http://\S+)', '<a href="\1" target="_blank">\1</a>') Return $sString EndFunc Func _SendChat($iCtrl) Local $sChat = StringStripWS(GUICtrlRead($iCtrl), 3) If $sChat Then FileWrite($CHAT_FILE, @CRLF & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @TAB & @ComputerName & @TAB & _EncodeForFile($sChat)) GUICtrlSetData($iCtrl, '') Return True EndIf EndFunc Func _LoadChat($iShowTS) Local $aLines = FileReadToArray($CHAT_FILE), _ $sOutput = '<style>' $sOutput &= 'body, table { margin: 0; font-family: Arial; font-size: 0.8em; border-collapse: collapse; width: 100%; } ' $sOutput &= 'tr { vertical-align: top; text-align: left; } ' $sOutput &= '.name_column { white-space: nowrap; } ' $sOutput &= '.text_column { width: 100%; } ' $sOutput &= '.row1 { background: #eee; } ' $sOutput &= '.date { background: #bef; text-align: center; border: solid #000; border-width: 1px 0; } ' If Not $iShowTS Then $sOutput &= '.timestamp { display: none }' $sOutput &= '</style>' $sOutput &= '<table>' Local $sDateMem For $L = 0 To @extended-1 If Not $aLines[$L] Then ContinueLoop Local $aRegExLine = StringRegExp($aLines[$L], '(.+)\t(.+)\t(.+)', 1), $sChat If Not @error Then $aDateTime = _FormatTime($aRegExLine[0]) If $aDateTime[0] <> $sDateMem Then $sOutput &= '<tr><th class="date" colspan="2">' & $aDateTime[0] & '</th></tr>' $sDateMem = $aDateTime[0] EndIf $sOutput &= '<tr class="row' & Mod($L, 2) & '" title="' & $aDateTime[1] & '">' & _ '<th class="name_column"><span class="timestamp">[' & $aDateTime[1] & '] </span>' & $aRegExLine[1] & '</th>' & _ '<td class="text_column">' & _EncodeFromFile($aRegExLine[2]) & '</td></tr>' & @CRLF EndIf Next $sOutput &= '</table>' Return $sOutput EndFunc Func _FormatTime($sTime) Local $aMonths = StringSplit('Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec', '|') Local $aReturn[2] Local $aRegEx = StringRegExp($sTime, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', 1) If Not @error Then $aReturn[0] = $aRegEx[0] &'-'& $aMonths[Int($aRegEx[1])] &'-'& $aRegEx[2] $aReturn[1] = $aRegEx[3] &':'& $aRegEx[4] &':'& $aRegEx[5] EndIf Return $aReturn EndFunc
       
×