Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Conversion of the linked-list-like SimpleDocStream
to a tree-like
SimpleDocTree
.
- 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.
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. |
Functor SimpleDocTree Source # | Alter the document’s annotations. This instance makes |
Foldable SimpleDocTree Source # | Collect all annotations from a document. |
Traversable SimpleDocTree Source # | Transform a document based on its annotations, possibly leveraging
|
Eq ann => Eq (SimpleDocTree ann) Source # | |
Ord ann => Ord (SimpleDocTree ann) Source # | |
Show ann => Show (SimpleDocTree ann) Source # | |
Generic (SimpleDocTree ann) Source # | |
type Rep (SimpleDocTree ann) Source # | |
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 #
:: 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 #
:: (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.