aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Shared.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index b8500ca7a..78206a7db 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -36,6 +36,7 @@ module Text.Pandoc.Shared (
joinWithSep,
tabsToSpaces,
backslashEscape,
+ escapeCharAsString,
endsWith,
stripTrailingNewlines,
removeLeadingTrailingSpace,
@@ -268,6 +269,14 @@ backslashEscape special (x:xs) = if x `elem` special
then '\\':x:(backslashEscape special xs)
else x:(backslashEscape special xs)
+-- | Escape a character as a string
+escapeCharAsString ch str "" = ""
+escapeCharAsString ch str (x:xs) | x == ch =
+ str ++ escapeCharAsString ch str xs
+escapeCharAsString ch str xs =
+ let (a,b) = break (== ch) xs in
+ a ++ escapeCharAsString ch str b
+
-- | Returns @True@ if string ends with given character.
endsWith :: Char -> [Char] -> Bool
endsWith char [] = False