@@ -145,17 +145,25 @@ sortStanzaFields sectionsFieldOrder = go
145145 Stanza name fields : xs | Just fieldOrder <- lookup name sectionsFieldOrder -> Stanza name (sortFieldsBy fieldOrder fields) : go xs
146146 x : xs -> x : go xs
147147
148+ descriptionFieldSize :: Int
149+ descriptionFieldSize = length (" description: " :: String )
150+
148151formatDescription :: CabalVersion -> Alignment -> String -> String
149- formatDescription cabalVersion (Alignment alignment) description = case formatDescription' cabalVersion description of
152+ formatDescription cabalVersion (Alignment alignment) description = case map emptyLineToDot $ lines description of
150153 x : xs -> intercalate " \n " (x : indent xs)
151154 [] -> " "
152155 where
153156 n :: Int
154- n = max alignment ( length ( " description: " :: String ))
157+ n = max alignment descriptionFieldSize
155158
156159 indentation :: String
157160 indentation = replicate n ' '
158161
162+ emptyLineToDot :: String -> String
163+ emptyLineToDot xs
164+ | isEmptyLine xs && cabalVersion < makeCabalVersion [3 ] = " ."
165+ | otherwise = xs
166+
159167 indent :: [String ] -> [String ]
160168 indent = map indentLine
161169
@@ -164,16 +172,8 @@ formatDescription cabalVersion (Alignment alignment) description = case formatDe
164172 | isEmptyLine xs = " "
165173 | otherwise = indentation ++ xs
166174
167- isEmptyLine :: String -> Bool
168- isEmptyLine = all isSpace
169-
170- formatDescription' :: CabalVersion -> String -> [String ]
171- formatDescription' cabalVersion = map emptyLineToDot . lines
172- where
173- emptyLineToDot :: String -> String
174- emptyLineToDot xs
175- | isEmptyLine xs && cabalVersion < makeCabalVersion [3 ] = " ."
176- | otherwise = xs
175+ isEmptyLine :: String -> Bool
176+ isEmptyLine = all isSpace
177177
178178renderSourceRepository :: SourceRepository -> Element
179179renderSourceRepository SourceRepository {.. } = Stanza " source-repository head" [
@@ -188,8 +188,11 @@ renderFlag cabalVersion Flag {..} = Stanza ("flag " ++ flagName) $ description +
188188 , Field " default" (Literal $ show flagDefault)
189189 ]
190190 where
191- description = maybe [] (return . Field " description" . LineSeparatedList ) formattedFlagDescription
192- formattedFlagDescription = formatDescription' cabalVersion <$> flagDescription
191+ description = maybe [] (return . Field " description" . Literal ) formattedFlagDescription
192+ -- We have to 'hard code' that the flag stanza's description field is
193+ -- indented by two spaces:
194+ alignment = Alignment (descriptionFieldSize + 2 )
195+ formattedFlagDescription = formatDescription cabalVersion alignment <$> flagDescription
193196
194197renderInternalLibraries :: Map String (Section Library ) -> RenderM [Element ]
195198renderInternalLibraries = traverse renderInternalLibrary . Map. toList
0 commit comments