@@ -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
@@ -151,13 +151,16 @@ sortStanzaFields sectionsFieldOrder = go
151151 Stanza name fields : xs | Just fieldOrder <- lookup name sectionsFieldOrder -> Stanza name (sortFieldsBy fieldOrder fields) : go xs
152152 x : xs -> x : go xs
153153
154+ descriptionFieldSize :: Int
155+ descriptionFieldSize = length (" description: " :: String )
156+
154157formatDescription :: CabalVersion -> Alignment -> String -> String
155158formatDescription cabalVersion (Alignment alignment) description = case map emptyLineToDot $ lines description of
156159 x : xs -> intercalate " \n " (x : indent xs)
157160 [] -> " "
158161 where
159162 n :: Int
160- n = max alignment ( length ( " description: " :: String ))
163+ n = max alignment descriptionFieldSize
161164
162165 indentation :: String
163166 indentation = replicate n ' '
@@ -185,13 +188,17 @@ renderSourceRepository SourceRepository{..} = Stanza "source-repository head" [
185188 , Field " subdir" (maybe " " Literal sourceRepositorySubdir)
186189 ]
187190
188- renderFlag :: Flag -> Element
189- renderFlag Flag {.. } = Stanza (" flag " ++ flagName) $ description ++ [
191+ renderFlag :: CabalVersion -> Flag -> Element
192+ renderFlag cabalVersion Flag {.. } = Stanza (" flag " ++ flagName) $ description ++ [
190193 Field " manual" (Literal $ show flagManual)
191194 , Field " default" (Literal $ show flagDefault)
192195 ]
193196 where
194- description = maybe [] (return . Field " description" . Literal ) flagDescription
197+ description = maybe [] (return . Field " description" . Literal ) formattedFlagDescription
198+ -- We have to 'hard code' that the flag stanza's description field is
199+ -- indented by two spaces:
200+ alignment = Alignment (descriptionFieldSize + 2 )
201+ formattedFlagDescription = formatDescription cabalVersion alignment <$> flagDescription
195202
196203renderInternalLibraries :: Map String (Section Library ) -> RenderM [Element ]
197204renderInternalLibraries = traverse renderInternalLibrary . Map. toList
0 commit comments