Dodo
- Package
- purescript-dodo-printer
- Repository
- natefaubion/purescript-dodo-printer
#alignCurrentColumn Source
alignCurrentColumn :: forall a. Doc a -> Doc a
Increases the indentation level so that it aligns to the current column.
#withPosition Source
withPosition :: forall a. (Position -> Doc a) -> Doc a
Build a document based on the current layout position.
#spaceBreak Source
spaceBreak :: forall a. Doc a
Inserts a space when in a flex group, otherwise inserts a break.
#appendBreak Source
appendBreak :: forall a. Doc a -> Doc a -> Doc a
Appends two documents with a break between them.
#appendSpace Source
appendSpace :: forall a. Doc a -> Doc a -> Doc a
Appends two documents with a space between them.
#appendSpaceBreak Source
appendSpaceBreak :: forall a. Doc a -> Doc a -> Doc a
Appends two documents with a space between them, falling back to a break if that does not fit.
#flexSelect Source
flexSelect :: forall a. Doc a -> Doc a -> Doc a -> Doc a
Attempts to layout the first document with flex alternatives, falling back to defaults if it doesn't fit the page width. If the flex alternatives are used then the second document will be appended, otherwise the third document will be appended.
#textParagraph Source
textParagraph :: forall a. String -> Doc a
Constructs a wrapping paragraph from a blob of text. Ignores newlines and multiple spaces.
#foldWithSeparator Source
foldWithSeparator :: forall f a. Foldable f => Doc a -> f (Doc a) -> Doc a
Appends a series of documents together with a separator in between them.
#locally Source
locally :: forall a. (LocalOptions -> LocalOptions) -> Doc a -> Doc a
EXPERIMENTAL: modifies printing state and options locally for a document. This may change or be removed at any time.
#withLocalOptions Source
withLocalOptions :: forall a. (LocalOptions -> Tuple LocalOptions (Doc a)) -> Doc a
EXPERIMENTAL: modifies printing state and options locally for a document.
This may change or be removed at any time. Differs from locally
in that the
document can be responsive to options.
#print Source
print :: forall b a r. Printer b a r -> PrintOptions -> Doc a -> r
Prints a documents given a printer and print options.
print plainText twoSpaces myDoc
This will use full line-lookahead from the start of a flex group. If it encounters a break or content overflows the page-width, it will layout the group using flex alternative defaults instead.
#Printer Source
newtype Printer buff ann res
Custom printers can be used to render richer documents than just plain text.
emptyBuffer
- The initial buffer.writeText
- Should write a string with the given width to the buffer.writeIndent
- Should write indentation with the given width to the buffer.writeBreak
- Should write a line break to the buffer.enterAnnotation
- Called when entering a new annotated region. Provides the full annotation stack.leaveAnnotation
- Called when leaving an annotated region. Provides the full annotation stack.flushBuffer
- Called at the end of the document to get the final result.
Constructors
#PrintOptions Source
type PrintOptions = { indentUnit :: String, indentWidth :: Int, pageWidth :: Int, ribbonRatio :: Number }
Configuration options for the printer.
pageWidth
- The printer will try not to exceed this width on any given line.ribbonRatio
- Ratio between 0.0 and 1.0, defaults to 1.0. The printer will use this ratio to calculate the printable area between the current indentation level and thepageWidth
.indentUnit
- The string used for a single indent.indentWidth
- The assumed character width of a singleindentUnit
.
#twoSpaces Source
twoSpaces :: PrintOptions
Prints 2-space indents, with a default 80-column page width.
#fourSpaces Source
fourSpaces :: PrintOptions
Prints 4-space indents, with a default 120-column page width.
#tabs Source
tabs :: PrintOptions
Prints tab indents (4-wide), with a default 120-column page width.