summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Bussonnier <bussonniermatthias@gmail.com>2016-02-08 13:25:00 -0800
committerMatthias Bussonnier <bussonniermatthias@gmail.com>2016-02-08 13:25:00 -0800
commit342fc93725ce00442e835b02218e232b1dd05b1e (patch)
tree056fd0e4d547175eaa66b498691bf344dbd2a8b9
parent86939c3764a93a9cd40cff29406d4d4f1ebd9c1c (diff)
downloadpygments-342fc93725ce00442e835b02218e232b1dd05b1e.tar.gz
Handle some `#ansi*` in HtmlFormatter
-rw-r--r--doc/docs/styles.rst8
-rw-r--r--pygments/formatters/html.py21
2 files changed, 25 insertions, 4 deletions
diff --git a/doc/docs/styles.rst b/doc/docs/styles.rst
index 13326129..baf18113 100644
--- a/doc/docs/styles.rst
+++ b/doc/docs/styles.rst
@@ -182,5 +182,9 @@ foreground color.
>>> print(result.encode())
b'print(\x1b[34;01m"\x1b[39m\x1b[34;01mHello World\x1b[39m\x1b[34;01m"\x1b[39m)\n'
-Style that use `#ansi*` foreground colors do not currently work with formatters
-others than ``Terminal256``.
+Style that use `#ansi*` foreground colors might not correctly work with
+formatters others than ``Terminal256``. `HtmlFormatter` is capable of handling
+some `#ansi*` code and will map to the corresponding HTML/CSS color. That is to
+say, `#ansiblue` will be converted to `color:blue` , `#ansired` to `color:red`.
+The behavior is undefined for argument like `#ansireset`, `#ansiunderline`,
+`#ansibold`... etc.
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index b03a4bd5..38e49f15 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -20,6 +20,23 @@ from pygments.token import Token, Text, STANDARD_TYPES
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
StringIO, string_types, iteritems
+
+_deansify_map = {
+ '#darkyellow':'#brown',
+ '#darkteal': '#turquoise',
+ '#fusia': '#fushia'
+}
+
+
+
+def _deansify(color):
+ if color.startswith('#ansi'):
+ color = color[5:]
+ else:
+ color = '#%s'% color
+
+ return _deansify_map.get(color, color)
+
try:
import ctags
except ImportError:
@@ -444,7 +461,7 @@ class HtmlFormatter(Formatter):
name = self._get_css_class(ttype)
style = ''
if ndef['color']:
- style += 'color: #%s; ' % ndef['color']
+ style += 'color: %s; ' % _deansify(ndef['color'])
if ndef['bold']:
style += 'font-weight: bold; '
if ndef['italic']:
@@ -452,7 +469,7 @@ class HtmlFormatter(Formatter):
if ndef['underline']:
style += 'text-decoration: underline; '
if ndef['bgcolor']:
- style += 'background-color: #%s; ' % ndef['bgcolor']
+ style += 'background-color: %s; ' % _deansify(ndef['bgcolor'])
if ndef['border']:
style += 'border: 1px solid #%s; ' % ndef['border']
if style: