mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-30 20:45:49 +00:00
core: fix multiline mardown (#478)
* core: fix multiline mardown * add test
This commit is contained in:
committed by
GitHub
parent
41a2e0b1d5
commit
ea343b634d
@@ -12,6 +12,7 @@ import qualified Data.Attoparsec.Text as A
|
||||
import Data.Char (isDigit)
|
||||
import Data.Either (fromRight)
|
||||
import Data.Functor (($>))
|
||||
import Data.List (intercalate)
|
||||
import Data.Maybe (fromMaybe, isNothing)
|
||||
import Data.String
|
||||
import Data.Text (Text)
|
||||
@@ -83,6 +84,9 @@ data FormattedText = FormattedText {format :: Maybe Format, text :: Text}
|
||||
instance ToJSON FormattedText where
|
||||
toEncoding = J.genericToEncoding J.defaultOptions {J.omitNothingFields = True}
|
||||
|
||||
instance IsString FormattedText where
|
||||
fromString = FormattedText Nothing . T.pack
|
||||
|
||||
type MarkdownList = [FormattedText]
|
||||
|
||||
unmarked :: Text -> Markdown
|
||||
@@ -90,7 +94,7 @@ unmarked = Markdown Nothing
|
||||
|
||||
parseMaybeMarkdownList :: Text -> Maybe MarkdownList
|
||||
parseMaybeMarkdownList s =
|
||||
let m = markdownToList $ parseMarkdown s
|
||||
let m = intercalate ["\n"] . map (markdownToList . parseMarkdown) $ T.lines s
|
||||
in if all (isNothing . format) m then Nothing else Just m
|
||||
|
||||
parseMarkdownList :: Text -> MarkdownList
|
||||
|
||||
@@ -16,6 +16,7 @@ markdownTests = do
|
||||
textWithUri
|
||||
textWithEmail
|
||||
textWithPhone
|
||||
multilineMarkdownList
|
||||
|
||||
textFormat :: Spec
|
||||
textFormat = describe "text format (bold)" do
|
||||
@@ -180,3 +181,13 @@ textWithPhone = describe "text with Phone" do
|
||||
parseMarkdown "test 077777 test" `shouldBe` "test 077777 test"
|
||||
it "ignored as markdown (double spaces)" $
|
||||
parseMarkdown "test 07777 777 777 test" `shouldBe` "test 07777 777 777 test"
|
||||
|
||||
uri' :: Text -> FormattedText
|
||||
uri' = FormattedText $ Just Uri
|
||||
|
||||
multilineMarkdownList :: Spec
|
||||
multilineMarkdownList = describe "multiline markdown" do
|
||||
it "correct markdown" do
|
||||
parseMaybeMarkdownList "http://simplex.chat\nhttp://app.simplex.chat" `shouldBe` Just [uri' "http://simplex.chat", "\n", uri' "http://app.simplex.chat"]
|
||||
it "no markdown" do
|
||||
parseMaybeMarkdownList "not a\nmarkdown" `shouldBe` Nothing
|
||||
|
||||
Reference in New Issue
Block a user