pandoc-2.5: Conversion between markup formats

Copyright | Copyright (C) 2010-2018 John MacFarlane
License | GNU GPL, version 2 or above
Maintainer | John MacFarlane <jgm@berkeley.edu>
Stability | alpha
Portability | portable
Safe Haskell | None
Language | Haskell2010

Text.Pandoc.Pretty

Description

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

Synopsis

- data Doc
- render :: IsString a => Maybe Int -> Doc -> a
- cr :: Doc
- blankline :: Doc
- blanklines :: Int -> Doc
- space :: Doc
- text :: String -> Doc
- char :: Char -> Doc
- prefixed :: String -> Doc -> Doc
- flush :: Doc -> Doc
- nest :: Int -> Doc -> Doc
- hang :: Int -> Doc -> Doc -> Doc
- beforeNonBlank :: Doc -> Doc
- nowrap :: Doc -> Doc
- afterBreak :: String -> Doc
- offset :: Doc -> Int
- minOffset :: Doc -> Int
- height :: Doc -> Int
- lblock :: Int -> Doc -> Doc
- cblock :: Int -> Doc -> Doc
- rblock :: Int -> Doc -> Doc
- (<>) :: Semigroup a => a -> a -> a
- (<+>) :: Doc -> Doc -> Doc
- ($$) :: Doc -> Doc -> Doc
- ($+$) :: Doc -> Doc -> Doc
- isEmpty :: Doc -> Bool
- empty :: Doc
- cat :: [Doc] -> Doc
- hcat :: [Doc] -> Doc
- hsep :: [Doc] -> Doc
- vcat :: [Doc] -> Doc
- vsep :: [Doc] -> Doc
- nestle :: Doc -> Doc
- chomp :: Doc -> Doc
- inside :: Doc -> Doc -> Doc -> Doc
- braces :: Doc -> Doc
- brackets :: Doc -> Doc
- parens :: Doc -> Doc
- quotes :: Doc -> Doc
- doubleQuotes :: Doc -> Doc
- charWidth :: Char -> Int
- realLength :: String -> Int

# Documentation

data Doc Source #

Instances

Eq Doc Source # |
Instance details Defined in Text.Pandoc.Pretty Methods (==) :: Doc -> Doc -> Bool Source # (/=) :: Doc -> Doc -> Bool Source #
Show Doc Source # |
Instance details Defined in Text.Pandoc.Pretty Methods showsPrec :: Int -> Doc -> ShowS Source # show :: Doc -> String Source # showList :: [Doc] -> ShowS Source #
IsString Doc Source # |
Instance details Defined in Text.Pandoc.Pretty Methods fromString :: String -> Doc Source #
Semigroup Doc Source # |
Instance details Defined in Text.Pandoc.Pretty Methods (<>) :: Doc -> Doc -> Doc Source # sconcat :: NonEmpty Doc -> Doc Source # stimes :: Integral b => b -> Doc -> Doc Source #
Monoid Doc Source # |
Instance details Defined in Text.Pandoc.Pretty Methods mempty :: Doc Source # mappend :: Doc -> Doc -> Doc Source # mconcat :: [Doc] -> Doc Source #

render :: IsString a => Maybe Int -> Doc -> a Source #

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

cr :: Doc Source #

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

blankline :: Doc Source #

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

blanklines :: Int -> Doc Source #

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

space :: Doc Source #

A breaking (reflowable) space.

text :: String -> Doc Source #

A literal string.

char :: Char -> Doc Source #

A character.

prefixed :: String -> Doc -> Doc Source #

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).

flush :: Doc -> Doc Source #

Makes a `Doc` flush against the left margin.

nest :: Int -> Doc -> Doc Source #

Indents a `Doc` by the specified number of spaces.

hang :: Int -> Doc -> Doc -> Doc Source #

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

beforeNonBlank :: Doc -> Doc Source #

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

nowrap :: Doc -> Doc Source #

Makes a `Doc` non-reflowable.

afterBreak :: String -> Doc Source #

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.

offset :: Doc -> Int Source #

Returns the width of a `Doc`.

minOffset :: Doc -> Int Source #

Returns the minimal width of a `Doc` when reflowed at breakable spaces.

height :: Doc -> Int Source #

Returns the height of a block or other `Doc`.

lblock :: Int -> Doc -> Doc Source #

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

cblock :: Int -> Doc -> Doc Source #

Like `lblock` but aligned centered.

rblock :: Int -> Doc -> Doc Source #

Like `lblock` but aligned to the right.

(<>) :: Semigroup a => a -> a -> a infixr 6 Source #

An associative operation.

(<+>) :: Doc -> Doc -> Doc infixr 6 Source #

Concatenate a list of `Doc`s, putting breakable spaces between them.

($$) :: Doc -> Doc -> Doc infixr 5 Source #

`a $$ b` puts `a` above `b`.

($+$) :: Doc -> Doc -> Doc infixr 5 Source #

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

isEmpty :: Doc -> Bool Source #

True if the document is empty.

empty :: Doc Source #

The empty document.

cat :: [Doc] -> Doc Source #

Concatenate a list of `Doc`s.

hcat :: [Doc] -> Doc Source #

Same as `cat`.

hsep :: [Doc] -> Doc Source #

Same as `cat`, but putting breakable spaces between the `Doc`s.

vcat :: [Doc] -> Doc Source #

List version of `$$`.

vsep :: [Doc] -> Doc Source #

List version of `$+$`.

nestle :: Doc -> Doc Source #

Removes leading blank lines from a `Doc`.

chomp :: Doc -> Doc Source #

Chomps trailing blank space off of a `Doc`.

inside :: Doc -> Doc -> Doc -> Doc Source #

Encloses a `Doc` inside a start and end `Doc`.

braces :: Doc -> Doc Source #

Puts a `Doc` in curly braces.

brackets :: Doc -> Doc Source #

Puts a `Doc` in square brackets.

parens :: Doc -> Doc Source #

Puts a `Doc` in parentheses.

quotes :: Doc -> Doc Source #

Wraps a `Doc` in single quotes.

doubleQuotes :: Doc -> Doc Source #

Wraps a `Doc` in double quotes.

charWidth :: Char -> Int Source #

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.

realLength :: String -> Int Source #

Get real length of string, taking into account combining and double-wide characters.