@@ -64,9 +64,10 @@ module Text.Pandoc.Parsing ( (>>~),
6464 QuoteContext (..),
6565 NoteTable,
6666 KeyTable,
67− Key (..),
68− lookupKeySrc,
69− refsMatch )
67+ Key,
68+ toKey,
69+ fromKey,
70+ lookupKeySrc )
7071where
7172
7273import Text.Pandoc.Definition
@@ -651,13 +652,21 @@ data QuoteContext
651652
652653type NoteTable = [(String, String)]
653654
654−newtype Key = Key [Inline] deriving (Show, Read)
655+newtype Key = Key [Inline] deriving (Show, Read, Eq, Ord)
655656
656−instance Eq Key where
657− Key a == Key b = refsMatch a b
657+toKey :: [Inline] -> Key
658+toKey = Key . processWith lowercase
659+ where lowercase :: Inline -> Inline
660+ lowercase (Str xs) = Str (map toLower xs)
661+ lowercase (Math t xs) = Math t (map toLower xs)
662+ lowercase (Code xs) = Code (map toLower xs)
663+ lowercase (TeX xs) = TeX (map toLower xs)
664+ lowercase (HtmlInline xs) = HtmlInline (map toLower xs)
665+ lowercase LineBreak = Space
666+ lowercase x = x
658667
659−instance Ord Key where
660− compare (Key a) (Key b) = if a == b then EQ else compare a b
668+fromKey :: Key -> [Inline]
669+fromKey (Key xs) = xs
661670
662671type KeyTable = M.Map Key Target
663672
@@ -669,33 +678,3 @@ lookupKeySrc table key = case M.lookup key table of
669678 Nothing -> Nothing
670679 Just src -> Just src
671680
672−-- | Returns @True@ if keys match (case insensitive).
673−refsMatch :: [Inline] -> [Inline] -> Bool
674−refsMatch ((Str x):restx) ((Str y):resty) =
675− ((map toLower x) == (map toLower y)) && refsMatch restx resty
676−refsMatch ((Emph x):restx) ((Emph y):resty) =
677− refsMatch x y && refsMatch restx resty
678−refsMatch ((Strong x):restx) ((Strong y):resty) =
679− refsMatch x y && refsMatch restx resty
680−refsMatch ((Strikeout x):restx) ((Strikeout y):resty) =
681− refsMatch x y && refsMatch restx resty
682−refsMatch ((Superscript x):restx) ((Superscript y):resty) =
683− refsMatch x y && refsMatch restx resty
684−refsMatch ((Subscript x):restx) ((Subscript y):resty) =
685− refsMatch x y && refsMatch restx resty
686−refsMatch ((SmallCaps x):restx) ((SmallCaps y):resty) =
687− refsMatch x y && refsMatch restx resty
688−refsMatch ((Quoted t x):restx) ((Quoted u y):resty) =
689− t == u && refsMatch x y && refsMatch restx resty
690−refsMatch ((Code x):restx) ((Code y):resty) =
691− ((map toLower x) == (map toLower y)) && refsMatch restx resty
692−refsMatch ((Math t x):restx) ((Math u y):resty) =
693− ((map toLower x) == (map toLower y)) && t == u && refsMatch restx resty
694−refsMatch ((TeX x):restx) ((TeX y):resty) =
695− ((map toLower x) == (map toLower y)) && refsMatch restx resty
696−refsMatch ((HtmlInline x):restx) ((HtmlInline y):resty) =
697− ((map toLower x) == (map toLower y)) && refsMatch restx resty
698−refsMatch (x:restx) (y:resty) = (x == y) && refsMatch restx resty
699−refsMatch [] x = null x
700−refsMatch x [] = null x
701−