#65 - naive version of single quote detection, and trying to replace them into double quotes and parse again
This commit is contained in:
parent
a054124590
commit
31e47da8c1
|
@ -175,13 +175,25 @@ class PrettyJsonCommand(PrettyJsonBaseCommand):
|
|||
selection = region
|
||||
|
||||
try:
|
||||
obj = self.json_loads(self.view.substr(selection))
|
||||
selection_text = self.view.substr(selection)
|
||||
obj = self.json_loads(selection_text)
|
||||
self.view.replace(edit, selection, self.json_dumps(obj))
|
||||
|
||||
if selected_entire_file:
|
||||
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)
|
||||
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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue