-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertAuthorHyperlinkCommand.py
More file actions
31 lines (27 loc) · 1017 Bytes
/
Copy pathInsertAuthorHyperlinkCommand.py
File metadata and controls
31 lines (27 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sublime, sublime_plugin
import re
class InsertAuthorHyperlinkCommand(sublime_plugin.TextCommand):
def run(self, edit):
c = sublime.get_clipboard()
region = self.view.sel()[0]
s = self.view.substr(region)
is_markdown = self.view.syntax() and self.view.syntax().name == 'Markdown'
if is_markdown:
c = re.sub(r'(?<!\\)([\)])', '\\\\\\1', c)
left = "["
right = "](" + c + "): "
if s != "":
left = "> " + left
right = right + s
else:
left = "<a href=\"" + c + "\">"
right = "</a>: "
if s != "":
left = "<blockquote>" + left
right = right + s + "</blockquote>"
#region = self.view.sel()[0]
self.view.replace(edit, region, left + right)
region = self.view.sel()[0]
self.view.sel().clear()
idx = region.a + len(left)
self.view.sel().add(sublime.Region(idx, idx))