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

ANSI Codes in output (e.g. from sphinx gallery) #9

Open
robintibor opened this issue Jun 24, 2021 · 2 comments
Open

ANSI Codes in output (e.g. from sphinx gallery) #9

robintibor opened this issue Jun 24, 2021 · 2 comments

Comments

@robintibor
Copy link

robintibor commented Jun 24, 2021

Hopefully this is a reasonable place to ask this question:

I have some program that has terminal output with ANSI color codes that nicely display color in the terminal, but will show the literal ANSI codes in the HTML output unfortunately.
As a simple example, let's say I have some python file like this:

# -*- coding: utf-8 -*-
"""
Plot The Marvelous Colors
=========================

"""

print('\033[94m' + "hi" + '\033[0m')

then in doc after building with sphinx gallery unfortunately I get this:

�[94mhis�[0m

This can also be seen in the second-last cell here:
https://braindecode.org/auto_examples/plot_bcic_iv_2a_moabb_trial.html

Is this something that this package would try to handle? Or do you know where else I might ask?

@jenisys
Copy link
Collaborator

jenisys commented Nov 6, 2022

sphinxcontrib.ansi currently only supports the basic 8 ANSI foreground and background colors.

It does not support the bright-colours, with colour codes from 90 .. 97 that is used in your example above: bright-blue (94). Internally, a KeyError exception is raised which probably causes sphinx to ignore the paragraph/directive processing.

WORKAROUND:
Use the BOLD annotation instead of the BRIGHT annotation, like: "\033[34;1m COLORED_BLUE \033[0" (if possible)

SEE ALSO:

@kdeldycke
Copy link

For this you can use my ANSI-capable Pygments lexer from the Click Extra project: https://kdeldycke.github.io/click-extra/sphinx.html#ansi-shell-sessions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants