Merge branch 'master' into st4_json_lines
This commit is contained in:
commit
4bcdd31b6b
|
@ -12,4 +12,4 @@
|
|||
// { "key": "selector", "operator": "equal", "operand": "source.json" }
|
||||
// ]
|
||||
// }
|
||||
]
|
||||
]
|
||||
|
|
|
@ -28,12 +28,12 @@
|
|||
"command": "pretty_json_validate"
|
||||
},
|
||||
{
|
||||
"caption": "Preferences: Pretty JSON Settings",
|
||||
"command": "edit_settings",
|
||||
"args":
|
||||
{
|
||||
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
||||
"default": "{\n\t$0\n}\n"
|
||||
}
|
||||
},
|
||||
"caption": "Preferences: Pretty JSON Settings",
|
||||
"command": "edit_settings"
|
||||
}
|
||||
]
|
|
@ -1,25 +1,29 @@
|
|||
[
|
||||
{
|
||||
"id": "preferences",
|
||||
"children": [
|
||||
{
|
||||
"id": "package-settings",
|
||||
"children": [
|
||||
{
|
||||
"caption": "Pretty JSON",
|
||||
"children": [
|
||||
{
|
||||
"caption": "Settings",
|
||||
"command": "edit_settings",
|
||||
"args":
|
||||
{
|
||||
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
||||
"default": "{\n\t$0\n}\n",
|
||||
}
|
||||
},
|
||||
{
|
||||
"caption": "-"
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
"children": [
|
||||
{
|
||||
"caption": "Pretty JSON",
|
||||
"children": [
|
||||
{
|
||||
"args":
|
||||
{
|
||||
"base_file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings",
|
||||
"default": "{\n\t$0\n}\n"
|
||||
},
|
||||
"caption": "Settings",
|
||||
"command": "edit_settings"
|
||||
},
|
||||
{
|
||||
"caption": "-"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"id": "package-settings"
|
||||
}
|
||||
],
|
||||
"id": "preferences"
|
||||
}
|
||||
]
|
|
@ -18,10 +18,10 @@
|
|||
// Example: /usr/bin/local/jq
|
||||
"jq_binary": "jq",
|
||||
"jq_errors": false,
|
||||
"as_json":[
|
||||
"as_json": [
|
||||
"Packages/JSON/JSON.sublime-syntax",
|
||||
"Packages/PackageDev/Package/Sublime Text Commands/Sublime Text Commands.sublime-syntax",
|
||||
"Packages/PackageDev/Package/Sublime Text Settings/Sublime Text Settings.sublime-syntax",
|
||||
"Packages/PackageDev/Package/Sublime Text Menu/Sublime Text Menu.sublime-syntax"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ class PrettyJsonBaseCommand:
|
|||
)
|
||||
|
||||
@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")
|
||||
|
||||
sort_keys = settings.get("sort_keys", False)
|
||||
if PrettyJsonBaseCommand.force_sorting:
|
||||
if force_sorting:
|
||||
sort_keys = True
|
||||
|
||||
line_separator = settings.get("line_separator", ",")
|
||||
|
@ -87,7 +87,20 @@ class PrettyJsonBaseCommand:
|
|||
content = m[1:-1].strip()
|
||||
items = [a.strip() for a in content.split(os.linesep)]
|
||||
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):
|
||||
output_json = output_json.replace(m, replacement, 1)
|
||||
|
||||
|
@ -257,8 +270,7 @@ class PrettyJsonCommand(PrettyJsonBaseCommand, sublime_plugin.TextCommand):
|
|||
selection_text = self.view.substr(region)
|
||||
try:
|
||||
obj = self.json_loads(selection_text)
|
||||
|
||||
json_text = self.json_dumps(obj=obj, minified=False)
|
||||
json_text = self.json_dumps(obj=obj, minified=False, force_sorting=self.force_sorting)
|
||||
if not entire_file and settings.get("reindent_block", False):
|
||||
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" }
|
||||
```
|
||||
|
||||
#### List of commands that can be mapped to shortcuts
|
||||
- `pretty_json`
|
||||
- `un_pretty_json`
|
||||
- `pretty_json_goto_symbol`
|
||||
|
||||
### Convert JSON to XML
|
||||
|
||||
Using Command Palette <kbd>Ctrl+Shift+P</kbd> search for
|
||||
|
|
|
@ -33,4 +33,4 @@ html.dark div.toolbar {
|
|||
}
|
||||
html.light div.toolbar {
|
||||
background-color: #ffffff18;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[tool.black]
|
||||
skip_string_normalization: True
|
Loading…
Reference in New Issue