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

Use the reference HtmlFormatter class defined on PygmentsBridge #657

Merged
merged 1 commit into from
May 15, 2023
Merged

Use the reference HtmlFormatter class defined on PygmentsBridge #657

merged 1 commit into from
May 15, 2023

Conversation

kdeldycke
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Owner

Thanks for those details! This seems OK. :)

@pradyunsg pradyunsg merged commit dd85574 into pradyunsg:main May 15, 2023
@kdeldycke
Copy link
Contributor Author

Thanks @pradyunsg for the quick merge! 🎉

@kdeldycke kdeldycke deleted the use-reference-html-formatter branch May 15, 2023 11:26
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

Successfully merging this pull request may close these issues.

2 participants