DokuWiki writer: rewrite backSlashLineBreaks (#4445)
Rewrite for efficiency.
This commit is contained in:
parent
85a65c6a51
commit
bcfc3916e9
1 changed files with 11 additions and 7 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue