implement: remaining fix for #109

remove: no-sublime-package
This commit is contained in:
TheSecEng 2020-04-17 17:22:19 -04:00
parent a261db2026
commit 9d17ced7f5
No known key found for this signature in database
GPG Key ID: A7C3BA459E8C5C4E
2 changed files with 18 additions and 11 deletions

View File

View File

@ -222,19 +222,26 @@ class PrettyJsonCommand(PrettyJsonBaseCommand, sublime_plugin.TextCommand):
self.change_syntax()
except Exception:
amount_of_single_quotes = re.findall(r"(\'[^\']+\'?)", selection_text)
amount_of_double_quotes = re.findall(r"(\"[^\"]+\"?)", selection_text)
if len(amount_of_single_quotes) >= len(amount_of_double_quotes):
selection_text_modified = re.sub(
r"(?:\'([^\']+)\'?)", r'"\1"', selection_text
try:
amount_of_single_quotes = re.findall(
r"(\'[^\']+\'?)", selection_text
)
amount_of_double_quotes = re.findall(
r"(\"[^\"]+\"?)", selection_text
)
obj = self.json_loads(selection_text_modified)
self.view.replace(edit, selection, self.json_dumps(obj))
if selected_entire_file:
self.change_syntax()
else:
if len(amount_of_single_quotes) >= len(amount_of_double_quotes):
selection_text_modified = re.sub(
r"(?:\'([^\']+)\'?)", r'"\1"', selection_text
)
obj = self.json_loads(selection_text_modified)
self.view.replace(edit, selection, self.json_dumps(obj))
if selected_entire_file:
self.change_syntax()
else:
self.show_exception()
except:
self.show_exception()