| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.Text.Prettyprint.Doc.Render.Text
Description
Render an unannotated SimpleDocStream as plain Text.
Synopsis
- renderLazy :: SimpleDocStream ann -> Text
- renderStrict :: SimpleDocStream ann -> Text
- renderIO :: Handle -> SimpleDocStream ann -> IO ()
- putDoc :: Doc ann -> IO ()
- hPutDoc :: Handle -> Doc ann -> IO ()
Conversion to plain Text
renderLazy :: SimpleDocStream ann -> Text Source #
( takes the output renderLazy sdoc)sdoc from a rendering function
and transforms it to lazy text.
>>>let render = TL.putStrLn . renderLazy . layoutPretty defaultLayoutOptions>>>let doc = "lorem" <+> align (vsep ["ipsum dolor", parens "foo bar", "sit amet"])>>>render doclorem ipsum dolor (foo bar) sit amet
renderStrict :: SimpleDocStream ann -> Text Source #
( takes the output renderStrict sdoc)sdoc from a rendering function
and transforms it to strict text.
Render to a Handle
renderIO :: Handle -> SimpleDocStream ann -> IO () Source #
( writes renderIO h sdoc)sdoc to the file h.
>>>renderIO System.IO.stdout (layoutPretty defaultLayoutOptions "hello\nworld")hello world
This function is more efficient than ,
since it writes to the handle directly, skipping the intermediate hPutStr h (renderStrict sdoc)Text
representation.
Convenience functions
putDoc :: Doc ann -> IO () Source #
( prettyprints document putDoc doc)doc to standard output. Uses the
defaultLayoutOptions.
>>>putDoc ("hello" <+> "world")hello world
putDoc=hPutDocstdout
hPutDoc :: Handle -> Doc ann -> IO () Source #
Like putDoc, but instead of using stdout, print to a user-provided
handle, e.g. a file or a socket. Uses the defaultLayoutOptions.
main =withFilefilename (h ->hPutDoch doc) where doc =vcat["vertical", "text"] filename = "someFile.txt"
hPutDoch doc =renderIOh (layoutPrettydefaultLayoutOptionsdoc)