@@ -40,6 +40,8 @@ module Text.Pandoc.Biblio () where
4040#endif
4141
4242#ifdef _CITEPROC
43+-- | Process a 'Pandoc' document by adding citations formatted
44+-- according to a CSL style, using 'citeproc' from citeproc-hs.
4345processBiblio :: String -> [Reference] -> Pandoc -> IO Pandoc
4446processBiblio cf r p
4547 = if null r then return p
@@ -47,16 +49,13 @@ processBiblio cf r p
4749 when (null cf) $ error "Missing the needed citation style file"
4850 csl <- readCSLFile cf
4951 let groups = queryPandoc getCite p
50− citations = zip groups . processCitations csl r $ groups
51− Pandoc m b = processPandoc (processCite citations) p
52− return $ Pandoc m $ b ++ renderBiblio csl r p
53−
54−renderBiblio :: Style -> [Reference] -> Pandoc -> [Block]
55−renderBiblio s r p
56− = map (read . renderPandoc') $ processBibliography s refs
57− where cits = nub . map fst . concat . queryPandoc getCite $ p
58− refs = getRefs r $ zip cits (repeat "")
52+ result = citeproc csl r groups
53+ cits_map = zip groups (citations result)
54+ biblioList = map (read . renderPandoc') (bibliography result)
55+ Pandoc m b = processPandoc (processCite cits_map) p
56+ return $ Pandoc m $ b ++ biblioList
5957
58+-- | Substitute 'Cite' elements with formatted citations.
6059processCite :: [([Target],[FormattedOutput])] -> Inline -> Inline
6160processCite cs il
6261 | Cite t _ <- il = Cite t (process t)
@@ -66,11 +65,9 @@ processCite cs il
6665 Just i -> read . renderPandoc $ snd (cs !! i)
6766 Nothing -> [Str ("Error processing " ++ show t)]
6867
68+-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
69+-- 'queryPandoc'.
6970getCite :: Inline -> [[(String,String)]]
7071getCite i | Cite t _ <- i = [t]
7172 | otherwise = []
72−
73−getRefs :: [Reference] -> [Target] -> [Reference]
74−getRefs = map . getReference
75−
7673#endif