Skip to content

Instantly share code, notes, and snippets.

@lutaf
Created January 22, 2013 05:20
Show Gist options
  • Select an option

  • Save lutaf/4592295 to your computer and use it in GitHub Desktop.

Select an option

Save lutaf/4592295 to your computer and use it in GitHub Desktop.
change for sublime text 2 plugin:Markdown to Clipboard
import sublime, sublime_plugin
import markdown2
import re
def lutaf_fix(content):
"""
for lutaf.com
"""
hr = re.compile(u'\s+href="(http[s]?://[^"]+)"',re.I|re.S|re.M)
def _repl(matchobj):
return u' href="/j?u=%s"' % matchobj.group(1)
return hr.sub(_repl,content).replace(u'<pre>',u'<pre class="highlight">')
class m2c(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
if view:
if view.substr(view.sel()[0]):
contents = view.substr(view.sel()[0])
message = u"selection converted and copied to clipboard"
else:
contents = view.substr(sublime.Region(0, view.size()))
message = u"converted and copied to clipboard"
md = markdown2.markdown(contents,extras=['footnotes','wiki-tables'])
md = lutaf_fix(md)
sublime.set_clipboard(md)
sublime.status_message(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment