Safe Haskell | Safe-Inferred |
---|---|
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 a = FlattenedInline {
- fiValue :: FlattenedContent
- fiStyles :: [InlineStyle]
- fiURL :: Maybe URL
- fiName :: Maybe a
- data InlineStyle
- = Strong
- | Emph
- | Strikethrough
- | Code
- | Permalink
- data FlattenedValue a
- = SingleInline (FlattenedInline a)
- | NonBreaking (Seq (Seq (FlattenedValue a)))
- flattenInlineSeq :: SemEq a => HighlightSet -> Maybe (Int -> Inline -> Maybe a) -> Inlines -> Seq (Seq (FlattenedValue a))
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
Show FlattenedContent Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> FlattenedContent -> ShowS # show :: FlattenedContent -> String # showList :: [FlattenedContent] -> ShowS # | |
Eq FlattenedContent Source # | |
Defined in Matterhorn.Draw.RichText.Flatten (==) :: FlattenedContent -> FlattenedContent -> Bool # (/=) :: FlattenedContent -> FlattenedContent -> Bool # |
data FlattenedInline a Source #
A flattened inline value.
FlattenedInline | |
|
Instances
Show a => Show (FlattenedInline a) Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> FlattenedInline a -> ShowS # show :: FlattenedInline a -> String # showList :: [FlattenedInline a] -> ShowS # |
data InlineStyle Source #
The visual styles of inline values.
Instances
Show InlineStyle Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> InlineStyle -> ShowS # show :: InlineStyle -> String # showList :: [InlineStyle] -> ShowS # | |
Eq InlineStyle Source # | |
Defined in Matterhorn.Draw.RichText.Flatten (==) :: InlineStyle -> InlineStyle -> Bool # (/=) :: InlineStyle -> InlineStyle -> Bool # |
data FlattenedValue a Source #
A flattened value.
SingleInline (FlattenedInline a) | A single flattened value |
NonBreaking (Seq (Seq (FlattenedValue a))) | A sequence of flattened values that MUST be kept together and never broken up by line-wrapping |
Instances
Show a => Show (FlattenedValue a) Source # | |
Defined in Matterhorn.Draw.RichText.Flatten showsPrec :: Int -> FlattenedValue a -> ShowS # show :: FlattenedValue a -> String # showList :: [FlattenedValue a] -> ShowS # |
:: SemEq a | |
=> HighlightSet | |
-> Maybe (Int -> Inline -> Maybe a) | A name generator function for clickable inlines. The integer argument is a unique (to this inline sequence) sequence number. |
-> Inlines | |
-> Seq (Seq (FlattenedValue a)) |
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.
The optional name generator function argument is used to assign
resource names to each inline that should be clickable once rendered.
The result of the name generator function will be stored in the
fiName
field of each FlattenedInline
that results from calling
that function on an Inline
.