1. Georg Brandl
  2. sphinx-contrib
Issue #40 new

sphinxcontrib-ansi: Better/more robust handling for unknown/unsupported color codes

jenisys
created an issue

If sphinxcontrib-ansi encounters an unknown color code, it crashes. This is not a very desirable behavior.

EXAMPLE:

ESC[90m             #< Use bright grey color, same with codes: 90..97

A better strategy would be to use the color-class "ansi-unknown" for unknown/unsupported color codes. An additional style should be added to CSS stylesheet. A developer could than modify the style with "color: red" to detect if any problems exist. Per default, a "color: black" (or something like that) should be used.

def _colorize_block_contents(self, block):
    ...
    for code in codes:
        # XXX-JE-PATCH: Use "ansi-unknown" for unknown/unsupported codes.
        code_class = CODE_CLASS_MAP.get(code, 'unknown')
        code_node['classes'].append('ansi-%s' % code_class)
        # XXX-ORIG: code_node['classes'].append(
        # XXX-ORIG: 'ansi-%s' % CODE_CLASS_MAP[code])
        # XXX-JE-PATCH-END

SEE ALSO:

Comments (0)

  1. Log in to comment