Skip to content

Commit

Permalink
Parse unexpected color scheme extension correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Oct 31, 2017
1 parent 9281774 commit 8ee2157
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions docs/src/markdown/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.0.5

> Oct 30, 2017
- **FIX**: Parse color schemes with unexpected extensions correctly.

## 3.0.4

> Oct 27, 2017
Expand Down
21 changes: 11 additions & 10 deletions st3/mdpopups/st_color_scheme_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
FONT_STYLE = "font_style" if int(sublime.version()) >= 3151 else "fontStyle"
GLOBAL_OPTIONS = "globals" if int(sublime.version()) >= 3152 else "defaults"

# XML
IS_XML_RE = re.compile(br'^[\r\n\s]*<')
XML_COMMENT_RE = re.compile(br"^[\r\n\s]*<!--[\s\S]*?-->[\s\r\n]*|<!--[\s\S]*?-->")

# For new Sublime format
FLOAT_TRIM_RE = re.compile(r'^(?P<keep>\d+)(?P<trash>\.0+|(?P<keep2>\.\d*[1-9])0+)$')

Expand Down Expand Up @@ -323,19 +327,16 @@ def __init__(self, scheme_file, color_filter=None):
"""Initialize."""
if color_filter is None:
color_filter = self.filter
self.legacy = not scheme_file.lower().endswith('.sublime-color-scheme') if NEW_SCHEMES else True
self.color_scheme = path.normpath(scheme_file)
self.scheme_file = path.basename(self.color_scheme)
if self.legacy:
scheme_obj = readPlistFromBytes(
re.sub(
br"^[\r\n\s]*<!--[\s\S]*?-->[\s\r\n]*|<!--[\s\S]*?-->", b'',
sublime.load_binary_resource(sublime_format_path(self.color_scheme))
)
)
self.convert_format(scheme_obj)

content = sublime.load_binary_resource(sublime_format_path(self.color_scheme))
if scheme_file.lower().endswith(('.tmtheme', '.hidden-tmtheme')) or IS_XML_RE.match(content) is not None:
self.legacy = True
self.convert_format(readPlistFromBytes(XML_COMMENT_RE.sub(b'', content)))
else:
self.scheme_obj = sublime.decode_value(sublime.load_resource(sublime_format_path(self.color_scheme)))
self.legacy = False
self.scheme_obj = sublime.decode_value(content.decode('utf-8'))
if 'variables' not in self.scheme_obj:
self.scheme_obj['variables'] = {}
if GLOBAL_OPTIONS not in self.scheme_obj:
Expand Down
2 changes: 1 addition & 1 deletion st3/mdpopups/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Version."""

_version_info = (3, 0, 4)
_version_info = (3, 0, 5)
__version__ = '.'.join([str(x) for x in _version_info])


Expand Down

0 comments on commit 8ee2157

Please sign in to comment.