Last active
August 6, 2020 13:09
-
-
Save CherryDT/c3e33fec3fbb23fa2389fc835b96b23c to your computer and use it in GitHub Desktop.
Evernote clipboard code wrapper tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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 %A_ScriptDir%\WinClipAPI.ahk | |
#include %A_ScriptDir%\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() | |
; 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, " ", " ") | |
; 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For macos, this works:
Now paste into Evernote and you get:
Therefore, you can convert any code in your clipboard to Evernote compatible HTML with:
I have a complete script at https://gist.github.com/RichardBronosky/c2d609b721df3ecc771c4980e9f6b63f