From 3b710b6fa7aad461302225abedd273dab06a40cd Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 19 Oct 2018 20:56:00 -0700 Subject: Man reader: minor refactoring. --- src/Text/Pandoc/Readers/Man.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index 77f8d42ec..9ead84f3e 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -145,13 +145,21 @@ lexMan = many (lexComment <|> lexMacro <|> lexLine <|> lexEmptyLine) parseMan :: PandocMonad m => ManParser m Pandoc parseMan = do - let parsers = [ try parseList, parseTitle, parsePara, parseSkippedContent - , try parseCodeBlock, parseHeader, parseSkipMacro] - bs <- many $ choice parsers - let (Pandoc _ blocks) = doc $ mconcat bs + bs <- many parseBlock meta <- stateMeta <$> getState + let (Pandoc _ blocks) = doc $ mconcat bs return $ Pandoc meta blocks +parseBlock :: PandocMonad m => ManParser m Blocks +parseBlock = choice [ parseList + , parseTitle + , parsePara + , parseSkippedContent + , parseCodeBlock + , parseHeader + , parseSkipMacro + ] + eofline :: Stream s m Char => ParsecT s u m () eofline = void newline <|> eof @@ -495,7 +503,7 @@ parseInlines = do parseCodeBlock :: PandocMonad m => ManParser m Blocks -parseCodeBlock = do +parseCodeBlock = try $ do mmacro "nf" toks <- many (mstr <|> mline <|> mmaybeLink <|> memptyLine <|> mcomment) mmacro "fi" @@ -522,7 +530,7 @@ parseHeader = do type ListBuilder = [Blocks] -> Blocks parseList :: PandocMonad m => ManParser m Blocks -parseList = do +parseList = try $ do xx <- many1 paras let bls = map snd xx let bldr = fst $ head xx -- cgit v1.2.3