the-sett / elm-pretty-printer / Pretty.Renderer

Pretty.Renderer lets you specify custom rendering functions to modify the output of the pretty printer as it is layed out. You do not need to use this module for the default monochrome text only rendering which can be achieved with Pretty.pretty.

If you have a tagged Doc model, you can use the tags to do syntax highlighting with a custom Renderer. You can also turn the output into other structured forms such as HTML.

pretty : Basics.Int -> Renderer t a b -> Internals.Doc t -> b

Pretty prints a document trying to fit it as best as possible to the specified column width of the page.

A custom Renderer must be specified to handle the different parts of the output.


type alias Renderer t a b =
{ init : a
, tagged : t -> String -> a -> a
, untagged : String -> a -> a
, newline : a -> a
, outer : a -> b 
}

A custom Renderer.

This works a bit like a foldl operation. Note that the text being rendered is folded left to right, which means if you accumulate intermediate results into Lists, you will need to reverse them.