-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtag_remove.py
executable file
·64 lines (56 loc) · 2.3 KB
/
tag_remove.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sublime, sublime_plugin
import re
from .Edit import Edit as Edit
def TagRemoveAll(data, view):
return re.sub(r'<[^\?][^>]*>', '', data);
def TagRemoveSelected(data, tags, view):
tags = tags.replace(',', ' ').replace(';', ' ').replace('|', ' ').replace('<', ' ').replace('>', ' ')+' '
for tag in tags.split(' '):
if tag:
regexp = re.compile('<'+re.escape(tag)+'(| [^>]*)>', re.IGNORECASE)
data = regexp.sub('', data);
regexp = re.compile('</'+re.escape(tag)+'>', re.IGNORECASE)
data = regexp.sub('', data);
return data;
class TagRemoveAllInSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
continue
dataRegion = sublime.Region(region.begin(), region.end())
data = TagRemoveAll(self.view.substr(dataRegion), self.view)
self.view.replace(edit, dataRegion, data);
class TagRemoveAllInDocumentCommand(sublime_plugin.TextCommand):
def run(self, edit):
dataRegion = sublime.Region(0, self.view.size())
data = TagRemoveAll(self.view.substr(dataRegion), self.view)
self.view.replace(edit, dataRegion, data);
class TagRemovePickedInSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit, tags = False):
if not tags:
import functools
self.view.window().run_command('hide_panel');
self.view.window().show_input_panel("Remove the following tags:", '', functools.partial(self.on_done, edit), None, None)
else:
self.on_done(edit, tags);
def on_done(self, edit, tags):
for region in self.view.sel():
if region.empty():
continue
dataRegion = sublime.Region(region.begin(), region.end())
data = TagRemoveSelected(self.view.substr(dataRegion), tags, self.view)
with Edit(self.view) as edit:
edit.replace(dataRegion, data);
class TagRemovePickedInDocumentCommand(sublime_plugin.TextCommand):
def run(self, edit, tags = False):
if not tags:
import functools
self.view.window().run_command('hide_panel');
self.view.window().show_input_panel("Remove the following tags:", '', functools.partial(self.on_done, edit), None, None)
else:
self.on_done(edit, tags);
def on_done(self, edit, tags):
dataRegion = sublime.Region(0, self.view.size())
data = TagRemoveSelected(self.view.substr(dataRegion), tags, self.view)
with Edit(self.view) as edit:
edit.replace(dataRegion, data);