HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduledoclayout-0.4.0.1Haskell2010

Text.DocLayout

A prettyprinting library for the production of text documents, including wrapped text, indentation and other prefixes, and blocks for tables.

  • 1 type
  • 1 class
  • 50 values
  • Packagedoclayout-0.4.0.1
  • Exports52
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceDocLayout.hs

Rendering

1 declaration
valuerender :: HasChars a => Maybe Int -> Doc a -> a
#

Render a Doc. render (Just n) will use a line length of n to reflow text on breakable spaces. render Nothing will not reflow text.

Doc constructors

27 declarations
valuecr :: Doc a
#

A carriage return. Does nothing if we're at the beginning of a line; otherwise inserts a newline.

valueblankline :: Doc a
#

Inserts a blank line unless one exists already. (blankline <> blankline has the same effect as blankline.

valueblanklines :: Int -> Doc a
#

Inserts blank lines unless they exist already. (blanklines m <> blanklines n has the same effect as blanklines (max m n).

valuespace :: Doc a
#

A breaking (reflowable) space.

valueprefixed :: IsString a => String -> Doc a -> Doc a
#

Uses the specified string as a prefix for every line of the inside document (except the first, if not at the beginning of the line).

valueflush :: Doc a -> Doc a
#

Makes a Doc flush against the left margin.

valuehang :: IsString a => Int -> Doc a -> Doc a -> Doc a
#

A hanging indent. hang ind start doc prints start, then doc, leaving an indent of ind spaces on every line but the first.

valuebeforeNonBlank :: Doc a -> Doc a
#

beforeNonBlank d conditionally includes d unless it is followed by blank space.

valueafterBreak :: Text -> Doc a
#

Content to print only if it comes at the beginning of a line, to be used e.g. for escaping line-initial . in roff man.

valuelblock :: HasChars a => Int -> Doc a -> Doc a
#

lblock n d is a block of width n characters, with text derived from d and aligned to the left.

valuevfill :: HasChars a => a -> Doc a
#

An expandable border that, when placed next to a box, expands to the height of the box. Strings cycle through the list provided.

valuechomp :: Doc a -> Doc a
#

Chomps trailing blank space off of a Doc.

Functions for concatenating documents

7 declarations
value(<+>) :: Doc a -> Doc a -> Doc a
#

Concatenate a list of Docs, putting breakable spaces between them.

value($$) :: Doc a -> Doc a -> Doc a
#

a $$ b puts a above b.

value($+$) :: Doc a -> Doc a -> Doc a
#

a $+$ b puts a above b, with a blank line between.

valuehcat :: [Doc a] -> Doc a
#

Concatenate documents horizontally.

valuehsep :: [Doc a] -> Doc a
#

Same as hcat, but putting breakable spaces between the Docs.

Functions for querying documents

11 declarations
valueupdateColumn :: HasChars a => Doc a -> Int -> Int
#

Returns the column that would be occupied by the last laid out character (assuming no wrapping).

valuecharWidth :: Char -> Int
#

Returns width of a character in a monospace font: 0 for a combining character, 1 for a regular character, 2 for an East Asian wide character. Ambiguous characters are treated as width 1.

valuerealLength :: HasChars a => a -> Int
#

Get real length of string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 1.

valuerealLengthNarrowContext :: HasChars a => a -> Int
#

Get the real length of a string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 1.

valuerealLengthWideContext :: HasChars a => a -> Int
#

Get the real length of a string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 2.

Char properties

3 declarations
valueisZWJ :: Char -> Bool
#

Checks whether a character is a zero-width joiner.

Utility functions

1 declaration

Types

2 declarations
datadata Doc a
#

Document, including structure relevant for layout.

Constructors

  • Text Int a

    Text with specified width.

  • Block Int [a]

    A block with a width and lines.

  • VFill Int a

    A vertically expandable block; when concatenated with a block, expands to height of block, with each line containing the specified text.

  • Prefixed Text (Doc a)

    Doc with each line prefixed with text. Note that trailing blanks are omitted from the prefix when the line after it is empty.

  • BeforeNonBlank (Doc a)

    Doc that renders only before nonblank.

  • Flush (Doc a)

    Doc laid out flush to left margin.

  • BreakingSpace

    A space or line break, in context.

  • AfterBreak Text

    Text printed only at start of line.

  • CarriageReturn

    Newline unless we're at start of line.

  • NewLine

    newline.

  • BlankLines Int

    Ensure a number of blank lines.

  • Concat (Doc a) (Doc a)

    Two documents concatenated.

  • Empty
Instances13Functor, Foldable, Traversable, Eq, Data, Ord, …
classclass (IsString a, Semigroup a, Monoid a, Show a) => HasChars a where
#

Class abstracting over various string types that can fold over characters. Minimal definition is foldrChar and foldlChar, but defining the other methods can give better performance.

Methods

Instances3HasChars