@@ -12,6 +12,7 @@ module Language.LSP.Types.MarkupContent where
1212import            Data.Aeson 
1313import            Data.Aeson.TH 
1414import            Data.Text                                       (Text )
15+ import  qualified  Data.Text  as  T 
1516import            Language.LSP.Types.Utils 
1617
1718--  |   Describes the content type that a client supports in various 
@@ -81,10 +82,18 @@ sectionSeparator = "* * *\n"
8182
8283--  ---------------------------------------------------------------------
8384
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+ 
8492instance  Semigroup  MarkupContent  where 
8593  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)
8897
8998instance  Monoid   MarkupContent  where 
9099  mempty  =  MarkupContent  MkPlainText  " " 
0 commit comments