aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Doc.hs
blob: 9c21015a601c5a5d1c42fa8897f4674b04ca9137 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Haddock.Doc ( module Documentation.Haddock.Doc
                   , docCodeBlock
                   , combineDocumentation
                   ) where

import Data.Maybe
import Documentation.Haddock.Doc
import Haddock.Types
import Haddock.Utils (mkMeta)

combineDocumentation :: Documentation name -> Maybe (MDoc name)
combineDocumentation (Documentation Nothing Nothing) = Nothing
combineDocumentation (Documentation mDoc mWarning)   =
  Just (maybe emptyMetaDoc mkMeta mWarning
        `metaDocAppend`
        fromMaybe emptyMetaDoc mDoc)

-- Drop trailing whitespace from @..@ code blocks.  Otherwise this:
--
--    -- @
--    -- foo
--    -- @
--
-- turns into (DocCodeBlock "\nfoo\n ") which when rendered in HTML
-- gives an extra vertical space after the code block.  The single space
-- on the final line seems to trigger the extra vertical space.
--
docCodeBlock :: DocH mod id -> DocH mod id
docCodeBlock (DocString s)
  = DocString (reverse $ dropWhile (`elem` " \t") $ reverse s)
docCodeBlock (DocAppend l r)
  = DocAppend l (docCodeBlock r)
docCodeBlock d = d