-
Notifications
You must be signed in to change notification settings - Fork 133
/
setup.py
45 lines (31 loc) · 1.29 KB
/
setup.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
import sublime
from xml.dom.minidom import CDATASection
original_writexml = None
warning_shown = False
WARNING_MESSAGE = """
Warning! You are using patched version of xml.dom.minidom.CDataSection.writexml from indent_xml plugin.
For more details and how to disable please refer to https://github.com/alek-sys/sublimetext_indentxml
"""
def show_warning():
global warning_shown
if not warning_shown:
print(WARNING_MESSAGE)
warning_shown = True
def patch_minidom_cdata():
global original_writexml
def patched_writexml(self, writer, indent="", addindent="", newl=""):
show_warning()
if self.data.find("]]>") >= 0:
raise ValueError("']]>' not allowed in a CDATA section")
writer.write("%s<![CDATA[%s]]>%s" % (indent, self.data, newl))
original_writexml = CDATASection.writexml
setattr(CDATASection, "writexml", patched_writexml)
def is_minidom_patching_disabled():
settings = sublime.load_settings("indent_xml.Sublime-settings")
return settings.get('disable_patch_minidom', False)
def plugin_loaded():
if not is_minidom_patching_disabled():
patch_minidom_cdata()
def plugin_unloaded():
if not is_minidom_patching_disabled() and original_writexml:
setattr(CDATASection, "writexml", original_writexml)