From 6167dda01d0a96c1faa10b349d4d02b0ee37e80d Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sat, 3 Jun 2017 00:53:59 +0200 Subject: [PATCH] Compact json list output --- src/Site/SiteStorage.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Site/SiteStorage.py b/src/Site/SiteStorage.py index bb0578df..103f184e 100644 --- a/src/Site/SiteStorage.py +++ b/src/Site/SiteStorage.py @@ -266,6 +266,15 @@ class SiteStorage(object): content = re.sub("\{(\n[^,\[\{]{10,100}?)\}[, ]{0,2}\n", compact_dict, content, flags=re.DOTALL) + def compact_list(match): + if "\n" in match.group(0): + stripped_lines = re.sub("\n[ ]*", "", match.group(1)) + return match.group(0).replace(match.group(1), stripped_lines) + else: + return match.group(0) + + content = re.sub("\[([^\[\{]{2,300}?)\][, ]{0,2}\n", compact_list, content, flags=re.DOTALL) + # Remove end of line whitespace content = re.sub("(?m)[ ]+$", "", content)