[Haskell-cafe] Request for a Simple Pretty Printing library

Tomasz Zielonka tomasz.zielonka at gmail.com
Wed Dec 13 16:31:21 EST 2006

On Wed, Dec 13, 2006 at 08:58:25PM +0000, Neil Mitchell wrote:
> I've been using the HughesPJ pretty printing library, but I need a new
> combinator:
> wrap :: String -> Doc -> String -> Doc
> wrap prepend doc append = ...
> The semantics of this would be that the text is prepended and appended
> to the doc when rendered, but does not alter the pretty printing at
> all. The idea of this is to support printing with HTML rendering:
> wrap "<span class='keyword'>" (text "case") "</span>"
> The HughesPJ library is 1000 lines long, so will be quite a lot of
> work to change this to get it working properly.

I am not sure it will work, but it's sufficiently easy to try.
Look at the innards of HughesPJ, especially the TextBeside data
constructor. Its second parameter is an Int holding the length
of the text. Perhaps if you created TextBeside with your HTML
markup, but with 0 length field, things would be laid out properly.

Something like:

wrap prepend doc append =
    zeroText prepend <> doc <> zeroText append
zeroText s = textBeside_ (Str s) 0 Empty

Best regards

More information about the Haskell-Cafe mailing list