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

Added groff formatter #1873

Merged
merged 1 commit into from
Nov 21, 2021
Merged

Added groff formatter #1873

merged 1 commit into from
Nov 21, 2021

Conversation

marcinzelent
Copy link
Contributor

This is a formatter that can output the source code in a form that can be used with GNU Troff (groff).

Groff is a typesetting system that has its roots in some of the oldest text formatting software out there. It can be used to create formatted documents, papers, books, etc. It is similar to LaTeX in that sense but much more minimal and older. Nowadays, it's mostly used for creation of man manual pages.

This formatter is using groff escapes to change the color and font style (regular, bold, italic) of the text. It also has a few options that allow the user to print the source code with line numbers and wrap it to a specified width. By default, the output is using a monospace font but it can be disabled too. Some special characters that are used by groff are replaced by escapes for printing Unicode characters. The same applies for non-ASCII characters, which groff can't print. The formatter isn't using any macro specific commands, so it should work with all of them (ms, mom, man, etc.).

I tested the formatter thoroughly using various source code files of my own and the ones available in the tests/examplefiles directory. I also used different combinations of options to make sure they don't conflict with each other. I didn't notice any issues. The only time when the output might look different than expected is when input contains characters that groff doesn't support (possibly to the lack of them in the default font). It will then give a warning that it cannot find the character and won't print it.

To test it yourself, you can use the following command:

pygmentize -f groff <input> | groff -Tpdf > output.pdf

It is my first contribution to the project and I'm not programming in Python that often, so I'm open to comments and feedback.

@Anteru Anteru merged commit ed4bc19 into pygments:master Nov 21, 2021
@Anteru Anteru added this to the 2.11.0 milestone Nov 21, 2021
@Anteru
Copy link
Collaborator

Anteru commented Nov 21, 2021

That works quite nicely. Thanks a lot for your contribution!

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