matterhorn-50200.17.0: Terminal client for the Mattermost chat system
Safe HaskellNone
LanguageHaskell2010

Matterhorn.Draw.RichText.Flatten

Description

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

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.

Constructors

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

data FlattenedInline a Source #

A flattened inline value.

Constructors

FlattenedInline 

Fields

Instances

Instances details
Show a => Show (FlattenedInline a) Source # 
Instance details

Defined in Matterhorn.Draw.RichText.Flatten

data InlineStyle Source #

The visual styles of inline values.

Instances

Instances details
Eq InlineStyle Source # 
Instance details

Defined in Matterhorn.Draw.RichText.Flatten

Show InlineStyle Source # 
Instance details

Defined in Matterhorn.Draw.RichText.Flatten

data FlattenedValue a Source #

A flattened value.

Constructors

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

Instances details
Show a => Show (FlattenedValue a) Source # 
Instance details

Defined in Matterhorn.Draw.RichText.Flatten

flattenInlineSeq Source #

Arguments

:: 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.