@@ -53,7 +53,9 @@ import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
53import Network.URI (parseURI, isURI, URI(..))
53import Network.URI (parseURI, isURI, URI(..))
54import qualified Data.ByteString.Lazy as B
54import qualified Data.ByteString.Lazy as B
55import Data.ByteString.Lazy.UTF8 (toString )
55import Data.ByteString.Lazy.UTF8 (toString )
56+import Text.HTML.TagSoup.Entity (lookupEntity)
56import Codec.Binary.UTF8.String (decodeString, encodeString)
57import Codec.Binary.UTF8.String (decodeString, encodeString)
58+import Text.CSL.Reference (Reference(..))
58copyrightMessage :: String
60copyrightMessage :: String
59copyrightMessage = "\nCopyright (C) 2006-2011 John MacFarlane\n" ++
61copyrightMessage = "\nCopyright (C) 2006-2011 John MacFarlane\n" ++
@@ -617,6 +619,18 @@ options =
617 "" -- "Show help"
619 "" -- "Show help"
622+-- Unescapes XML entities
623+deEntity :: String -> String
625+ case lookupEntity ent of
626+ Just c -> c : deEntity rest
627+ Nothing -> '&' : deEntity rest
628+ where (ent, rest) = case break (==';') xs of
629+ (zs,';':ys) -> (zs,ys)
631+deEntity (x:xs) = x : deEntity xs
620-- Returns usage message
634-- Returns usage message
621usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
635usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
622usageMessage programName = usageInfo
636usageMessage programName = usageInfo
@@ -821,10 +835,15 @@ main = do
821 return $ ("dzslides-core", dzcore) : variables'
835 return $ ("dzslides-core", dzcore) : variables'
822 _ -> return variables'
836 _ -> return variables'
838+ -- unescape reference ids, which may contain XML entities, so
839+ -- that we can do lookups with regular string equality
840+ let unescapeRefId ref = ref{ refId = deEntity (refId ref) }
824 refs <- mapM (\f -> catch (CSL.readBiblioFile f) $ \e -> do
842 refs <- mapM (\f -> catch (CSL.readBiblioFile f) $ \e -> do
825 UTF8.hPutStrLn stderr $ "Error reading bibliography `" ++ f ++ "'"
843 UTF8.hPutStrLn stderr $ "Error reading bibliography `" ++ f ++ "'"
826 UTF8.hPutStrLn stderr $ show e
844 UTF8.hPutStrLn stderr $ show e
827− exitWith (ExitFailure 23)) reffiles >>= \rs -> return $ concat rs
845+ exitWith (ExitFailure 23)) reffiles >>=
846+ return . map unescapeRefId . concat
829 let sourceDir = if null sources
848 let sourceDir = if null sources