pradyunsg / furo

A clean customizable documentation theme for Sphinx
https://pradyunsg.me/furo/quickstart
MIT License
2.65k stars 304 forks source link

Use the reference `HtmlFormatter` class defined on `PygmentsBridge` #657

Closed kdeldycke closed 1 year ago

kdeldycke commented 1 year ago

This patch respect the HtmlFormatter class set on PygmentsBridge, instead of hard-coding it into Furo. That way Furo can use the same Pygments formatter as the whole Sphinx machinery.

For the context, I encountered this issue while trying to implement a way for Pygments to render ANSI codes in documentation.

kdeldycke commented 1 year ago

And for those interested in the details of my implementation, I have a custom AnsiHtmlFormatter, which inherits from Pygments.HtmlFormatter and ExtendedColorHtmlFormatterMixin from the pygments_ansi_color project.

This custom formatter allow me to render ANSI codes in Sphinx code blocks. See for instance the ANSI color matrix at: https://kdeldycke.github.io/click-extra/colorize.html#colors-and-styles

And because of Furo's hard-coded reference to HtmlFormatter, I cannot simply set PygmentsBridge.html_formatter and expect Furo to use my custom formatter.

In the mean time, I monkey-patched Furo at: https://github.com/kdeldycke/click-extra/blob/115d6a879accf66a4ff71f81cf5693373d79aa3a/click_extra/sphinx.py#L152-L166

pradyunsg commented 1 year ago

Thanks for those details! This seems OK. :)

kdeldycke commented 1 year ago

Thanks @pradyunsg for the quick merge! 🎉