diff options
author | Mateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk> | 2013-09-03 01:29:27 +0100 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-01-12 14:48:35 -0600 |
commit | b11f371fdc9197cb45a6dafbcc0b095273d6614f (patch) | |
tree | 47dcee8f16e17903dfa059ed9236f276d6cdf1b0 /src/Haddock/Parser.hs | |
parent | ef9aa98d6ccbe79888c501f94c9aa6688520c28e (diff) |
Allow for headings inside function documentation.
LaTeX will treat the h3-h6 headings the same as we'd have to hack the
style file heavily otherwise and it would make the headings tiny
anyway.
Hoogle upstream said they will put in the functionality on their end.
Conflicts:
src/Haddock/Interface/Rename.hs
src/Haddock/Types.hs
test/Haddock/ParserSpec.hs
Diffstat (limited to 'src/Haddock/Parser.hs')
-rw-r--r-- | src/Haddock/Parser.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Haddock/Parser.hs b/src/Haddock/Parser.hs index 58d047f7..0d24cf17 100644 --- a/src/Haddock/Parser.hs +++ b/src/Haddock/Parser.hs @@ -14,7 +14,7 @@ module Haddock.Parser (parseString, parseParas, parseStringMaybe, parseParasMayb import Prelude hiding (takeWhile) import Control.Monad (void, mfilter) import Control.Applicative -import Data.Attoparsec.ByteString.Char8 hiding (parse, take, string, endOfLine) +import Data.Attoparsec.ByteString.Char8 hiding (parse, take, endOfLine) import qualified Data.ByteString.Char8 as BS import Data.Char (chr, isAsciiUpper) import Data.List (stripPrefix, intercalate) @@ -168,7 +168,17 @@ picture = DocPic . makeLabeled Picture . decodeUtf8 -- | Paragraph parser, called by 'parseParas'. paragraph :: DynFlags -> Parser (Doc RdrName) paragraph d = examples <|> skipSpace *> (list d <|> birdtracks <|> codeblock d - <|> property <|> textParagraph d) + <|> property <|> header d + <|> textParagraph d) + +header :: DynFlags -> Parser (Doc RdrName) +header d = do + let psers = map (string . encodeUtf8 . concat . flip replicate "=") [6, 5 .. 1] + pser = foldl1 (<|>) psers + delim <- decodeUtf8 <$> pser + line <- skipHorizontalSpace *> nonEmptyLine >>= return . parseString d + rest <- paragraph d <|> return mempty + return $ docAppend (DocParagraph (DocHeader (Header (length delim) line))) rest textParagraph :: DynFlags -> Parser (Doc RdrName) textParagraph d = docParagraph . parseString d . intercalate "\n" <$> many1 nonEmptyLine |