@@ -33,6 +33,7 @@ module Text.Pandoc.Parsing ( (>>~),
3333 many1Till,
3434 notFollowedBy',
3535 oneOfStrings,
36+ oneOfStringsCI,
3637 spaceChar,
3738 nonspaceChar,
3839 skipSpaces,
@@ -210,16 +211,28 @@ notFollowedBy' p = try $ join $ do a <- try p
210211 return (return ())
211212-- (This version due to Andrew Pimlott on the Haskell mailing list.)
212213
213−-- | Parses one of a list of strings (tried in order).
214−oneOfStrings :: [String] -> Parser [Char] st String
215−oneOfStrings [] = fail "no strings"
216−oneOfStrings strs = do
214+oneOfStrings' :: (Char -> Char -> Bool) -> [String] -> Parser [Char] st String
215+oneOfStrings' matches [] = fail "no strings"
216+oneOfStrings' matches strs = try $ do
217217 c <- anyChar
218− let strs' = [xs | (x:xs) <- strs, x == c]
218+ let strs' = [xs | (x:xs) <- strs, x `matches` c]
219219 case strs' of
220220 [] -> fail "not found"
221− z | "" `elem` z -> return [c]
222− | otherwise -> (c:) `fmap` oneOfStrings strs'
221+ _ -> (c:) `fmap` oneOfStrings' matches strs'
222+ <|> if "" `elem` strs'
223+ then return [c]
224+ else fail "not found"
225+
226+-- | Parses one of a list of strings. If the list contains
227+-- two strings one of which is a prefix of the other, the longer
228+-- string will be matched if possible.
229+oneOfStrings :: [String] -> Parser [Char] st String
230+oneOfStrings = oneOfStrings' (==)
231+
232+-- | Parses one of a list of strings (tried in order), case insensitive.
233+oneOfStringsCI :: [String] -> Parser [Char] st String
234+oneOfStringsCI = oneOfStrings' ciMatch
235+ where ciMatch x y = toLower x == toLower y
223236
224237-- | Parses a space or tab.
225238spaceChar :: Parser [Char] st Char