Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert a private API in the HTML formatter #1655

Merged
merged 1 commit into from Dec 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions pygments/formatters/html.py
Expand Up @@ -457,20 +457,20 @@ def _get_css_class(self, ttype):
return ''

def _get_css_classes(self, ttype):
"""Generate the opening <span> 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 '<span class="%s">' % cls or ''
return cls or ''

def _get_css_inline_styles(self, ttype):
"""Generate the opening <span> 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 '<span style="%s">' % self.class2style[cclass][0] or ''
return cclass or ''

def _create_stylesheet(self):
t2c = self.ttype2class = {Token: ''}
Expand Down Expand Up @@ -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 '<span style="%s">' % 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 '<span class="%s">' % css_class or ''
self.span_element_openers[ttype] = cspan

parts = self._translate_parts(value)

Expand Down