Created
December 7, 2019 14:37
-
-
Save llinfeng/fcf833f9b801e6c9ac903ee53338a89a to your computer and use it in GitHub Desktop.
An Autohotkey snippet that converts raw Markdown texts into "pastable" rich-text, for Gmail and even MS Word.
This file contains hidden or 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
| ::togo:: | |
| ; Debugging tips | |
| ; 1. Check if pandoc is installed. If not, the best way is to install through choco. | |
| ; choco install page:https://chocolatey.org/packages/pandoc | |
| ; 2. Check if `paste.exe` is available to PowerShell, same thing for `clip.exe` ==> these two are necessary Windows utilities/executable that were called with Ctrl+V and Ctrl+C | |
| Run, PowerShell "paste.exe | pandoc -f markdown-smart --from=gfm -t HTML | Set-Clipboard -AsHtml ; echo 'Conversion done.' " | |
| ; Caveat: single quotes are pasted wrongly, as question marks. | |
| Return |
version for ahk v2 with fixed clipboard processing encoding issues
::togo::
{
; Save current clipboard content
ClipSave := ClipboardAll
; PowerShell command to process clipboard content with pandoc
Command := "
(
$clipboard = Get-Clipboard -Raw -TextFormatType UnicodeText;
if (!$clipboard) { $clipboard = Get-Clipboard -Raw };
$converted = $clipboard | pandoc -f markdown-smart --from=gfm -t html;
Set-Clipboard -Text $converted -AsHtml;
Write-Output 'Conversion done.'
)"
; Run PowerShell command
RunWait "PowerShell -NoProfile -Command " . Command
; Paste the processed clipboard content
Send "^v"
; Restore the original clipboard content
Clipboard := ClipSave
ClipSave := ""
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
version for ahk 2.0