@@ -12,6 +12,7 @@ module Language.LSP.Types.MarkupContent where
12
12
import Data.Aeson
13
13
import Data.Aeson.TH
14
14
import Data.Text (Text )
15
+ import qualified Data.Text as T
15
16
import Language.LSP.Types.Utils
16
17
17
18
-- | Describes the content type that a client supports in various
@@ -81,10 +82,18 @@ sectionSeparator = "* * *\n"
81
82
82
83
-- ---------------------------------------------------------------------
83
84
85
+ -- | Given some plaintext, convert it into some equivalent markdown text.
86
+ -- This is not *quite* the identity function.
87
+ plainTextToMarkdown :: Text -> Text
88
+ -- Line breaks in markdown paragraphs are ignored unless the line ends with two spaces.
89
+ -- In order to respect the line breaks in the original plaintext, we stick two spaces on the end of every line.
90
+ plainTextToMarkdown = T. unlines . fmap (<> " " ) . T. lines
91
+
84
92
instance Semigroup MarkupContent where
85
93
MarkupContent MkPlainText s1 <> MarkupContent MkPlainText s2 = MarkupContent MkPlainText (s1 `mappend` s2)
86
- MarkupContent MkMarkdown s1 <> MarkupContent _ s2 = MarkupContent MkMarkdown (s1 `mappend` s2)
87
- MarkupContent _ s1 <> MarkupContent MkMarkdown s2 = MarkupContent MkMarkdown (s1 `mappend` s2)
94
+ MarkupContent MkMarkdown s1 <> MarkupContent MkMarkdown s2 = MarkupContent MkMarkdown (s1 `mappend` s2)
95
+ MarkupContent MkPlainText s1 <> MarkupContent MkMarkdown s2 = MarkupContent MkMarkdown (plainTextToMarkdown s1 `mappend` s2)
96
+ MarkupContent MkMarkdown s1 <> MarkupContent MkPlainText s2 = MarkupContent MkMarkdown (s1 `mappend` plainTextToMarkdown s2)
88
97
89
98
instance Monoid MarkupContent where
90
99
mempty = MarkupContent MkPlainText " "
0 commit comments