Merge branch 'master' into st4_json_lines
This commit is contained in:
commit
4bcdd31b6b
|
@ -28,12 +28,12 @@
|
||||||
"command": "pretty_json_validate"
|
"command": "pretty_json_validate"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"caption": "Preferences: Pretty JSON Settings",
|
|
||||||
"command": "edit_settings",
|
|
||||||
"args":
|
"args":
|
||||||
{
|
{
|
||||||
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
||||||
"default": "{\n\t$0\n}\n"
|
"default": "{\n\t$0\n}\n"
|
||||||
}
|
},
|
||||||
|
"caption": "Preferences: Pretty JSON Settings",
|
||||||
|
"command": "edit_settings"
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -1,25 +1,29 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "preferences",
|
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"id": "package-settings",
|
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"caption": "Pretty JSON",
|
"caption": "Pretty JSON",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"caption": "Settings",
|
|
||||||
"command": "edit_settings",
|
|
||||||
"args":
|
"args":
|
||||||
{
|
{
|
||||||
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
||||||
"default": "{\n\t$0\n}\n",
|
"default": "{\n\t$0\n}\n"
|
||||||
}
|
},
|
||||||
|
"caption": "Settings",
|
||||||
|
"command": "edit_settings"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"caption": "-"
|
"caption": "-"
|
||||||
}]
|
}
|
||||||
}]
|
]
|
||||||
}]
|
}
|
||||||
}]
|
],
|
||||||
|
"id": "package-settings"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "preferences"
|
||||||
|
}
|
||||||
|
]
|
|
@ -55,11 +55,11 @@ class PrettyJsonBaseCommand:
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def json_dumps(obj, minified: bool = False) -> str:
|
def json_dumps(obj, minified: bool = False, force_sorting: bool = False) -> str:
|
||||||
settings = sublime.load_settings("Pretty JSON.sublime-settings")
|
settings = sublime.load_settings("Pretty JSON.sublime-settings")
|
||||||
|
|
||||||
sort_keys = settings.get("sort_keys", False)
|
sort_keys = settings.get("sort_keys", False)
|
||||||
if PrettyJsonBaseCommand.force_sorting:
|
if force_sorting:
|
||||||
sort_keys = True
|
sort_keys = True
|
||||||
|
|
||||||
line_separator = settings.get("line_separator", ",")
|
line_separator = settings.get("line_separator", ",")
|
||||||
|
@ -87,7 +87,20 @@ class PrettyJsonBaseCommand:
|
||||||
content = m[1:-1].strip()
|
content = m[1:-1].strip()
|
||||||
items = [a.strip() for a in content.split(os.linesep)]
|
items = [a.strip() for a in content.split(os.linesep)]
|
||||||
items = [item[:-1] if item[-1] == "," else item for item in items]
|
items = [item[:-1] if item[-1] == "," else item for item in items]
|
||||||
replacement = f"[{join_separator.join(items)}]"
|
replacement = "["
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
if item in ('{', '}') or item.endswith("{") or item.startswith("}"):
|
||||||
|
replacement = replacement + item
|
||||||
|
if item == '}':
|
||||||
|
if index != len(items)-1 and items[index+1] != "}":
|
||||||
|
replacement = replacement + ','
|
||||||
|
else:
|
||||||
|
replacement = replacement + item
|
||||||
|
if index != len(items)-1:
|
||||||
|
if items[index+1] != '}':
|
||||||
|
replacement = replacement + ','
|
||||||
|
replacement = replacement + ']'
|
||||||
|
|
||||||
if len(replacement) <= settings.get("max_arrays_line_length", 120):
|
if len(replacement) <= settings.get("max_arrays_line_length", 120):
|
||||||
output_json = output_json.replace(m, replacement, 1)
|
output_json = output_json.replace(m, replacement, 1)
|
||||||
|
|
||||||
|
@ -257,8 +270,7 @@ class PrettyJsonCommand(PrettyJsonBaseCommand, sublime_plugin.TextCommand):
|
||||||
selection_text = self.view.substr(region)
|
selection_text = self.view.substr(region)
|
||||||
try:
|
try:
|
||||||
obj = self.json_loads(selection_text)
|
obj = self.json_loads(selection_text)
|
||||||
|
json_text = self.json_dumps(obj=obj, minified=False, force_sorting=self.force_sorting)
|
||||||
json_text = self.json_dumps(obj=obj, minified=False)
|
|
||||||
if not entire_file and settings.get("reindent_block", False):
|
if not entire_file and settings.get("reindent_block", False):
|
||||||
json_text = self.reindent(json_text, region)
|
json_text = self.reindent(json_text, region)
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,11 @@ you can add a setting like this to your .sublime-keymap file
|
||||||
{ "keys": [ "ctrl+alt+m" ], "command": "un_pretty_json" }
|
{ "keys": [ "ctrl+alt+m" ], "command": "un_pretty_json" }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### List of commands that can be mapped to shortcuts
|
||||||
|
- `pretty_json`
|
||||||
|
- `un_pretty_json`
|
||||||
|
- `pretty_json_goto_symbol`
|
||||||
|
|
||||||
### Convert JSON to XML
|
### Convert JSON to XML
|
||||||
|
|
||||||
Using Command Palette <kbd>Ctrl+Shift+P</kbd> search for
|
Using Command Palette <kbd>Ctrl+Shift+P</kbd> search for
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
[tool.black]
|
|
||||||
skip_string_normalization: True
|
|
Loading…
Reference in New Issue