Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unreliable default settings handling.
Now use a auto-genearated default setting instead of hard writting them in the python source. Fix #47
- Loading branch information
Timon Wong
committed
Apr 14, 2014
1 parent
41f01e6
commit a8c3d92
Showing
4 changed files
with
120 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"html_template_name": "github", | ||
"browser_command": [], | ||
"refresh_on_saved": true, | ||
"server_host": "127.0.0.1", | ||
"refresh_on_modified_delay": 500, | ||
"refresh_on_modified": true, | ||
"server_port": 51004, | ||
"ajax_polling_interval": 500, | ||
"ignored_renderers": [ | ||
"LiterateHaskellRenderer" | ||
], | ||
"export_options": { | ||
"template_name": "github-export", | ||
"target_folder": ".", | ||
"open_after_exporting": false, | ||
"timestamp_format": "_%y%m%d%H%M%S", | ||
"copy_to_clipboard": false | ||
}, | ||
"renderer_options-MarkdownRenderer": { | ||
"extensions": [ | ||
"tables", | ||
"strikeout", | ||
"fenced_code", | ||
"codehilite" | ||
] | ||
}, | ||
"mathjax_enabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
|
||
''' | ||
Created on 20/01/2011 | ||
v0.1 (C) Gerald Storer | ||
MIT License | ||
Based on JSON.minify.js: | ||
https://github.com/getify/JSON.minify | ||
''' | ||
|
||
import re | ||
|
||
|
||
def json_minify(json, strip_space=True): | ||
tokenizer = re.compile('"|(/\*)|(\*/)|(//)|\n|\r') | ||
in_string = False | ||
in_multiline_comment = False | ||
in_singleline_comment = False | ||
|
||
new_str = [] | ||
from_index = 0 # from is a keyword in Python | ||
|
||
for match in re.finditer(tokenizer, json): | ||
|
||
if not in_multiline_comment and not in_singleline_comment: | ||
tmp2 = json[from_index:match.start()] | ||
if not in_string and strip_space: | ||
tmp2 = re.sub('[ \t\n\r]*', '', tmp2) # replace only white space defined in standard | ||
new_str.append(tmp2) | ||
|
||
from_index = match.end() | ||
|
||
if match.group() == '"' and not in_multiline_comment and not in_singleline_comment: | ||
escaped = re.search('(\\\\)*$', json[:match.start()]) | ||
if not in_string or escaped is None or len(escaped.group()) % 2 == 0: | ||
# start of string with ", or unescaped " character found to end string | ||
in_string = not in_string | ||
from_index -= 1 # include " character in next catch | ||
|
||
elif match.group() == '/*' and not in_string and not in_multiline_comment and not in_singleline_comment: | ||
in_multiline_comment = True | ||
elif match.group() == '*/' and not in_string and in_multiline_comment and not in_singleline_comment: | ||
in_multiline_comment = False | ||
elif match.group() == '//' and not in_string and not in_multiline_comment and not in_singleline_comment: | ||
in_singleline_comment = True | ||
elif (match.group() == '\n' or match.group() == '\r') and not in_string and not in_multiline_comment and in_singleline_comment: | ||
in_singleline_comment = False | ||
elif not in_multiline_comment and not in_singleline_comment and ( | ||
match.group() not in ['\n', '\r', ' ', '\t'] or not strip_space): | ||
new_str.append(match.group()) | ||
|
||
new_str.append(json[from_index:]) | ||
return ''.join(new_str) | ||
|
||
|
||
import json | ||
s = json_minify(open('OmniMarkupPreviewer.sublime-settings').read()) | ||
json_obj = json.loads(s) | ||
default_settings_string = json.dumps(json_obj, indent=4, separators=(',', ': ')) | ||
open('default_settings.json', 'w').write(default_settings_string) |