From fdb7a5b79fd180c77cf72d8b0d0f75b334ed56e1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 21 Aug 2019 08:59:15 -0700 Subject: Don't add a newline if there's already one. --- src/Text/Pandoc/App.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index 4897366c3..741f2d37b 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -299,10 +299,11 @@ convertWithOpts opts = do TL.unpack (TE.decodeUtf8With TE.lenientDecode err') Nothing -> do - let addNl = if standalone - then id - else (<> T.singleton '\n') - output <- addNl <$> f writerOptions doc + let ensureNl t + | standalone = t + | T.null t || T.last t /= '\n' = t <> T.singleton '\n' + | otherwise = t + output <- ensureNl <$> f writerOptions doc writerFn eol outputFile =<< if optSelfContained opts && htmlFormat format -- TODO not maximally efficient; change type -- cgit v1.2.3