Jake.codes

To Markdown, for Pythonista

Thursday, January 02, 2014

# -*- coding: utf-8 -*-
# Based on Gabe from MacDrifter's
# URL to Markdown trick
# http://www.macdrifter.com/2012/09/pythonista-trick-url-to-markdown.html
#
# javascript:location.href='pythonista://ToMarkdown?action=run&argv='+encodeURIComponent(location.href);
#
import sys
import console
import clipboard
import urllib
import urllib2
import webbrowser

try:
    clipString = sys.argv[1]
except:
    clipString = console.input_alert('To Markdown', '', clipboard.get(), 'Get Markdown')

marky = 'http://heckyesmarkdown.com/go/?u='

queryString = marky + clipString

reqMD = urllib2.Request(queryString)
openMD = urllib2.urlopen(reqMD)
content = (openMD.read().decode('utf-8'))

# clipboard.set(content)
# webbrowser.open(queryString)

draftsURL = 'drafts://x-callback-url/create?text=' + urllib.quote(content.encode('utf-8'))

webbrowser.open(draftsURL)