@@ -152,8 +152,8 @@ import Text.Pandoc.Builder (Blocks, Inlines, rawBlock)
152152import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
153153import Text.Parsec
154154import Text.Parsec.Pos (newPos)
155−import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isHexDigit,
156− isSpace )
155+import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum, isDigit,
156+ isHexDigit, isSpace )
157157import Data.List ( intercalate, transpose )
158158import Text.Pandoc.Shared
159159import qualified Data.Map as M
@@ -244,7 +244,13 @@ oneOfStrings = oneOfStrings' (==)
244244-- | Parses one of a list of strings (tried in order), case insensitive.
245245oneOfStringsCI :: [String] -> Parser [Char] st String
246246oneOfStringsCI = oneOfStrings' ciMatch
247− where ciMatch x y = toLower x == toLower y
247+ where ciMatch x y = toLower' x == toLower' y
248+ -- this optimizes toLower by checking common ASCII case
249+ -- first, before calling the expensive unicode-aware
250+ -- function:
251+ toLower' c | c >= 'A' && c <= 'Z' = chr (ord c + 32)
252+ | isAscii c = c
253+ | otherwise = toLower c
248254
249255-- | Parses a space or tab.
250256spaceChar :: Parser [Char] st Char