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

pretty-print to multiple targets including colored strings and html #38

Open
mio-19 opened this issue Aug 31, 2024 · 2 comments
Open

pretty-print to multiple targets including colored strings and html #38

mio-19 opened this issue Aug 31, 2024 · 2 comments

Comments

@mio-19
Copy link

mio-19 commented Aug 31, 2024

I would like to pretty print in various formats such as colored strings (fansi.Str), HTML and LaTeX. It would be ideal if there is an API available that allows me to reuse existing pretty print logic while only needing to customize the output formatting.

@mio-19
Copy link
Author

mio-19 commented Sep 5, 2024

@inkytonik
Copy link
Owner

As you note, the library is designed to output text. It's not in the spirit of the approach to change the library to output different forms of text (HTML etc).

In projects where I have wanted to output "the same thing" in multiple text formats (say, JSON, XML, HTML, etc) I have done it by making an interface that takes the things I want to pretty-print. Then multiple implementations of that interface define pretty-printers for the different textual formats that I want. Then I can switch formats by just choosing which pretty-printer implementation I use.

In my experience, this is a good way to do it since you get to control the formatting of the different formats using the high-level pretty-printing constructs (eg laying out JSON is different to laying out HTML). You want to have control of that at the high level, not at the low level of the output text.

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

No branches or pull requests

2 participants