From 9d44d9a17ec7fa67ded43c0977cdd3be61d96794 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Wed, 30 Dec 2020 10:11:34 -0600 Subject: [PATCH] Revert a private API in the HTML formatter (#1655) This should revert the behavior of the function without losing the overall caching behavior that was intended. Closes #1644 --- pygments/formatters/html.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index e49b88cd6f..de9aa13300 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -457,20 +457,20 @@ def _get_css_class(self, ttype): return '' def _get_css_classes(self, ttype): - """Generate the opening tag for a given token type using CSS classes.""" + """Return the CSS classes of this token type prefixed with the classprefix option.""" cls = self._get_css_class(ttype) while ttype not in STANDARD_TYPES: ttype = ttype.parent cls = self._get_css_class(ttype) + ' ' + cls - return cls and '' % cls or '' + return cls or '' def _get_css_inline_styles(self, ttype): - """Generate the opening tag for a given token type using inline CSS styles.""" + """Return the inline CSS styles for this token type.""" cclass = self.ttype2class.get(ttype) while cclass is None: ttype = ttype.parent cclass = self.ttype2class.get(ttype) - return cclass and '' % self.class2style[cclass][0] or '' + return cclass or '' def _create_stylesheet(self): t2c = self.ttype2class = {Token: ''} @@ -816,9 +816,12 @@ def _format_lines(self, tokensource): cspan = self.span_element_openers[ttype] except KeyError: if nocls: - cspan = self.span_element_openers[ttype] = self._get_css_inline_styles(ttype) + css_style = self._get_css_inline_styles(ttype) + cspan = css_style and '' % self.class2style[css_style][0] or '' else: - cspan = self.span_element_openers[ttype] = self._get_css_classes(ttype) + css_class = self._get_css_classes(ttype) + cspan = css_class and '' % css_class or '' + self.span_element_openers[ttype] = cspan parts = self._translate_parts(value)