@@ -12,6 +12,7 @@ import Control.Monad (unless, zipWithM_)
1212import Control.Monad.Writer (Writer , tell , execWriter )
1313
1414import Data.Foldable (for_ )
15+ import Data.Maybe (fromMaybe )
1516import Data.List (partition )
1617import Data.Text (Text )
1718import qualified Data.Text as T
@@ -45,14 +46,14 @@ declAsMarkdown decl@Declaration{..} = do
4546 let (instances, children) = partition (isChildInstance . cdeclInfo) declChildren
4647 fencedBlock $ do
4748 tell' (codeToString $ Render. renderDeclaration decl)
48- zipWithM_ (\ f c -> tell' ( childToString f c) ) (First : repeat NotFirst ) children
49+ zipWithM_ (\ f c -> childToString f c) (First : repeat NotFirst ) children
4950 spacer
5051
5152 for_ declComments tell'
5253
5354 unless (null instances) $ do
5455 headerLevel 5 " Instances"
55- fencedBlock $ mapM_ (tell' . childToString NotFirst ) instances
56+ mapM_ (childToString NotFirst ) instances
5657 spacer
5758
5859 where
@@ -82,22 +83,31 @@ codeToString = outputWith elemAsMarkdown
8283-- P.Infixr -> "right-associative"
8384-- P.Infix -> "non-associative"
8485
85- childToString :: First -> ChildDeclaration -> Text
86+ childToString :: First -> ChildDeclaration -> Docs
8687childToString f decl@ ChildDeclaration {.. } =
8788 case cdeclInfo of
8889 ChildDataConstructor _ ->
8990 let c = if f == First then " =" else " |"
90- in " " <> c <> " " <> str
91+ in fencedBlock $ do
92+ tell' $ " " <> c <> " "
93+ str
9194 ChildTypeClassMember _ ->
92- " " <> str
95+ fencedBlock $ do
96+ tell' $ " "
97+ str
9398 ChildInstanceChain _ ->
9499 str
95100 ChildPartOfInstanceChain _ ->
96- str
101+ fencedBlock $ str
97102 where
98103 str = case Render. renderChildDeclaration decl of
99- Render. RenderedAsCode code -> codeToString code
100- Render. RenderedAsStructure structure -> T. unlines $ (" - " <> ) <$> codeToString <$> snd <$> structure
104+ Render. RenderedAsCode code -> tell' $ codeToString code
105+ Render. RenderedAsStructure structure -> mapM_ chainInstanceToString structure
106+
107+ chainInstanceToString :: (ChildInstanceChainInfo , RenderedCode ) -> Docs
108+ chainInstanceToString (inst, code) = do
109+ fencedBlock $ tell' $ codeToString code
110+ mapM_ tell' $ icComments inst
101111
102112data First
103113 = First
0 commit comments