ansi-to-html
ansi-to-html copied to clipboard
Add option to display spaces
Hi, I know html does not take into account spaces in text, but sometimes ansi text only displays correctly when we include spaces. I needed to display log info in html, so I added a 'spaces' option that replaces spaces with 'span' tags that have a width of 0.6em. Implementation is pretty easy, but it's also pretty much hacking, which is why I'm not doing a pull request. But do you think that may be a good feature ? And would there be a better way to do it?
@the-duck having a toggle to preserve spaces seems reasonable. maybe outputting it as an html entity (` ') is a better option than a span element.
It's related to the existing configuration option for preserving newlines. (https://github.com/rburns/ansi-to-html/blob/master/README.md#options) It would be tempting to preserve spaces and newlines in one config key. Though, the newlines
key behaviour would need to be unchanged for compatibility.
Possibly the existing newlines
key and an additional spaces
key. or alternatively the existing newlines
key and an additional whitespace
key that does both. Not certain which would be most useful.
Or how about newlines
, spaces
, and a setting whitespace
that does both?
Just in case one wishes XML support,  
would be a little safer than
which may only be supported in HTML (HTML supports either).
Am eager to have an option to auto-generate CLI docs (using command-line-usage
), and preserving spacing is critical for this. But your tool otherwise looks to be doing the job quite nicely!
Either of those solutions are likely fine. (three config keys, or two). I struggle to imagine a scenario where you would want spaces preserved, but not newlines, or the opposite.
I guess a whitespace key would have to take into account not only spaces and newlines, but also other whitespace characters like tabs.
Makes me think newlines
and whitespace
would be enough. For example, adding a tabs
key in addition to newlines
and spaces
wouldn't make a lot of sense.
In my PR #57 , I've just added a tabs
option as well, as I do think it's utility as a separate preference can be in using it to indicate the number of non-breaking spaces that each tab should be converted into.
Though of course whatever API you prefer--just demoing the idea...