Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a set of data types to represent message text. The inline and block types in this module are designed to represent most of what is found in Markdown documents (particularly the Commonmark specification) in addition to other things we find in Mattermost messages, such as username or channel references.
To parse a Markdown document, use parseMarkdown
. To actually render
text in this representation, see the module RichText
.
Synopsis
- newtype Blocks = Blocks (Seq Block)
- unBlocks :: Blocks -> Seq Block
- data Block
- sameBlockType :: Block -> Block -> Bool
- data CodeBlockInfo = CodeBlockInfo {}
- data Inline
- = EText Text
- | EEmph Inlines
- | EStrikethrough Inlines
- | EStrong Inlines
- | ECode Inlines
- | ESpace
- | ESoftBreak
- | ELineBreak
- | ERawHtml Text
- | EEditSentinel Bool
- | EUser Text
- | EChannel Text
- | EHyperlink URL Inlines
- | EImage URL Inlines
- | EEmoji Text
- | ENonBreaking Inlines
- | EPermalink TeamURLName PostId (Maybe Inlines)
- newtype Inlines = Inlines (Seq Inline)
- unInlines :: Inlines -> Seq Inline
- data ListType
- data ListSpacing
- data EnumeratorType
- data DelimiterType
- data ColAlignment
- data TeamBaseURL = TeamBaseURL TeamURLName ServerBaseURL
- data TeamURLName = TeamURLName Text
- newtype URL = URL Text
- unURL :: URL -> Text
- parseMarkdown :: Maybe TeamBaseURL -> Text -> Blocks
- findUsernames :: Blocks -> Set Text
- blockGetURLs :: Block -> [(Either (TeamURLName, PostId) URL, Maybe Inlines)]
- findVerbatimChunk :: Blocks -> Maybe Text
Documentation
A sequence of rich text blocks.
Instances
Show Blocks Source # | |
Semigroup Blocks Source # | |
Monoid Blocks Source # | |
Rangeable Blocks Source # | |
Defined in Matterhorn.Types.RichText ranged :: SourceRange -> Blocks -> Blocks # | |
HasAttributes Blocks Source # | |
Defined in Matterhorn.Types.RichText addAttributes :: Attributes -> Blocks -> Blocks # | |
IsBlock Inlines Blocks Source # | |
HasPipeTable Inlines Blocks Source # | |
Defined in Matterhorn.Types.RichText |
A block in a rich text document.
NOTE: update sameBlockType
when constructors are added to this
type.
Para Inlines | A paragraph. |
Header Int Inlines | A section header with specified depth and contents. |
Blockquote Blocks | A blockquote. |
List ListType ListSpacing (Seq Blocks) | An itemized list. |
CodeBlock CodeBlockInfo Text | A code block. |
HTMLBlock Text | A fragment of raw HTML. |
HRule | A horizontal rule. |
Table [ColAlignment] [Inlines] [[Inlines]] | A table. |
data CodeBlockInfo Source #
Information about a code block.
CodeBlockInfo | |
|
Instances
Eq CodeBlockInfo Source # | |
Defined in Matterhorn.Types.RichText (==) :: CodeBlockInfo -> CodeBlockInfo -> Bool # (/=) :: CodeBlockInfo -> CodeBlockInfo -> Bool # | |
Ord CodeBlockInfo Source # | |
Defined in Matterhorn.Types.RichText compare :: CodeBlockInfo -> CodeBlockInfo -> Ordering # (<) :: CodeBlockInfo -> CodeBlockInfo -> Bool # (<=) :: CodeBlockInfo -> CodeBlockInfo -> Bool # (>) :: CodeBlockInfo -> CodeBlockInfo -> Bool # (>=) :: CodeBlockInfo -> CodeBlockInfo -> Bool # max :: CodeBlockInfo -> CodeBlockInfo -> CodeBlockInfo # min :: CodeBlockInfo -> CodeBlockInfo -> CodeBlockInfo # | |
Show CodeBlockInfo Source # | |
Defined in Matterhorn.Types.RichText showsPrec :: Int -> CodeBlockInfo -> ShowS # show :: CodeBlockInfo -> String # showList :: [CodeBlockInfo] -> ShowS # |
The kinds of inline values that can appear in rich text blocks.
EText Text | Plain text that SHOULD be a contiguous sequence of non-whitespace characters. |
EEmph Inlines | Emphasized (usually italicized) content. |
EStrikethrough Inlines | Strikethrough content. |
EStrong Inlines | Boldface content. |
ECode Inlines | A sequence of non-whitespace characters. |
ESpace | A single space. |
ESoftBreak | A soft line break. |
ELineBreak | A hard line break. |
ERawHtml Text | Raw HTML. |
EEditSentinel Bool | A sentinel indicating that some text has been edited (used to indicate that mattermost messages have been edited by their authors). This has no parsable representation; it is only used to annotate a message prior to rendering to add a visual editing indicator. The boolean indicates whether the edit was "recent" (True) or not (False). |
EUser Text | A user reference. The text here includes only the username, not the sigil. |
EChannel Text | A channel reference. The text here includes only the channel name, not the sigil. |
EHyperlink URL Inlines | A hyperlink to the specified URL. Optionally provides an element sequence indicating the URL's text label; if absent, the label is understood to be the URL itself. |
EImage URL Inlines | An image at the specified URL. Optionally provides an element sequence indicating the image's "alt" text label; if absent, the label is understood to be the URL itself. |
EEmoji Text | An emoji reference. The text here includes only the text portion, not the colons, e.g. "foo" instead of ":foo:". |
ENonBreaking Inlines | A sequence of elements that must never be separated during line wrapping. |
EPermalink TeamURLName PostId (Maybe Inlines) | A permalink to the specified team (name) and post ID with an optional label. |
A sequence of inline values.
Instances
Eq Inlines Source # | |
Ord Inlines Source # | |
Show Inlines Source # | |
Semigroup Inlines Source # | |
Monoid Inlines Source # | |
IsInline Inlines Source # | |
Rangeable Inlines Source # | |
Defined in Matterhorn.Types.RichText ranged :: SourceRange -> Inlines -> Inlines # | |
HasAttributes Inlines Source # | |
Defined in Matterhorn.Types.RichText addAttributes :: Attributes -> Inlines -> Inlines # | |
HasStrikethrough Inlines Source # | |
Defined in Matterhorn.Types.RichText strikethrough :: Inlines -> Inlines # | |
IsBlock Inlines Blocks Source # | |
HasPipeTable Inlines Blocks Source # | |
Defined in Matterhorn.Types.RichText |
Instances
Eq ListType | |
Data ListType | |
Defined in Commonmark.Types gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ListType -> c ListType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ListType # toConstr :: ListType -> Constr # dataTypeOf :: ListType -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ListType) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ListType) # gmapT :: (forall b. Data b => b -> b) -> ListType -> ListType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ListType -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ListType -> r # gmapQ :: (forall d. Data d => d -> u) -> ListType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ListType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ListType -> m ListType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ListType -> m ListType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ListType -> m ListType # | |
Ord ListType | |
Defined in Commonmark.Types | |
Show ListType | |
data ListSpacing #
Instances
data EnumeratorType #
Instances
data DelimiterType #
Instances
data ColAlignment #
Instances
Eq ColAlignment | |
Defined in Commonmark.Extensions.PipeTable (==) :: ColAlignment -> ColAlignment -> Bool # (/=) :: ColAlignment -> ColAlignment -> Bool # | |
Data ColAlignment | |
Defined in Commonmark.Extensions.PipeTable gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ColAlignment -> c ColAlignment # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ColAlignment # toConstr :: ColAlignment -> Constr # dataTypeOf :: ColAlignment -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ColAlignment) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ColAlignment) # gmapT :: (forall b. Data b => b -> b) -> ColAlignment -> ColAlignment # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ColAlignment -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ColAlignment -> r # gmapQ :: (forall d. Data d => d -> u) -> ColAlignment -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ColAlignment -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ColAlignment -> m ColAlignment # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ColAlignment -> m ColAlignment # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ColAlignment -> m ColAlignment # | |
Show ColAlignment | |
Defined in Commonmark.Extensions.PipeTable showsPrec :: Int -> ColAlignment -> ShowS # show :: ColAlignment -> String # showList :: [ColAlignment] -> ShowS # |
data TeamBaseURL Source #
A server base URL with a team name.
Instances
Eq TeamBaseURL Source # | |
Defined in Matterhorn.Types.RichText (==) :: TeamBaseURL -> TeamBaseURL -> Bool # (/=) :: TeamBaseURL -> TeamBaseURL -> Bool # | |
Show TeamBaseURL Source # | |
Defined in Matterhorn.Types.RichText showsPrec :: Int -> TeamBaseURL -> ShowS # show :: TeamBaseURL -> String # showList :: [TeamBaseURL] -> ShowS # |
data TeamURLName Source #
A team name found in a Mattermost post URL
Instances
Eq TeamURLName Source # | |
Defined in Matterhorn.Types.RichText (==) :: TeamURLName -> TeamURLName -> Bool # (/=) :: TeamURLName -> TeamURLName -> Bool # | |
Ord TeamURLName Source # | |
Defined in Matterhorn.Types.RichText compare :: TeamURLName -> TeamURLName -> Ordering # (<) :: TeamURLName -> TeamURLName -> Bool # (<=) :: TeamURLName -> TeamURLName -> Bool # (>) :: TeamURLName -> TeamURLName -> Bool # (>=) :: TeamURLName -> TeamURLName -> Bool # max :: TeamURLName -> TeamURLName -> TeamURLName # min :: TeamURLName -> TeamURLName -> TeamURLName # | |
Show TeamURLName Source # | |
Defined in Matterhorn.Types.RichText showsPrec :: Int -> TeamURLName -> ShowS # show :: TeamURLName -> String # showList :: [TeamURLName] -> ShowS # |
:: Maybe TeamBaseURL | If provided, perform post link detection whenever a hyperlink is parsed by checking to see if the post link is a post in this Mattermost team |
-> Text | The markdown input text to parse |
-> Blocks |
Parse markdown input text to RichText.
Note that this always returns a block sequence even if the input cannot be parsed. It isn't yet clear just how permissive the commonmark parser is, but so far we have not encountered any issues. If the input document is so broken that commonmark cannot parse it, we return an empty block sequence.
blockGetURLs :: Block -> [(Either (TeamURLName, PostId) URL, Maybe Inlines)] Source #
Obtain all URLs (and optional labels) in a rich text block.