| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.Text.Prettyprint.Doc.Render.Util.SimpleDocTree
Description
Conversion of the linked-list-like SimpleDocStream to a tree-like
SimpleDocTree.
Synopsis
- data SimpleDocTree ann
- treeForm :: SimpleDocStream ann -> SimpleDocTree ann
- unAnnotateST :: SimpleDocTree ann -> SimpleDocTree xxx
- reAnnotateST :: (ann -> ann') -> SimpleDocTree ann -> SimpleDocTree ann'
- alterAnnotationsST :: (ann -> [ann']) -> SimpleDocTree ann -> SimpleDocTree ann'
- renderSimplyDecorated :: Monoid out => (Text -> out) -> (ann -> out -> out) -> SimpleDocTree ann -> out
- renderSimplyDecoratedA :: (Applicative f, Monoid out) => (Text -> f out) -> (ann -> f out -> f out) -> SimpleDocTree ann -> f out
Type and conversion
data SimpleDocTree ann Source #
A SimpleDocStream is a linked list of different annotated cons cells
(SText and then some further SimpleDocStream, SLine and then some
further SimpleDocStream, …). This format is very suitable as a target for a
layout engine, but not very useful for rendering to a structured format such
as HTML, where we don’t want to do a lookahead until the end of some markup.
These formats benefit from a tree-like structure that explicitly marks its
contents as annotated. SimpleDocTree is that format.
Constructors
| STEmpty | |
| STChar Char | |
| STText !Int Text | Some layout algorithms use the Since the frequently used |
| STLine !Int |
|
| STAnn ann (SimpleDocTree ann) | Annotate the contained document. |
| STConcat [SimpleDocTree ann] | Horizontal concatenation of multiple documents. |
Instances
treeForm :: SimpleDocStream ann -> SimpleDocTree ann Source #
Convert a SimpleDocStream to its SimpleDocTree representation.
Manipulating annotations
unAnnotateST :: SimpleDocTree ann -> SimpleDocTree xxx Source #
Remove all annotations. unAnnotate for SimpleDocTree.
reAnnotateST :: (ann -> ann') -> SimpleDocTree ann -> SimpleDocTree ann' Source #
Change the annotation of a document. reAnnotate for SimpleDocTree.
alterAnnotationsST :: (ann -> [ann']) -> SimpleDocTree ann -> SimpleDocTree ann' Source #
Change the annotation of a document to a different annotation, or none at
all. alterAnnotations for SimpleDocTree.
Note that this is as powerful as alterAnnotations, allowing one annotation
to become multiple ones, contrary to alterAnnotationsS, which cannot do
this.
Common use case shortcut definitions
renderSimplyDecorated Source #
Arguments
| :: Monoid out | |
| => (Text -> out) | Render plain |
| -> (ann -> out -> out) | How to modify an element with an annotation |
| -> SimpleDocTree ann | |
| -> out |
Simplest possible tree-based renderer.
For example, here is a document annotated with (), and the behaviour is to
surround annotated regions with »>>>« and »<<<«:
>>>let doc = "hello" <+> annotate () "world" <> "!">>>let stdoc = treeForm (layoutPretty defaultLayoutOptions doc)>>>T.putStrLn (renderSimplyDecorated id (\() x -> ">>>" <> x <> "<<<") stdoc)hello >>>world<<<!
renderSimplyDecoratedA Source #
Arguments
| :: (Applicative f, Monoid out) | |
| => (Text -> f out) | Render plain |
| -> (ann -> f out -> f out) | How to modify an element with an annotation |
| -> SimpleDocTree ann | |
| -> f out |
Version of renderSimplyDecoratedA that allows for Applicative effects.