aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-10-22 10:41:22 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-22 10:42:47 -0700
commit8f97c8e4580390a5c611c07925f1e38cfa42fb2a (patch)
tree64b3482842166d41fb72a6bd2997664c1cac14d5 /src
parent9608fd0c4af42bb891d42bc4591452001f3b4686 (diff)
downloadpandoc-8f97c8e4580390a5c611c07925f1e38cfa42fb2a.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Man.hs14
1 files changed, 7 insertions, 7 deletions
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 ""