From 8f97c8e4580390a5c611c07925f1e38cfa42fb2a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 22 Oct 2018 10:41:22 -0700 Subject: Man reader: fixed spurious newlines in code blocks. These were caused by lines that just changed to typewriter font. The lexer has been adjusted so these no longer show up as blank lines. Closes #5005. --- src/Text/Pandoc/Readers/Man.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index c449590ff..d74836435 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -416,8 +416,12 @@ lexLine :: PandocMonad m => ManLexer m ManTokens lexLine = do lnparts <- mconcat <$> many1 linePart eofline - return $ singleTok $ MLine lnparts - where + go lnparts + where -- return empty line if we only have empty strings; + -- this can happen if the line just contains \f[C], for example. + go [] = return mempty + go (RoffStr ("",_):xs) = go xs + go xs = return $ singleTok $ MLine xs linePart :: PandocMonad m => ManLexer m [LinePart] linePart = macroArg <|> esc <|> escStar <|> @@ -647,15 +651,11 @@ parseCodeBlock = try $ do mmacro "nf" toks <- many (mline <|> memptyLine) mmacro "fi" - return $ codeBlock (removeFinalNewline $ - intercalate "\n" . catMaybes $ + return $ codeBlock (intercalate "\n" . catMaybes $ extractText <$> toks) where - removeFinalNewline [] = [] - removeFinalNewline xs = if last xs == '\n' then init xs else xs - extractText :: ManToken -> Maybe String extractText (MLine ss) = Just $ linePartsToString ss extractText MEmptyLine = Just "" -- cgit v1.2.3