-
Notifications
You must be signed in to change notification settings - Fork 4
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
AnsiHtmlFormatter
and ANSI-aware shell-like lexers
#33
Comments
Thanks for the contributions! The # current code
from pygments.formatters import HtmlFormatter
from pygments_ansi_color import ExtendedColorHtmlFormatterMixin
class MyFormatter(ExtendedColorHtmlFormatterMixin, HtmlFormatter):
pass
_my_formatter = MyFormatter(
noclasses=False,
linespans='line',
style=MY_STYLE,
) to simply # new code
from pygments_ansi_color import AnsiHtmlFormatter
_my_formatter = AnsiHtmlFormatter(
noclasses=False,
linespans='line',
style=MY_STYLE,
) Is that right? The additional lexers feel like they may be too tied to your specific use-case and not the best fit here, although maybe I'm not fully understanding their purpose. |
Yes. But even better, you wouldn't have to defined you own style, and just pass one of Pygments' default: import pygments
from pygments_ansi_color import AnsiHtmlFormatter
_my_formatter = AnsiHtmlFormatter(
noclasses=False,
linespans='line',
style="xcode",
) The magic of |
As for the additional lexers, yes, they're a little bit cumbersome and hard to maintain. I can understand they're not fit for the The reason for these lexers is that some default lexers available in Pygments allow a mix of command lines and terminal output. That is the case of What I propose with my new custom lexers are an ANSI-capable variant, which are the same exact copy of the original from Pygments. But parse the sections that are supposed to be console output (i.e. encapsulated by I've implemented a working exemple in my Click Extra project: https://kdeldycke.github.io/click-extra/pygments.html#lexers . See there how the Python console |
Yeah, I think this is more than I'd like to include in this package, I would like to keep this mainly to the existing lexer. Happy to merge the |
Yeah, makes sense. I'll keep my extra ANSI-capable language lexers in my own project then. BTW, do you mind if I had a little explanation at the end of the read me of
OK, working on an PR then. |
After a year of usage in my Click Extra project and lots of pain trying to integrate it with Click, Sphinx and Furo, I finally reached a point where my stack of monkey-patch work as intended and validates my efforts.
So now I'm wondering if there are some stuff worth contributing back to
pygments-ansi-color
. Namely:AnsiHtmlFormatter
: which automatically patch the user-provided style with custom style so you do not have to perform thecolor_tokens
dance.A collection of shell-like lexers capable of rendering ANSI codes in
Generic.Output
.The text was updated successfully, but these errors were encountered: