Skip to content

Commit 8d1b1c1

Browse files
committed
Strip comments from color schemes
This has been a problem. Because xml.parser.expat doesn't seem to be able to handle comments like this: `<!-- comments --- -->`, it is probably best to strip them out. Another common problem is that people put comments before the encoding declaration. This will address that as well. It is easier to just clean it up than educate people. ref: #24 and #22
1 parent 7f9dccb commit 8d1b1c1

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

lib/color_scheme_matcher.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
from .rgba import RGBA
3030
from os import path
3131
from collections import namedtuple
32-
ST3 = int(sublime.version()) >= 3000
33-
if not ST3:
34-
from plistlib import readPlist
35-
else:
36-
from plistlib import readPlistFromBytes
32+
from plistlib import readPlistFromBytes
3733

3834

3935
class SchemeColors(
@@ -72,14 +68,14 @@ def __init__(self, scheme_file, ignore_gutter=False, track_dark_background=False
7268
color_filter = self.filter
7369
self.color_scheme = path.normpath(scheme_file)
7470
self.scheme_file = path.basename(self.color_scheme)
75-
if ST3:
76-
self.plist_file = color_filter(
77-
readPlistFromBytes(sublime.load_binary_resource(sublime_format_path(self.color_scheme)))
78-
)
79-
else:
80-
self.plist_file = color_filter(
81-
readPlist(sublime.packages_path() + self.color_scheme.replace('Packages', ''))
71+
self.plist_file = color_filter(
72+
readPlistFromBytes(
73+
re.sub(
74+
br"(\r?\n?\s*)*<!--[\s\S]*?-->(\s*\r?\n?)*", b'',
75+
sublime.load_binary_resource(sublime_format_path(self.color_scheme))
76+
)
8277
)
78+
)
8379
self.scheme_file = scheme_file
8480
self.ignore_gutter = ignore_gutter
8581
self.track_dark_background = track_dark_background

0 commit comments

Comments
 (0)