Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text Markdown-to-HTML-email

I'm loving that I can use Editorial (iOS) to compose an email in Markdown and pipe a rendered HTML message straight to Mail.app. I'd love to do this with Sublime Text 3 and Sparrow (or any default mail client) on the Mac, and I'm wondering whether it will be possible (or sensible) for me to make a Sublime package or build script.

The only problem is that I don't know Python. I'm not looking for the final solution, just whether my plan of using Python is a reasonable one given that I'd like to actually get this working.

like image 985
Matt Stein Avatar asked Jul 14 '26 00:07

Matt Stein


1 Answers

That's a pretty cool idea actually.

  • Step 1: Get a markdown syntax definition, like: sublime-markdown-extended

  • Step 2: Go to "Tools -> Build System -> New Build System" and add your new build:


    { 
        "cmd": ["python", "-u", "/path/to/convert.py $file"],
        "selector": "source.markdown",
        "path": "/usr/local/lib/python"
    }
    
  • Step 3: convert.py uses markdown2 to create html and opens Mail.app for you:


    import sys
    import markdown2
    
    with open(sys.argv[0]) as f:
        script = 'tell application "Mail"' \
           'make new outgoing message with properties {' \
           'visible:true,content:"%s" }' \
        'end tell' % markdown2.markdown(f.read())
    
        p = Popen('/usr/bin/osascript',stdin=PIPE,stdout=PIPE)
        p.communicate(script)
    
like image 100
fanti Avatar answered Jul 15 '26 15:07

fanti