@@ -299,10 +299,11 @@ convertWithOpts opts = do
299299 TL.unpack (TE.decodeUtf8With TE.lenientDecode err')
300300
301301 Nothing -> do
302− let addNl = if standalone
303− then id
304− else (<> T.singleton '\n')
305− output <- addNl <$> f writerOptions doc
302+ let ensureNl t
303+ | standalone = t
304+ | T.null t || T.last t /= '\n' = t <> T.singleton '\n'
305+ | otherwise = t
306+ output <- ensureNl <$> f writerOptions doc
306307 writerFn eol outputFile =<<
307308 if optSelfContained opts && htmlFormat format
308309 -- TODO not maximally efficient; change type