Skip to content

Commit b843afc

Browse files
committed
Improved comments handling
1 parent 3b5560f commit b843afc

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/Language/PureScript/Docs/AsHtml.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ renderChildren r xs = ul $ mapM_ item xs
182182
case Render.renderChildDeclaration decl of
183183
Render.RenderedAsCode renderedCode -> renderCode renderedCode
184184
Render.RenderedAsStructure struct ->
185-
ul $ for_ struct $ \(title, el) ->
186-
li ! A.id (v (T.drop 1 (subFragement decl title))) $ (renderCode el)
185+
ul $ for_ struct $ \(instChainEl, el) -> do
186+
li ! A.id (v (T.drop 1 (subFragement decl (icTitle instChainEl)))) $ (renderCode el)
187+
for_ (icComments instChainEl) $ \coms ->
188+
H.div ! A.class_ "decl__child__comments" $ renderMarkdown coms
187189
for_ (cdeclComments decl) $ \coms ->
188190
H.div ! A.class_ "decl__child_comments" $ renderMarkdown coms
189191

src/Language/PureScript/Docs/AsMarkdown.hs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Control.Monad (unless, zipWithM_)
1212
import Control.Monad.Writer (Writer, tell, execWriter)
1313

1414
import Data.Foldable (for_)
15+
import Data.Maybe (fromMaybe)
1516
import Data.List (partition)
1617
import Data.Text (Text)
1718
import 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
8687
childToString 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

102112
data First
103113
= First

src/Language/PureScript/Docs/Render.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ renderDeclaration Declaration{..} =
8282

8383
data RenderedChildDeclaration
8484
= RenderedAsCode RenderedCode
85-
| RenderedAsStructure [(Text, RenderedCode)]
85+
| RenderedAsStructure [(ChildInstanceChainInfo, RenderedCode)]
8686
deriving (Show, Eq, Ord)
8787

8888
renderChildDeclaration :: ChildDeclaration -> RenderedChildDeclaration
@@ -110,9 +110,9 @@ renderChildDeclaration ChildDeclaration{..} =
110110

111111
mapSnd f (a, b) = (a, f b)
112112

113-
renderInstanceChain :: ChildInstanceChainInfo -> (Text, RenderedCode)
113+
renderInstanceChain :: ChildInstanceChainInfo -> (ChildInstanceChainInfo, RenderedCode)
114114
renderInstanceChain inst =
115-
(icTitle inst, mintersperse sp $ renderChildInstance $ inst)
115+
(inst, mintersperse sp $ renderChildInstance $ inst)
116116

117117
renderChildInstance :: ChildInstanceChainInfo -> [RenderedCode]
118118
renderChildInstance (ChildInstanceChainInfo{..}) =

0 commit comments

Comments
 (0)