diff options
author | Sylvain Corlay <sylvain.corlay@gmail.com> | 2019-05-02 00:05:47 +0200 |
---|---|---|
committer | Sylvain Corlay <sylvain.corlay@gmail.com> | 2019-05-02 00:05:47 +0200 |
commit | 8f733ca887f216cdcf1b1e5f9b70954811bcfc17 (patch) | |
tree | e03bebbb3a9d5e0b4fde177c8c4900770150e3e2 /pygments/formatters | |
parent | 249e5feec73189cfff3a4c81d6a6c9fc821286cd (diff) | |
download | pygments-8f733ca887f216cdcf1b1e5f9b70954811bcfc17.tar.gz |
Allow for CSS variable in pygments stylesheets
Diffstat (limited to 'pygments/formatters')
-rw-r--r-- | pygments/formatters/html.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index 7d7605eb..bbddf507 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -41,6 +41,11 @@ def escape_html(text, table=_escape_html_table): """Escape &, <, > as well as single and double quotes for HTML.""" return text.translate(table) +def webify(color): + if color.startswith('calc') or color.startswith('var'): + return color + else: + return '#' + color def _get_ttype_class(ttype): fname = STANDARD_TYPES.get(ttype) @@ -451,7 +456,7 @@ class HtmlFormatter(Formatter): name = self._get_css_class(ttype) style = '' if ndef['color']: - style += 'color: #%s; ' % ndef['color'] + style += 'color: %s; ' % webify(ndef['color']) if ndef['bold']: style += 'font-weight: bold; ' if ndef['italic']: @@ -459,9 +464,9 @@ class HtmlFormatter(Formatter): if ndef['underline']: style += 'text-decoration: underline; ' if ndef['bgcolor']: - style += 'background-color: #%s; ' % ndef['bgcolor'] + style += 'background-color: %s; ' % webify(ndef['bgcolor']) if ndef['border']: - style += 'border: 1px solid #%s; ' % ndef['border'] + style += 'border: 1px solid %s; ' % webify(ndef['border']) if style: t2c[ttype] = name # save len(ttype) to enable ordering the styles by |