Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module implements a "flattening" pass over RichText Inline
values. This means that a tree structure such as
EStrong [ EStrikethrough [ EText "inside" ] , EText "outside" ]
will be converted into a "flat" representation without a tree structure so that the style information encoded in the tree is available at each node:
[ [ SingleInline (FlattenedInline (FText "inside") [Strong, Strikethrough] Nothing , SingleInline (FlattenedInline (FText "outside") [Strong] Nothing ] ]
The outer sequence is a sequence of lines (since inline lists can
introduce line breaks). Each inner sequence is a single line.
Each SingleInline
can be rendered as-is; if a NonBreaking
is
encountered, that group of inlines should be treated as a unit for
the purposes of line-wrapping (to happen in the Wrap module). The
above representation example shows how the tree path including the
EStrong
and EStrikethrough
nodes is flattened into a list of
styles to accompany each inline value. This makes it trivial to carry
that style information along with each node during line-wrapping
rather than needing to deal with the tree structure.
Synopsis
- data FlattenedContent
- data FlattenedInline = FlattenedInline {
- fiValue :: FlattenedContent
- fiStyles :: [InlineStyle]
- fiURL :: Maybe URL
- data InlineStyle
- = Strong
- | Emph
- | Strikethrough
- | Code
- | Permalink
- data FlattenedValue
- flattenInlineSeq :: HighlightSet -> Inlines -> Seq (Seq FlattenedValue)
Documentation
data FlattenedContent Source #
A piece of text in a sequence of flattened RichText elements. This type represents the lowest-level kind of data that we can get from a rich text document.
FText Text | Some text |
FSpace | A space |
FUser Text | A user reference |
FChannel Text | A channel reference |
FEmoji Text | An emoji |
FEditSentinel Bool | An "edited" marking |
Instances
Eq FlattenedContent Source # | |
Defined in Matterhorn.Draw.RichText.Flatten (==) :: FlattenedContent -> FlattenedContent -> Bool # (/=) :: FlattenedContent -> FlattenedContent -> Bool # | |
Show FlattenedContent Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> FlattenedContent -> ShowS # show :: FlattenedContent -> String # showList :: [FlattenedContent] -> ShowS # |
data FlattenedInline Source #
A flattened inline value.
FlattenedInline | |
|
Instances
Show FlattenedInline Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> FlattenedInline -> ShowS # show :: FlattenedInline -> String # showList :: [FlattenedInline] -> ShowS # |
data InlineStyle Source #
The visual styles of inline values.
Instances
Eq InlineStyle Source # | |
Defined in Matterhorn.Draw.RichText.Flatten (==) :: InlineStyle -> InlineStyle -> Bool # (/=) :: InlineStyle -> InlineStyle -> Bool # | |
Show InlineStyle Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> InlineStyle -> ShowS # show :: InlineStyle -> String # showList :: [InlineStyle] -> ShowS # |
data FlattenedValue Source #
A flattened value.
SingleInline FlattenedInline | A single flattened value |
NonBreaking (Seq (Seq FlattenedValue)) | A sequence of flattened values that MUST be kept together and never broken up by line-wrapping |
Instances
Show FlattenedValue Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> FlattenedValue -> ShowS # show :: FlattenedValue -> String # showList :: [FlattenedValue] -> ShowS # |
flattenInlineSeq :: HighlightSet -> Inlines -> Seq (Seq FlattenedValue) Source #
Given a sequence of inlines, flatten it into a list of lines of flattened values.
The flattening process also validates user and channel references
against a HighlightSet
. For example, if an EUser
node is found,
its username argument is looked up in the HighlightSet
. If the
username is found, the EUser
node is preserved as an FUser
node.
Otherwise it is rewritten as an FText
node so that the username
does not get highlighted. Channel references (EChannel
) are handled
similarly.