From 56763e95b841d39e2074720d17f1cdf5e858e86a Mon Sep 17 00:00:00 2001 From: Isaac Muse Date: Sun, 5 Sep 2021 16:57:39 -0600 Subject: [PATCH] Chore/pc4 (#89) * Add support for PC4 (changes needed to support latest mdpopups) * Reduce dependencies * Bump version * spelling --- CHANGES.md | 6 ++++ ExportHtml.py | 2 +- dependencies.json | 8 +----- docs/src/requirements.txt | 2 +- lib/color_scheme_matcher.py | 6 ++-- lib/color_scheme_tweaker.py | 4 +-- lib/st_colormod.py | 57 +++++++++++++++++++++---------------- lib/tmtheme.py | 16 ++++++----- mkdocs.yml | 1 + support.py | 2 +- tests/test_json.py | 2 +- tox.ini | 2 +- 12 files changed, 59 insertions(+), 49 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7ca945f..7af2e8f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # ExportHtml +## 2.17.3 + +- **FIX**: Fix a scheme loading related issue. +- **FIX**: Ensure ExportHTML will work with Package Control 4.0 (compatibility issues with latest `mdpopups` needed for + Package Control 4.0). + ## 2.17.2 - **FIX**: Fix a regression where custom defined schemes are not used. diff --git a/ExportHtml.py b/ExportHtml.py index 087cb35..50142a7 100755 --- a/ExportHtml.py +++ b/ExportHtml.py @@ -469,7 +469,7 @@ def setup(self, **kwargs): self.switch = False self.save_to_view = False self.view_scheme = view_scheme - if alt_scheme != view_scheme: + if isinstance(alt_scheme, str) and alt_scheme != view_scheme: switch = True if view_scheme != default.get('color_scheme'): self.save_to_view = True diff --git a/dependencies.json b/dependencies.json index 5917397..e8a675f 100644 --- a/dependencies.json +++ b/dependencies.json @@ -4,13 +4,7 @@ "python-jinja2" ], ">=3124": [ - "pygments", - "python-markdown", - "mdpopups", - "python-jinja2", - "markupsafe", - "pymdownx", - "pyyaml" + "mdpopups" ] } } diff --git a/docs/src/requirements.txt b/docs/src/requirements.txt index 299e5af..29804f9 100644 --- a/docs/src/requirements.txt +++ b/docs/src/requirements.txt @@ -1,4 +1,4 @@ -mkdocs_pymdownx_material_extras>=1.2.2 +mkdocs_pymdownx_material_extras>=1.4 mkdocs-git-revision-date-localized-plugin mkdocs-minify-plugin pyspelling diff --git a/lib/color_scheme_matcher.py b/lib/color_scheme_matcher.py index 8ee7b64..7256d00 100644 --- a/lib/color_scheme_matcher.py +++ b/lib/color_scheme_matcher.py @@ -418,7 +418,7 @@ def process_color_gradient(self, colors, simple_strip=False, bground=None): if not simple_strip: if bground is None: bground = self.special_colors['background']['color_simulated'] - rgb.overlay(Color(bground if bground != "" else "#FFFFFF")) + rgb.compose(Color(bground if bground != "" else "#FFFFFF")) gradient.append((color, rgb.to_string(**HEX))) if gradient: @@ -446,7 +446,7 @@ def process_color(self, color, simple_strip=False, bground=None): if not simple_strip: if bground is None: bground = self.special_colors['background']['color_simulated'] - rgb.overlay(Color(bground if bground != "" else "#FFFFFF")) + rgb.compose(Color(bground if bground != "" else "#FFFFFF")) return color, rgb.to_string(**HEX) @@ -481,7 +481,7 @@ def guess_color(self, scope_key, selected=False, explicit_background=False, no_b This was originally introduced for mdpopups so that it would know when a background was not needed. This allowed mdpopups - to generate syntax highlighted code that could be overlayed on + to generate syntax highlighted code that could be overlaid on block elements with different background colors and allow that background would show through. """ diff --git a/lib/color_scheme_tweaker.py b/lib/color_scheme_tweaker.py index a9d0bb9..515fbc6 100644 --- a/lib/color_scheme_tweaker.py +++ b/lib/color_scheme_tweaker.py @@ -307,7 +307,7 @@ def _filter_colors(self, *args, **kwargs): (bg is None or bg.strip() == "" or bg == "none") ): rgba = Color(rgba_fg) - rgba.overlay(self.bground if self.bground != "" else "#FFFFFF", in_place=True) + rgba.compose(self.bground if self.bground != "" else "#FFFFFF", in_place=True) bg = rgba.to_string(hex=True, alpha=False) + ("%02X" % int((255.0 * value))) try: rgba_bg = Color(bg) @@ -431,7 +431,7 @@ def _filter_colors(self, *args, **kwargs): (bg is None or bg.strip() == "" or bg == "none") ): rgba = Color(rgba_fg) - rgba.overlay(self.bground if self.bground != "" else "#FFFFFF", in_place=True) + rgba.compose(self.bground if self.bground != "" else "#FFFFFF", in_place=True) bg = rgba.to_string(hex=True, alpha=False) + ("%02X" % int((255.0 * value))) try: rgba_bg = Color(bg) diff --git a/lib/st_colormod.py b/lib/st_colormod.py index 8d7301c..1018d51 100644 --- a/lib/st_colormod.py +++ b/lib/st_colormod.py @@ -1,8 +1,8 @@ """Color-mod.""" import re -from mdpopups.coloraide.css import Color as ColorCSS -from mdpopups.coloraide.colors import ColorMatch -from mdpopups.coloraide.colors import _parse as parse +from mdpopups.coloraide import Color as ColorCSS +from mdpopups.coloraide import ColorMatch +from mdpopups.coloraide.spaces import _parse from mdpopups.coloraide import util import functools import math @@ -21,30 +21,32 @@ \#(?:{hex}{{6}}(?:{hex}{{2}})?|{hex}{{3}}(?:{hex})?) | [\w][\w\d]* ) - """.format(**parse.COLOR_PARTS) + """.format(**_parse.COLOR_PARTS) ), "functions": re.compile(r'(?i)[\w][\w\d]*\('), - "separators": re.compile(r'(?:{comma}|{space}|{slash})'.format(**parse.COLOR_PARTS)) + "separators": re.compile(r'(?:{comma}|{space}|{slash})'.format(**_parse.COLOR_PARTS)) } RE_ADJUSTERS = { "alpha": re.compile( r'(?i)\s+a(?:lpha)?\(\s*(?:(\+\s+|\-\s+)?({percent}|{float})|(\*)?\s*({percent}|{float}))\s*\)'.format( - **parse.COLOR_PARTS + **_parse.COLOR_PARTS ) ), - "saturation": re.compile(r'(?i)\s+s(?:aturation)?\((\+\s|\-\s|\*)?\s*({percent})\s*\)'.format(**parse.COLOR_PARTS)), - "lightness": re.compile(r'(?i)\s+l(?:ightness)?\((\+\s|\-\s|\*)?\s*({percent})\s*\)'.format(**parse.COLOR_PARTS)), + "saturation": re.compile( + r'(?i)\s+s(?:aturation)?\((\+\s|\-\s|\*)?\s*({percent})\s*\)'.format(**_parse.COLOR_PARTS) + ), + "lightness": re.compile(r'(?i)\s+l(?:ightness)?\((\+\s|\-\s|\*)?\s*({percent})\s*\)'.format(**_parse.COLOR_PARTS)), "min-contrast_start": re.compile(r'(?i)\s+min-contrast\(\s*'), "blend_start": re.compile(r'(?i)\s+blenda?\(\s*'), "end": re.compile(r'(?i)\s*\)') } -RE_HUE = re.compile(r'(?i){angle}'.format(**parse.COLOR_PARTS)) +RE_HUE = re.compile(r'(?i){angle}'.format(**_parse.COLOR_PARTS)) RE_COLOR_START = re.compile(r'(?i)color\(\s*') -RE_BLEND_END = re.compile(r'(?i)\s+({percent})(?:\s+(rgb|hsl|hwb))?\s*\)'.format(**parse.COLOR_PARTS)) +RE_BLEND_END = re.compile(r'(?i)\s+({percent})(?:\s+(rgb|hsl|hwb))?\s*\)'.format(**_parse.COLOR_PARTS)) RE_BRACKETS = re.compile(r'(?:(\()|(\))|[^()]+)') -RE_MIN_CONTRAST_END = re.compile(r'(?i)\s+({float})\s*\)'.format(**parse.COLOR_PARTS)) +RE_MIN_CONTRAST_END = re.compile(r'(?i)\s+({float})\s*\)'.format(**_parse.COLOR_PARTS)) RE_VARS = re.compile(r'(?i)(?:(?<=^)|(?<=[\s\t\(,/]))(var\(\s*([-\w][-\w\d]*)\s*\))(?!\()(?=[\s\t\),/]|$)') @@ -209,7 +211,7 @@ def _adjust(self, string, start=0): start = m.end(0) m = RE_HUE.match(string, start) if m: - hue = parse.norm_hue_channel(m.group(0)) + hue = _parse.norm_angle(m.group(0)) color = Color("hsl", [hue, 1, 0.5]).convert("srgb") start = m.end(0) if color is None: @@ -233,12 +235,13 @@ def _adjust(self, string, start=0): if color is not None: self._color = color - if not self._color.in_gamut(): - self._color.fit(method="clip", in_place=True) + self._color.fit(method="clip", in_place=True) while not done: m = None - for name, pattern in RE_ADJUSTERS.items(): + name = None + for key, pattern in RE_ADJUSTERS.items(): + name = key m = pattern.match(string, start) if m: start = m.end(0) @@ -260,8 +263,7 @@ def _adjust(self, string, start=0): else: break - if not self._color.in_gamut(): - self._color.fit(method="clip", in_place=True) + self._color.fit(method="clip", in_place=True) else: raise ValueError('Could not calculate base color') except Exception: @@ -306,7 +308,7 @@ def process_alpha(self, m, hue): else: value = m.group(4) if value.endswith('%'): - value = float(value.strip('%')) * parse.SCALE_PERCENT + value = float(value.strip('%')) * _parse.SCALE_PERCENT else: value = float(value) op = "" @@ -348,7 +350,7 @@ def process_blend(self, m, string, hue): raise ValueError("Could not find a valid color for 'blend'") m = RE_BLEND_END.match(string, start) if m: - value = float(m.group(1).strip('%')) * parse.SCALE_PERCENT + value = float(m.group(1).strip('%')) * _parse.SCALE_PERCENT space = "srgb" if m.group(2): space = m.group(2).lower() @@ -539,7 +541,7 @@ def _parse(self, color, data=None, alpha=util.DEF_ALPHA, filters=None, variables return obj elif isinstance(color, ColorCSS): if not filters or color.space() in filters: - obj = self.CS_MAP[color.space()](color._color) + obj = self.CS_MAP[color.space()](color._space) else: m = self._match(color, fullmatch=True, filters=filters, variables=variables) if m is None: @@ -581,7 +583,7 @@ def _match(cls, string, start=0, fullmatch=False, filters=None, variables=None): string = handle_vars(string, variables) obj, match_end = ColorMod(fullmatch).adjust(string, start) if obj is not None: - return ColorMatch(obj._color, start, end if end is not None else match_end) + return ColorMatch(obj._space, start, end if end is not None else match_end) else: filters = set(filters) if filters is not None else set() obj = None @@ -605,17 +607,22 @@ def match(cls, string, start=0, fullmatch=False, *, filters=None, variables=None obj.color = cls(obj.color.space(), obj.color.coords(), obj.color.alpha) return obj - @classmethod - def new(cls, color, data=None, alpha=util.DEF_ALPHA, *, filters=None, variables=None, **kwargs): + def new(self, color, data=None, alpha=util.DEF_ALPHA, *, filters=None, variables=None, **kwargs): """Create new color object.""" - return cls(color, data, alpha, filters=filters, variables=variables, **kwargs) + return type(self)(color, data, alpha, filters=filters, variables=variables, **kwargs) def update(self, color, data=None, alpha=util.DEF_ALPHA, *, filters=None, variables=None, **kwargs): """Update the existing color space with the provided color.""" + clone = self.clone() obj = self._parse(color, data, alpha, filters=filters, variables=variables, **kwargs) - self._color.update(obj) + clone._attach(obj) + + if clone.space() != self.space(): + clone.convert(self.space(), in_place=True) + + self._attach(clone._space) return self def mutate(self, color, data=None, alpha=util.DEF_ALPHA, *, filters=None, variables=None, **kwargs): diff --git a/lib/tmtheme.py b/lib/tmtheme.py index b31d842..b327a71 100644 --- a/lib/tmtheme.py +++ b/lib/tmtheme.py @@ -1,11 +1,12 @@ """Custom color that looks for colors of format `#RRGGBBAA` as `#AARRGGBB`.""" -from mdpopups.coloraide.css.colors import Color, SRGB -from mdpopups.coloraide.colors import _parse as parse +from mdpopups.coloraide import Color +from mdpopups.coloraide.spaces.srgb.css import SRGB +from mdpopups.coloraide.spaces import _parse from mdpopups.coloraide import util import copy import re -RE_COMPRESS = re.compile(r'(?i)^#({hex})\1({hex})\2({hex})\3(?:({hex})\4)?$'.format(**parse.COLOR_PARTS)) +RE_COMPRESS = re.compile(r'(?i)^#({hex})\1({hex})\2({hex})\3(?:({hex})\4)?$'.format(**_parse.COLOR_PARTS)) name2hex_map = { "black": "#000000", @@ -691,11 +692,11 @@ class SRGBX11(SRGB): # Names \b(?