diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-02-01 22:12:54 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-02-01 22:12:54 -0800 |
commit | a6e3f1c7751c946780fab56c0d4f1c7d4ca85833 (patch) | |
tree | 8d4dd2cefa6e776fd79741c811a61b5d19957178 /src | |
parent | f5ebe98773e5b2de0d3cd2a87411b4141d0acd39 (diff) | |
download | pandoc-a6e3f1c7751c946780fab56c0d4f1c7d4ca85833.tar.gz |
LaTeX writer: use right fold for escapeString.
This is more elegant than the explicit recursive
we were using.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 619ad05a4..a61369330 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -323,13 +323,12 @@ stringToLaTeX :: PandocMonad m => StringContext -> String -> LW m String stringToLaTeX context zs = do opts <- gets stOptions return $ - go opts context $ + foldr (go opts context) mempty $ if writerPreferAscii opts then T.unpack $ Normalize.normalize Normalize.NFD $ T.pack zs else zs where - go _ _ [] = "" - go opts ctx (x:xs) = + go opts ctx x xs = let ligatures = isEnabled Ext_smart opts && ctx == TextString isUrl = ctx == URLString mbAccentCmd = @@ -338,24 +337,23 @@ stringToLaTeX context zs = do else Nothing emits s = case mbAccentCmd of - Just cmd -> (cmd ++ "{" ++ s ++ "}") ++ - go opts ctx (drop 1 xs) -- drop combining accent - Nothing -> s ++ go opts ctx xs + Just cmd -> + cmd ++ "{" ++ s ++ "}" ++ drop 1 xs -- drop combining accent + Nothing -> s ++ xs emitc c = case mbAccentCmd of - Just cmd -> cmd ++ "{" ++ [c] ++ "}" ++ - go opts ctx (drop 1 xs) -- drop combining accent - Nothing -> c : go opts ctx xs + Just cmd -> + cmd ++ "{" ++ [c] ++ "}" ++ drop 1 xs -- drop combining accent + Nothing -> c : xs emitcseq cs = do - let rest = go opts ctx xs - case rest of + case xs of c:_ | isLetter c , ctx == TextString - -> cs <> " " <> rest - | isSpace c -> cs <> "{}" <> rest + -> cs <> " " <> xs + | isSpace c -> cs <> "{}" <> xs | ctx == TextString - -> cs <> rest - _ -> cs <> "{}" <> rest + -> cs <> xs + _ -> cs <> "{}" <> xs in case x of '{' -> emits "\\{" '}' -> emits "\\}" |