@@ -366,12 +366,16 @@ isSimpleBlockQuote bs = all isPlainOrPara bs
366366vcat :: [String] -> String
367367vcat = intercalate "\n"
368368
369−backSlashLineBreaks :: String -> String
370−backSlashLineBreaks cs = reverse $ g $ reverse $ concatMap f cs
371− where f '\n' = "\\\\ "
372− f c = [c]
373− g (' ' : '\\':'\\': xs) = xs
374− g s = s
369+-- | For each string in the input list, convert all newlines to
370+-- dokuwiki escaped newlines. Then concat the list using double linebreaks.
371+backSlashLineBreaks :: [String] -> String
372+backSlashLineBreaks ls = vcatBackSlash $ map escape ls
373+ where
374+ vcatBackSlash = intercalate "\\\\ \\\\ " -- simulate paragraphs.
375+ escape ('\n':[]) = "" -- remove trailing newlines
376+ escape ('\n':cs) = "\\\\ " ++ escape cs
377+ escape (c:cs) = c : (escape cs)
378+ escape [] = []
375379
376380-- Auxiliary functions for tables:
377381
@@ -400,7 +404,7 @@ blockListToDokuWiki opts blocks = do
400404 backSlash <- stBackSlashLB <$> ask
401405 let blocks' = consolidateRawBlocks blocks
402406 if backSlash
403− then (backSlashLineBreaks . vcat) <$> mapM (blockToDokuWiki opts) blocks'
407+ then backSlashLineBreaks <$> mapM (blockToDokuWiki opts) blocks'
404408 else vcat <$> mapM (blockToDokuWiki opts) blocks'
405409
406410consolidateRawBlocks :: [Block] -> [Block]