summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Corlay <sylvain.corlay@gmail.com>2019-05-02 00:05:47 +0200
committerSylvain Corlay <sylvain.corlay@gmail.com>2019-05-02 00:05:47 +0200
commit8f733ca887f216cdcf1b1e5f9b70954811bcfc17 (patch)
treee03bebbb3a9d5e0b4fde177c8c4900770150e3e2
parent249e5feec73189cfff3a4c81d6a6c9fc821286cd (diff)
downloadpygments-8f733ca887f216cdcf1b1e5f9b70954811bcfc17.tar.gz
Allow for CSS variable in pygments stylesheets
-rw-r--r--pygments/formatters/html.py11
-rw-r--r--pygments/style.py4
2 files changed, 11 insertions, 4 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
diff --git a/pygments/style.py b/pygments/style.py
index 89766d8c..aee23f96 100644
--- a/pygments/style.py
+++ b/pygments/style.py
@@ -73,9 +73,11 @@ class StyleMeta(type):
if len(col) == 6:
return col
elif len(col) == 3:
- return col[0]*2 + col[1]*2 + col[2]*2
+ return col[0] * 2 + col[1] * 2 + col[2] * 2
elif text == '':
return ''
+ elif text.startswith('var') or text.startswith('calc'):
+ return text
assert False, "wrong color format %r" % text
_styles = obj._styles = {}