From 8f428c4e103c5d13dc478d16a05c9f1d317fe6d0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 23 Oct 2018 12:47:49 -0700 Subject: Man reader: handle implicitly closed RS, nf, EX. These are implicitly closed by a new section command. (See e.g. tiffcp.1) --- src/Text/Pandoc/Readers/Man.hs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index 7cf46a59a..fb10e3613 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -719,11 +719,19 @@ bareIP = msatisfy isBareIP where isBareIP (MMacro "IP" [] _) = True isBareIP _ = False +endmacro :: PandocMonad m => String -> ManParser m ManToken +endmacro name = mmacro name <|> lookAhead newBlockMacro + where + newBlockMacro = msatisfy isNewBlockMacro + isNewBlockMacro (MMacro "SH" _ _) = True + isNewBlockMacro (MMacro "SS" _ _) = True + isNewBlockMacro _ = False + parseCodeBlock :: PandocMonad m => ManParser m Blocks parseCodeBlock = try $ do optional bareIP -- some people indent their code - toks <- (mmacro "nf" *> many (mline <|> memptyLine) <* mmacro "fi") - <|> (mmacro "EX" *> many (mline <|> memptyLine) <* mmacro "EE") + toks <- (mmacro "nf" *> many (mline <|> memptyLine) <* endmacro "fi") + <|> (mmacro "EX" *> many (mline <|> memptyLine) <* endmacro "EE") return $ codeBlock (intercalate "\n" . catMaybes $ extractText <$> toks) @@ -786,12 +794,9 @@ parseList = try $ do Ordered lattr -> orderedListWith lattr (x:xs) continuation :: PandocMonad m => ManParser m Blocks -continuation = (do - mmacro "RS" - bs <- mconcat <$> many (notFollowedBy (mmacro "RE") >> parseBlock) - mmacro "RE" - return bs) - <|> mconcat <$> many1 (try (bareIP *> parsePara)) +continuation = + mconcat <$> (mmacro "RS" *> manyTill parseBlock (endmacro "RE")) + <|> mconcat <$> many1 (try (bareIP *> parsePara)) definitionListItem :: PandocMonad m => ManParser m (Inlines, [Blocks]) -- cgit v1.2.3