@@ -104,7 +104,7 @@ renderPackageWith settings headerFieldsAlignment existingFieldOrder sectionsFiel
104104 return $ concat [
105105 sourceRepository
106106 , customSetup
107- , map renderFlag packageFlags
107+ , map ( renderFlag packageCabalVersion) packageFlags
108108 , library
109109 , internalLibraries
110110 , executables
@@ -145,13 +145,16 @@ 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
149152formatDescription 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 ' '
@@ -179,13 +182,17 @@ renderSourceRepository SourceRepository{..} = Stanza "source-repository head" [
179182 , Field " subdir" (maybe " " Literal sourceRepositorySubdir)
180183 ]
181184
182- renderFlag :: Flag -> Element
183- renderFlag Flag {.. } = Stanza (" flag " ++ flagName) $ description ++ [
185+ renderFlag :: CabalVersion -> Flag -> Element
186+ renderFlag cabalVersion Flag {.. } = Stanza (" flag " ++ flagName) $ description ++ [
184187 Field " manual" (Literal $ show flagManual)
185188 , Field " default" (Literal $ show flagDefault)
186189 ]
187190 where
188- description = maybe [] (return . Field " description" . Literal ) 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
189196
190197renderInternalLibraries :: Map String (Section Library ) -> RenderM [Element ]
191198renderInternalLibraries = traverse renderInternalLibrary . Map. toList
0 commit comments