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.
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 declarationDoc constructors
27 declarationsA carriage return. Does nothing if we're at the beginning of a line; otherwise inserts a newline.
Inserts a blank line unless one exists already.
(blankline <> blankline has the same effect as blankline.
Inserts blank lines unless they exist already.
(blanklines m <> blanklines n has the same effect as blanklines (max m n).
A breaking (reflowable) space.
Create a Doc from a stringlike value.
A literal string. (Like literal, but restricted to String.)
A character.
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).
Makes a Doc flush against the left margin.
Indents a Doc by the specified number of spaces.
A hanging indent. hang ind start doc prints start,
then doc, leaving an indent of ind spaces on every
line but the first.
beforeNonBlank d conditionally includes d unless it is
followed by blank space.
Makes a Doc non-reflowable.
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.
lblock n d is a block of width n characters, with
text derived from d and aligned to the left.
Like lblock but aligned centered.
Like lblock but aligned to the right.
An expandable border that, when placed next to a box, expands to the height of the box. Strings cycle through the list provided.
Removes leading blank lines from a Doc.
Chomps trailing blank space off of a Doc.
Puts a Doc in curly braces.
Puts a Doc in square brackets.
Puts a Doc in parentheses.
Wraps a Doc in single quotes.
Wraps a Doc in double quotes.
The empty document.
Functions for concatenating documents
7 declarationsConcatenate a list of Docs, putting breakable spaces between them.
a $$ b puts a above b.
a $+$ b puts a above b, with a blank line between.
Concatenate documents horizontally.
List version of $$.
List version of $+$.
Functions for querying documents
11 declarationsTrue if the document is empty.
Returns the width of a Doc.
Returns the minimal width of a Doc when reflowed at breakable spaces.
Returns the column that would be occupied by the last laid out character (assuming no wrapping).
Returns the height of a block or other Doc.
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.
Get real length of string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 1.
Get the real length of a string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 1.
Get the real length of a string, taking into account combining and double-wide characters. Ambiguous characters are treated as width 2.
Like realLengthNarrowContext, but avoids optimizations (shortcuts). This is exposed for testing, to ensure that the optimizations are safe.
Like realLengthWideContext, but avoids optimizations (shortcuts). This is exposed for testing, to ensure that the optimizations are safe.
Char properties
3 declarationsChecks whether a character is a skin tone modifier.
Checks whether a character is an emoji variation modifier.
Checks whether a character is a zero-width joiner.
Utility functions
1 declarationUnfold a Doc into a flat list.
Types
2 declarationsDocument, including structure relevant for layout.
Constructors
Text Int aText with specified width.
Block Int [a]A block with a width and lines.
VFill Int aA 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.
BreakingSpaceA space or line break, in context.
AfterBreak TextText printed only at start of line.
CarriageReturnNewline unless we're at start of line.
NewLinenewline.
BlankLines IntEnsure a number of blank lines.
Concat (Doc a) (Doc a)Two documents concatenated.
Empty
Instances13Functor, Foldable, Traversable, Eq, Data, Ord, …
Functor DocDefined in doclayout-0.4.0.1 · Text.DocLayoutFoldable DocDefined in doclayout-0.4.0.1 · Text.DocLayoutTraversable DocDefined in doclayout-0.4.0.1 · Text.DocLayoutEq a => Eq (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutData a => Data (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutOrd a => Ord (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutRead a => Read (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutShow a => Show (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutHasChars a => IsString (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutGeneric (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutSemigroup (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayoutMonoid (Doc a)Defined in doclayout-0.4.0.1 · Text.DocLayouttype Rep (Doc a) = D1 ('MetaDataDefined in doclayout-0.4.0.1 · Text.DocLayout"Doc"
"Text.DocLayout"
"doclayout-0.4.0.1-ERgdHJuGUYz6fwTjyJ4DFi"
'False) (((C1 ('MetaCons"Text"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: (C1 ('MetaCons"Block"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])) :+: C1 ('MetaCons"VFill"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))) :+: (C1 ('MetaCons"Prefixed"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a))) :+: (C1 ('MetaCons"BeforeNonBlank"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a))) :+: C1 ('MetaCons"Flush"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a)))))) :+: ((C1 ('MetaCons"BreakingSpace"
'PrefixI 'False) U1 :+: (C1 ('MetaCons"AfterBreak"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons"CarriageReturn"
'PrefixI 'False) U1)) :+: ((C1 ('MetaCons"NewLine"
'PrefixI 'False) U1 :+: C1 ('MetaCons"BlankLines"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))) :+: (C1 ('MetaCons"Concat"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a)) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a))) :+: C1 ('MetaCons"Empty"
'PrefixI 'False) U1))))
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
foldrChar :: (Char -> b -> b) -> b -> a -> bfoldlChar :: (b -> Char -> b) -> b -> a -> breplicateChar :: Int -> Char -> aisNull :: a -> BoolsplitLines :: a -> [a]