doclayout

A prettyprinting library for laying out text documents.

https://github.com/jgm/doclayout

Version on this page:0.3
LTS Haskell 22.14:0.4.0.1
Stackage Nightly 2024-03-28:0.4.0.1
Latest on Hackage:0.4.0.1

See all snapshots doclayout appears in

BSD-3-Clause licensed by John MacFarlane
Maintained by [email protected]
This version can be pinned in stack with:doclayout-0.3@sha256:06c03875b1645e6ab835c40f9b73fd959b6c4232c01d06f07debedfae46723f2,2059

Module documentation for 0.3

Depends on 4 packages(full list with versions):
Used by 2 packages in nightly-2020-11-17(full list with versions):

doclayout

CI tests

This is a prettyprinting library designed for laying out plain-text documents. It originated in the pandoc module Text.Pandoc.Pretty, and its development has been guided by pandoc’s needs in rendering wrapped textual documents.

In supports wrapping of text on breaking spaces, indentation and other line prefixes, blank lines, and tabular content.

Example:

Text.DocLayout> mydoc = hang 2 "- " (text "foo" <+> text "bar")
Text.DocLayout> putStrLn $ render (Just 20) mydoc
- foo bar
Text.DocLayout> putStrLn $ render (Just 10) (prefixed "> " (mydoc $+$ mydoc))
> - foo
>   bar
>
> - foo
>   bar

The Doc type may be parameterized to either String or (strict or lazy) Text, depending on the desired render target.

Changes

doclayout

0.3

  • Add foldlChar to signature of HasChars [API change].
  • Use foldlChar in realLength. This avoids a stack overflow we were getting with long strings in the previous version (with foldrChar). See jgm/pandoc#6031.
  • Replace isBlank with isBreakable and improved startsWithBlank. Previously isBlank was used in the layout algorithm where what we really wanted was isBreakable.
  • Avoid unnecessary calculation in updateColumns.
  • Replace a right fold with a strict left fold.
  • Add strictness annotations in realLength and updateColumn.

0.2.0.1

  • Made realLength smarter about combining characters. If a string starts with a combining character, that character takes up a width of 1; if the combining character occurs after another character, it takes 0. See jgm/pandoc#5863.
  • Improve isBlank, re-use in rendering code for BreakingSpace.
  • Fixed incorrect Text width in renderig blocks.

0.2

  • Add instances for Doc: Data, Typeable, Ord, Read, Generic.
  • Add literal (like text, but polymorphic).
  • Change some IsString constraints to HasChars.
  • Add some default definitions for methods in HasChars.
  • Change offset and minOffset to be more efficient (in simple cases they no longer render and count line lengths).
  • Add updateColumn.
  • Fix problem with lblock/cblock/rblock when chop is invoked. This caused very strange behavior in which text got reversed in certain circumstances.

0.1

  • Initial release.