Add ability to specify custom Formatter for Pygments code highlighting#490
Add ability to specify custom Formatter for Pygments code highlighting#490dprothero wants to merge 2 commits intoPython-Markdown:masterfrom dprothero:custom-formatter
Conversation
|
I work with @dprothero. As front end design evolves, I'm sure we're not the only ones who could benefit from specifying custom formatters. Thanks for your maintenance of the project and for giving this PR a look! |
|
Cool! I like it. And I would merge this if we weren't in a feature freeze right now. We are only accepting bug fixes at this time. As we move toward version 3.0 (see the roadmap) the extensions will be broken out into separate packages and will no longer be tied to the development/release cycle of the main package. At that time these sorts of things won't hold up a good contribution like this. Unfortunately, until then, this will have to wait. Of course, in the meantime, you are welcome to fork the extension as long as you honor the licence. |
|
Oh, and before you ask, the timeline is "when it's done." |
|
That sounds totally fine to me! We'll just keep my fork in our requirements.txt until this all comes together. |
In our use of the Python-Markdown library, we discovered the need to be able to use a custom Pygments Formatter class. Pygments supports creating custom formatters, but there wasn't a way to have the
CodeHiliteExtensionutlize them.I've added
pygments_formatteras a config option for theCodeHiliteExtensionclass (which is also used byFencedCodeExtension). It can take a string, which will be passed to the call to Pygments'get_formatter_by_namefunction. It defaults to 'html', which is what was hard-coded before.Also, the option can take a reference to a class. This makes it convenient to specify a custom class in code without having to create a separate package for your custom formatter. Usage is something like this:
The last line of code demonstrates the usage.
All tests pass (aside from those marked as Skip), including the additional test I added. Let me know if you'd like any modifications.