git.iko.soy/typeable/pandoc
on master help sign in
Implemented --citation-abbreviations option.

Mostly due to Andrea Rossato.

commit9a46d755061713d6656020d554b62f1aaa922def authorJohn MacFarlane <jgm@berkeley.edu> dateFri 11 Nov 2011, 17:36 (15 years ago) parent1462057
3 files changed+36−6
README+16 src/Text/Pandoc/Biblio.hs+10−5 src/pandoc.hs+10−1
README+16
@@ -439,6 +439,22 @@ Options
439439 user data directory (see `--data-dir`), or, if that is
440440 not present, the Chicago author-date style.
441441
442+`--citation-abbreviations=`*FILE*
443+: Specify a file containing abbreviations for journal titles and
444+ other bibliographic fields (indicated by setting `form="short"`
445+ in the CSL node for the field). The format is described at
446+ <http://citationstylist.org/2011/10/19/abbreviations-for-zotero-test-release/>.
447+ Here is a short example:
448+
449+ { "default": {
450+ "container-title": {
451+ "Lloyd's Law Reports": "Lloyd's Rep",
452+ "Estates Gazette": "EG",
453+ "Scots Law Times": "SLT"
454+ }
455+ }
456+ }
457+
442458`--natbib`
443459: Use natbib for citations in LaTeX output.
444460
src/Text/Pandoc/Biblio.hs+10−5
@@ -43,11 +43,15 @@ import Control.Monad
4343
4444-- | Process a 'Pandoc' document by adding citations formatted
4545-- according to a CSL style, using 'citeproc' from citeproc-hs.
46−processBiblio :: FilePath -> [Reference] -> Pandoc -> IO Pandoc
47−processBiblio cslfile r p
46+processBiblio :: FilePath -> Maybe FilePath -> [Reference] -> Pandoc
47+ -> IO Pandoc
48+processBiblio cslfile abrfile r p
4849 = if null r then return p
4950 else do
5051 csl <- readCSLFile cslfile
52+ abbrevs <- case abrfile of
53+ Just f -> readJsonAbbrevFile f
54+ Nothing -> return []
5155 p' <- bottomUpM setHash p
5256 let (nts,grps) = if styleClass csl == "note"
5357 then let cits = queryWith getCite p'
@@ -55,11 +59,12 @@ processBiblio cslfile r p
5559 needNt = cits \\ concat ncits
5660 in (,) needNt $ getNoteCitations needNt p'
5761 else (,) [] $ queryWith getCitation p'
58− result = citeproc procOpts csl r (setNearNote csl $
62+ style = csl { styleAbbrevs = abbrevs }
63+ result = citeproc procOpts style r (setNearNote style $
5964 map (map toCslCite) grps)
6065 cits_map = M.fromList $ zip grps (citations result)
61− biblioList = map (renderPandoc' csl) (bibliography result)
62− Pandoc m b = bottomUp (procInlines $ processCite csl cits_map) p'
66+ biblioList = map (renderPandoc' style) (bibliography result)
67+ Pandoc m b = bottomUp (procInlines $ processCite style cits_map) p'
6368 return . generateNotes nts . Pandoc m $ b ++ biblioList
6469
6570-- | Substitute 'Cite' elements with formatted citations.
src/pandoc.hs+10−1
@@ -124,6 +124,7 @@ data Opt = Opt
124124 , optCiteMethod :: CiteMethod -- ^ Method to output cites
125125 , optBibliography :: [String]
126126 , optCslFile :: FilePath
127+ , optAbbrevsFile :: Maybe FilePath
127128 , optListings :: Bool -- ^ Use listings package for code blocks
128129 , optAscii :: Bool -- ^ Avoid using nonascii characters
129130 }
@@ -168,6 +169,7 @@ defaultOpts = Opt
168169 , optCiteMethod = Citeproc
169170 , optBibliography = []
170171 , optCslFile = ""
172+ , optAbbrevsFile = Nothing
171173 , optListings = False
172174 , optAscii = False
173175 }
@@ -537,6 +539,12 @@ options =
537539 "FILENAME")
538540 ""
539541
542+ , Option "" ["citation-abbreviations"]
543+ (ReqArg
544+ (\arg opt -> return opt { optAbbrevsFile = Just arg })
545+ "FILENAME")
546+ ""
547+
540548 , Option "" ["natbib"]
541549 (NoArg
542550 (\opt -> return opt { optCiteMethod = Natbib }))
@@ -702,6 +710,7 @@ main = do
702710 , optDataDir = mbDataDir
703711 , optBibliography = reffiles
704712 , optCslFile = cslfile
713+ , optAbbrevsFile = cslabbrevs
705714 , optCiteMethod = citeMethod
706715 , optListings = listings
707716 , optAscii = ascii
@@ -883,7 +892,7 @@ main = do
883892 replaceDirectory
884893 (replaceExtension cslfile "csl")
885894 csldir
886− processBiblio cslfile' refs doc1
895+ processBiblio cslfile' cslabbrevs refs doc1
887896 else return doc1
888897
889898 case lookup writerName' writers of