diff options
author | Mauro Bieg <mb21@users.noreply.github.com> | 2018-03-14 05:41:23 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-03-13 21:41:23 -0700 |
commit | bcfc3916e9c5cc32b1abe4413e6290edabcf3d3e (patch) | |
tree | 6ddee025a517b3908af1bcce420eed3018991827 /src/Text/Pandoc/Writers | |
parent | 85a65c6a513421b373bbf23d81f53a16d62aa013 (diff) | |
download | pandoc-bcfc3916e9c5cc32b1abe4413e6290edabcf3d3e.tar.gz |
DokuWiki writer: rewrite backSlashLineBreaks (#4445)
Rewrite for efficiency.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/DokuWiki.hs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/DokuWiki.hs b/src/Text/Pandoc/Writers/DokuWiki.hs index 3fd297c00..523830e28 100644 --- a/src/Text/Pandoc/Writers/DokuWiki.hs +++ b/src/Text/Pandoc/Writers/DokuWiki.hs @@ -366,12 +366,16 @@ isSimpleBlockQuote bs = all isPlainOrPara bs vcat :: [String] -> String vcat = intercalate "\n" -backSlashLineBreaks :: String -> String -backSlashLineBreaks cs = reverse $ g $ reverse $ concatMap f cs - where f '\n' = "\\\\ " - f c = [c] - g (' ' : '\\':'\\': xs) = xs - g s = s +-- | For each string in the input list, convert all newlines to +-- dokuwiki escaped newlines. Then concat the list using double linebreaks. +backSlashLineBreaks :: [String] -> String +backSlashLineBreaks ls = vcatBackSlash $ map escape ls + where + vcatBackSlash = intercalate "\\\\ \\\\ " -- simulate paragraphs. + escape ('\n':[]) = "" -- remove trailing newlines + escape ('\n':cs) = "\\\\ " ++ escape cs + escape (c:cs) = c : (escape cs) + escape [] = [] -- Auxiliary functions for tables: @@ -400,7 +404,7 @@ blockListToDokuWiki opts blocks = do backSlash <- stBackSlashLB <$> ask let blocks' = consolidateRawBlocks blocks if backSlash - then (backSlashLineBreaks . vcat) <$> mapM (blockToDokuWiki opts) blocks' + then backSlashLineBreaks <$> mapM (blockToDokuWiki opts) blocks' else vcat <$> mapM (blockToDokuWiki opts) blocks' consolidateRawBlocks :: [Block] -> [Block] |