copy google doc comments I can't edit wile keeping the formatting

Post your working scripts, libraries and tools for AHK v1.1 and older
partof
Posts: 110
Joined: 16 Jan 2016, 08:38

copy google doc comments I can't edit wile keeping the formatting

Post by partof » 06 Nov 2020, 05:40

1) get the WinClip module (which contains 2 file)

in WinClip.ahk replace this

Code: Select all

GetHtml()
  {
    if !( clipSize := this._fromclipboard( clipData ) )
      return ""
    if !( out_size := this._getFormatData( out_data, clipData, clipSize, "HTML Format" ) )
      return ""
    return strget( &out_data, out_size, "CP0" )
  }
by

Code: Select all

GetHtml(enc:="UTF-8")
  {
    if !( clipSize := this._fromclipboard( clipData ) )
      return ""
    if !( out_size := this._getFormatData( out_data, clipData, clipSize, "HTML Format" ) )
      return ""
    return strget( &out_data, out_size, enc )
  }
(more info on https://www.autohotkey.com/boards/viewtopic.php?t=71323)

2) use this script (and change the path inside):

Code: Select all

;++++++++++++++++++ copy google docs comment (get html, replace b/i tags with *, remove all html tags, past as text)


#Include C:\Users\xxx\modul_ahk\WinClip\WinClip.ahk
#Include C:\Users\xxx\modul_ahk\WinClip\WinClipAPI.ahk

wc := new WinClip

; shortcut will only work on google docs
SetTitleMatchMode, Regex
#If WinActive("Google Docs ahk_class Chrome_WidgetWin_1", Tweaks)
^!+d::

WinClip.Copy()
t := WinClip.GetHTML()

; if you add a  single space before/after the markdown symbol,  GoogleDocs ignore the markdown symbol -so we replace then with a random place holder (df4523ght) and then in "text" mode we replace if with a  single space (cf end of the script)
StringReplace t, t,% "<b ", % "df4523ght*<b ", A  
StringReplace t, t,% "</b>", % "</b>*df4523ght", A
StringReplace t, t,% "<i ", % "df4523ght_<i ", A  
StringReplace t, t,% "</i>", % "</i>_df4523ght", A
StringReplace t, t,% "<br ", % "`n<br ", A           

;   remove all html tags
t := RegExReplace(t, "<.*?>")

; remove all first line of hmtl = fragment, urlsource....  
t:=RegExReplace(t,"^.*?\R.*?\R.*?\R.*?\R.*?\R.*?\R.*?\R.*?\R")

; replace space placeholder
StringReplace t, t,% "df4523ght", % " ", A           

clipboard = %t%
TrayTip Clipboard, Clipboard Ready, 1

return
ps: this script did not work on my main shortcut.ahk file (I don't know why), so I included it by writting this on the top of it:

Code: Select all

 #Include %A_ScriptDir%\ahk_apps\copy_gdoc_comment_with_formatting.ahk

Return to “Scripts and Functions (v1)”