-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdasher.py
More file actions
36 lines (30 loc) · 1.17 KB
/
dasher.py
File metadata and controls
36 lines (30 loc) · 1.17 KB
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
32
33
34
35
36
import sublime, sublime_plugin, re
class DasherToggleCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
regions = view.sel()
for region in regions:
region = view.word(region)
replace_string = ""
new_line = ""
substr = view.substr(region)
newline_split = re.split("\n", substr)
for line in newline_split:
# check if we have dash - remove dash and titlecase
if line.find("-") != -1:
new_line = line.replace('-', ' ')
new_line = self.title_case(new_line);
# add dash
else:
new_line = line.replace(' ', '-')
new_line = new_line.lower()
if replace_string != "":
replace_string += "\n"
replace_string += new_line
view.replace(edit, region, replace_string)
def title_case(self, string):
split_str = re.split(" ", string)
out = []
for word in split_str:
out.append(word.capitalize())
return " ".join(out)