diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-08-12 00:52:08 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-08-12 00:52:08 +0000 |
commit | 24bf0cfe8cada90c585eefe25cf905c256240e57 (patch) | |
tree | eb5c094635ce5114b8a5525dc2bd340ebdd0bc64 /Text | |
parent | c8a56a2864191831e234224eb5638ee53672b314 (diff) | |
download | pandoc-24bf0cfe8cada90c585eefe25cf905c256240e57.tar.gz |
Patches to Text.Pandoc.Biblio for new citeproc API.
(Andrea Rossato)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1406 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Text')
-rw-r--r-- | Text/Pandoc/Biblio.hs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/Text/Pandoc/Biblio.hs b/Text/Pandoc/Biblio.hs index fc7d0a15f..3b1c06aeb 100644 --- a/Text/Pandoc/Biblio.hs +++ b/Text/Pandoc/Biblio.hs @@ -40,6 +40,8 @@ module Text.Pandoc.Biblio () where #endif #ifdef _CITEPROC +-- | Process a 'Pandoc' document by adding citations formatted +-- according to a CSL style, using 'citeproc' from citeproc-hs. processBiblio :: String -> [Reference] -> Pandoc -> IO Pandoc processBiblio cf r p = if null r then return p @@ -47,16 +49,13 @@ processBiblio cf r p when (null cf) $ error "Missing the needed citation style file" csl <- readCSLFile cf let groups = queryPandoc getCite p - citations = zip groups . processCitations csl r $ groups - Pandoc m b = processPandoc (processCite citations) p - return $ Pandoc m $ b ++ renderBiblio csl r p - -renderBiblio :: Style -> [Reference] -> Pandoc -> [Block] -renderBiblio s r p - = map (read . renderPandoc') $ processBibliography s refs - where cits = nub . map fst . concat . queryPandoc getCite $ p - refs = getRefs r $ zip cits (repeat "") + result = citeproc csl r groups + cits_map = zip groups (citations result) + biblioList = map (read . renderPandoc') (bibliography result) + Pandoc m b = processPandoc (processCite cits_map) p + return $ Pandoc m $ b ++ biblioList +-- | Substitute 'Cite' elements with formatted citations. processCite :: [([Target],[FormattedOutput])] -> Inline -> Inline processCite cs il | Cite t _ <- il = Cite t (process t) @@ -66,11 +65,9 @@ processCite cs il Just i -> read . renderPandoc $ snd (cs !! i) Nothing -> [Str ("Error processing " ++ show t)] +-- | Retrieve all citations from a 'Pandoc' docuument. To be used with +-- 'queryPandoc'. getCite :: Inline -> [[(String,String)]] getCite i | Cite t _ <- i = [t] | otherwise = [] - -getRefs :: [Reference] -> [Target] -> [Reference] -getRefs = map . getReference - #endif |