module Text.Jira.Parser.PlainText
( plainText
) where
import Data.Text (Text, append, pack)
import Text.Jira.Markup
import Text.Jira.Parser.Core
import Text.Jira.Parser.Inline (specialChars)
import Text.Jira.Parser.Shared (icon)
import Text.Parsec
plainText :: Text -> Either ParseError [Inline]
plainText = parseJira (normalizeInlines <$> many plainInlineParser)
where
plainInlineParser :: JiraParser Inline
plainInlineParser = choice
[ Space <$ skipMany1 (char ' ')
, escapeIcon
, plainSpecialChar
, Str . pack <$> many1 (noneOf (' ':specialChars))
] <?> "text-only inline"
escapeIcon :: Parsec Text u Inline
escapeIcon = Str . ("\\" `append`) . iconText <$> icon
plainSpecialChar :: Parsec Text u Inline
plainSpecialChar = SpecialChar <$> oneOf specialChars