{-# LANGUAGE LambdaCase #-}
module Text.Jira.Markup
( Doc (..)
, Block (..)
, Inline (..)
, InlineStyle (..)
, ListStyle (..)
, URL (..)
, ColorName (..)
, Icon (..)
, Row (..)
, Cell (..)
, Language (..)
, Parameter (..)
, normalizeInlines
, iconText
) where
import Data.Text (Text, append)
newtype Doc = Doc { fromDoc :: [Block] }
deriving (Eq, Ord, Show)
data Inline
= Anchor Text
| AutoLink URL
| ColorInline ColorName [Inline]
| Emoji Icon
| Entity Text
| Image [Parameter] URL
| Linebreak
| Link [Inline] URL
| Monospaced [Inline]
| Space
| SpecialChar Char
| Str Text
| Styled InlineStyle [Inline]
deriving (Eq, Ord, Show)
data InlineStyle
= Emphasis
| Insert
| Strikeout
| Strong
| Subscript
| Superscript
deriving (Eq, Ord, Show)
data Block
= Code Language [Parameter] Text
| Color ColorName [Block]
| BlockQuote [Block]
| Header Int [Inline]
| HorizontalRule
| List ListStyle [[Block]]
| NoFormat [Parameter] Text
| Panel [Parameter] [Block]
| Para [Inline]
| Table [Row]
deriving (Eq, Ord, Show)
data ListStyle
= CircleBullets
| SquareBullets
| Enumeration
deriving (Eq, Ord, Show)
newtype ColorName = ColorName Text
deriving (Eq, Ord, Show)
newtype URL = URL { fromURL :: Text }
deriving (Eq, Ord, Show)
newtype Row = Row { fromRow :: [Cell] }
deriving (Eq, Ord, Show)
data Cell
= BodyCell [Block]
| HeaderCell [Block]
deriving (Eq, Ord, Show)
newtype Language = Language Text
deriving (Eq, Ord, Show)
data Parameter = Parameter
{ parameterKey :: Text
, parameterValue :: Text
} deriving (Eq, Ord, Show)
data Icon
= IconSlightlySmiling
| IconFrowning
| IconTongue
| IconSmiling
| IconWinking
| IconThumbsUp
| IconThumbsDown
| IconInfo
| IconCheckmark
| IconX
| IconAttention
| IconPlus
| IconMinus
| IconQuestionmark
| IconOn
| IconOff
| IconStar
| IconStarRed
| IconStarGreen
| IconStarBlue
| IconStarYellow
| IconFlag
| IconFlagOff
deriving (Enum, Eq, Ord, Show)
normalizeInlines :: [Inline] -> [Inline]
normalizeInlines = \case
[] -> []
[Space] -> []
[Linebreak] -> []
Space : Space : xs -> Space : normalizeInlines xs
Space : Linebreak : xs -> Linebreak : normalizeInlines xs
Linebreak : Space : xs -> Linebreak : normalizeInlines xs
Str s1 : Str s2 : xs -> Str (s1 `append` s2) : normalizeInlines xs
x : xs -> x : normalizeInlines xs
iconText :: Icon -> Text
iconText = \case
IconSlightlySmiling -> ":)"
IconFrowning -> ":("
IconTongue -> ":P"
IconSmiling -> ":D"
IconWinking -> ";)"
IconThumbsUp -> "(y)"
IconThumbsDown -> "(n)"
IconInfo -> "(i)"
IconCheckmark -> "(/)"
IconX -> "(x)"
IconAttention -> "(!)"
IconPlus -> "(+)"
IconMinus -> "(-)"
IconQuestionmark -> "(?)"
IconOn -> "(on)"
IconOff -> "(off)"
IconStar -> "(*)"
IconStarRed -> "(*r)"
IconStarGreen -> "(*g)"
IconStarBlue -> "(*b)"
IconStarYellow -> "(*y)"
IconFlag -> "(flag)"
IconFlagOff -> "(flagoff)"