summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2011-11-11 17:36:57 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2011-11-11 17:54:34 -0800
commit9a46d755061713d6656020d554b62f1aaa922def (patch)
treee5f728782d0b4afe1d226a7fea0231404201120b /src
parent14620579c0467157a641613275a11379b34c9534 (diff)
Implemented --citation-abbreviations option.
Mostly due to Andrea Rossato.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Biblio.hs15
-rw-r--r--src/pandoc.hs11
2 files changed, 20 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs
index cf99e5c35..c8e87b2a0 100644
--- a/src/Text/Pandoc/Biblio.hs
+++ b/src/Text/Pandoc/Biblio.hs
@@ -43,11 +43,15 @@ import Control.Monad
-- | Process a 'Pandoc' document by adding citations formatted
-- according to a CSL style, using 'citeproc' from citeproc-hs.
-processBiblio :: FilePath -> [Reference] -> Pandoc -> IO Pandoc
-processBiblio cslfile r p
+processBiblio :: FilePath -> Maybe FilePath -> [Reference] -> Pandoc
+ -> IO Pandoc
+processBiblio cslfile abrfile r p
= if null r then return p
else do
csl <- readCSLFile cslfile
+ abbrevs <- case abrfile of
+ Just f -> readJsonAbbrevFile f
+ Nothing -> return []
p' <- bottomUpM setHash p
let (nts,grps) = if styleClass csl == "note"
then let cits = queryWith getCite p'
@@ -55,11 +59,12 @@ processBiblio cslfile r p
needNt = cits \\ concat ncits
in (,) needNt $ getNoteCitations needNt p'
else (,) [] $ queryWith getCitation p'
- result = citeproc procOpts csl r (setNearNote csl $
+ style = csl { styleAbbrevs = abbrevs }
+ result = citeproc procOpts style r (setNearNote style $
map (map toCslCite) grps)
cits_map = M.fromList $ zip grps (citations result)
- biblioList = map (renderPandoc' csl) (bibliography result)
- Pandoc m b = bottomUp (procInlines $ processCite csl cits_map) p'
+ biblioList = map (renderPandoc' style) (bibliography result)
+ Pandoc m b = bottomUp (procInlines $ processCite style cits_map) p'
return . generateNotes nts . Pandoc m $ b ++ biblioList
-- | Substitute 'Cite' elements with formatted citations.
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 1fe923976..387fc8095 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -124,6 +124,7 @@ data Opt = Opt
, optCiteMethod :: CiteMethod -- ^ Method to output cites
, optBibliography :: [String]
, optCslFile :: FilePath
+ , optAbbrevsFile :: Maybe FilePath
, optListings :: Bool -- ^ Use listings package for code blocks
, optAscii :: Bool -- ^ Avoid using nonascii characters
}
@@ -168,6 +169,7 @@ defaultOpts = Opt
, optCiteMethod = Citeproc
, optBibliography = []
, optCslFile = ""
+ , optAbbrevsFile = Nothing
, optListings = False
, optAscii = False
}
@@ -537,6 +539,12 @@ options =
"FILENAME")
""
+ , Option "" ["citation-abbreviations"]
+ (ReqArg
+ (\arg opt -> return opt { optAbbrevsFile = Just arg })
+ "FILENAME")
+ ""
+
, Option "" ["natbib"]
(NoArg
(\opt -> return opt { optCiteMethod = Natbib }))
@@ -702,6 +710,7 @@ main = do
, optDataDir = mbDataDir
, optBibliography = reffiles
, optCslFile = cslfile
+ , optAbbrevsFile = cslabbrevs
, optCiteMethod = citeMethod
, optListings = listings
, optAscii = ascii
@@ -883,7 +892,7 @@ main = do
replaceDirectory
(replaceExtension cslfile "csl")
csldir
- processBiblio cslfile' refs doc1
+ processBiblio cslfile' cslabbrevs refs doc1
else return doc1
case lookup writerName' writers of