Skip to content

Instantly share code, notes, and snippets.

@CherryDT
Last active August 6, 2020 13:09
Show Gist options
  • Save CherryDT/c3e33fec3fbb23fa2389fc835b96b23c to your computer and use it in GitHub Desktop.
Save CherryDT/c3e33fec3fbb23fa2389fc835b96b23c to your computer and use it in GitHub Desktop.

Revisions

  1. CherryDT revised this gist Feb 28, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions evernote_code_wrap.ahk
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@

    ; WinClip is required, from here: https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/

    #include WinClipAPI.ahk
    #include WinClip.ahk
    #include %A_ScriptDir%\WinClipAPI.ahk
    #include %A_ScriptDir%\WinClip.ahk

    ; Ctrl+Alt+P = wrap plain text in clipboard to EN code block
    ^!p::EvernoteCodeWrap()
  2. CherryDT revised this gist Feb 28, 2020. 1 changed file with 21 additions and 1 deletion.
    22 changes: 21 additions & 1 deletion evernote_code_wrap.ahk
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,24 @@
    ; AutoHotkey script to wrap plain text clipboard contents for Evernote in such a way that they can be pasted as code
    ; block and won't get double empty lines, removed indents or anything like that.
    ; By David Trapp
    ; License: MIT

    ; WinClip is required, from here: https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/

    #include WinClipAPI.ahk
    #include WinClip.ahk

    ; Ctrl+Alt+P = wrap plain text in clipboard to EN code block
    ^!p::EvernoteCodeWrap()

    ; Ctrl+Alt+V = wrap plain text in clipboard to EN code block and paste
    ^!v::EvernoteCodeWrapAndPaste()

    EvernoteCodeWrapAndPaste() {
    EvernoteCodeWrap()
    Send ^v
    }

    EvernoteCodeWrap() {
    plainText := WinClip.GetText()

    @@ -18,4 +39,3 @@ EvernoteCodeWrap() {

    WinClip.SetHTML(html)
    }

  3. CherryDT revised this gist Feb 28, 2020. 1 changed file with 3 additions and 22 deletions.
    25 changes: 3 additions & 22 deletions evernote_code_wrap.ahk
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,3 @@
    ; AutoHotkey script to wrap plain text clipboard contents for Evernote in such a way that they can be pasted as code
    ; block and won't get double empty lines, removed indents or anything like that.
    ; By David Trapp
    ; License: MIT

    ; WinClip is required, from here: https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/

    #include WinClipAPI.ahk
    #include WinClip.ahk

    ; Ctrl+Alt+P = wrap plain text in clipboard to EN code block
    ^!p::EvernoteCodeWrap()

    ; Ctrl+Alt+V = wrap plain text in clipboard to EN code block and paste
    ^!v::EvernoteCodeWrapAndPaste()

    EvernoteCodeWrapAndPaste() {
    EvernoteCodeWrap()
    Send ^v
    }

    EvernoteCodeWrap() {
    plainText := WinClip.GetText()

    @@ -33,7 +12,9 @@ EvernoteCodeWrap() {
    innerHtml := RegExReplace(innerHtml, "<br>", "</div><div>")
    innerHtml := RegExReplace(innerHtml, "<div></div>", "<div><br/></div>")
    innerHtml := RegExReplace(innerHtml, " ", "&nbsp;")
    html := "<div style=""-en-clipboard:true;""><br/></div><div style=""-en-codeblock:true;""><div>" . innerHtml . "</div></div>"
    ; Note: normally EN uses <div> for the -en-clipboard part, but with <span> we can save one newline
    ; The <br/> is unfortunately required for this whole thing to work
    html := "<span style=""-en-clipboard:true;""><br/></span><div style=""-en-codeblock:true;""><div>" . innerHtml . "</div></div>"

    WinClip.SetHTML(html)
    }
  4. CherryDT revised this gist Feb 28, 2020. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions evernote_code_wrap.ahk
    Original file line number Diff line number Diff line change
    @@ -21,12 +21,20 @@ EvernoteCodeWrapAndPaste() {

    EvernoteCodeWrap() {
    plainText := WinClip.GetText()

    ; Clear other formats, most importantly ENML
    WinClip.Clear()
    WinClip.SetText(plainText)

    ; Convert
    plainText := RegExReplace(plainText, "\t", " ")
    Transform, innerHtml, HTML, % plainText
    innerHtml := RegExReplace(innerHtml, "[\r\n]", "")
    innerHtml := RegExReplace(innerHtml, "<br>", "</div><div>")
    innerHtml := RegExReplace(innerHtml, "<div></div>", "<div><br/></div>")
    innerHtml := RegExReplace(innerHtml, " ", "&nbsp;")
    html := "<div style=""-en-clipboard:true;""><br/></div><div style=""-en-codeblock:true;""><div>" . innerHtml . "</div></div>"

    WinClip.SetHTML(html)
    }

  5. CherryDT created this gist Feb 28, 2020.
    32 changes: 32 additions & 0 deletions evernote_code_wrap.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    ; AutoHotkey script to wrap plain text clipboard contents for Evernote in such a way that they can be pasted as code
    ; block and won't get double empty lines, removed indents or anything like that.
    ; By David Trapp
    ; License: MIT

    ; WinClip is required, from here: https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/

    #include WinClipAPI.ahk
    #include WinClip.ahk

    ; Ctrl+Alt+P = wrap plain text in clipboard to EN code block
    ^!p::EvernoteCodeWrap()

    ; Ctrl+Alt+V = wrap plain text in clipboard to EN code block and paste
    ^!v::EvernoteCodeWrapAndPaste()

    EvernoteCodeWrapAndPaste() {
    EvernoteCodeWrap()
    Send ^v
    }

    EvernoteCodeWrap() {
    plainText := WinClip.GetText()
    plainText := RegExReplace(plainText, "\t", " ")
    Transform, innerHtml, HTML, % plainText
    innerHtml := RegExReplace(innerHtml, "[\r\n]", "")
    innerHtml := RegExReplace(innerHtml, "<br>", "</div><div>")
    innerHtml := RegExReplace(innerHtml, "<div></div>", "<div><br/></div>")
    innerHtml := RegExReplace(innerHtml, " ", "&nbsp;")
    html := "<div style=""-en-clipboard:true;""><br/></div><div style=""-en-codeblock:true;""><div>" . innerHtml . "</div></div>"
    WinClip.SetHTML(html)
    }