From 677f2ca26e784771a4b3eacb0a5318cb757cc339 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 5 Feb 2022 23:48:55 -0800 Subject: [PATCH] Allow use of a RIS bibliography with citeproc. --- MANUAL.txt | 1 + src/Text/Pandoc/Citeproc.hs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/MANUAL.txt b/MANUAL.txt index b06a618e7..5883fc64f 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -5730,6 +5730,7 @@ to YAML array. A bibliography may have any of these formats: BibTeX .bibtex CSL JSON .json CSL YAML .yaml + RIS .ris Note that `.bib` can be used with both BibTeX and BibLaTeX files; use the extension `.bibtex` to force interpretation as BibTeX. diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index 039238630..973e6bc17 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -16,6 +16,7 @@ import Text.Pandoc.Citeproc.Locator (parseLocator, toLocatorMap, LocatorInfo(..)) import Text.Pandoc.Citeproc.CslJson (cslJsonToReferences) import Text.Pandoc.Citeproc.BibTeX (readBibtexString, Variant(..)) +import Text.Pandoc.Readers.RIS (readRIS) import Text.Pandoc.Citeproc.MetaValue (metaValueToReference, metaValueToText) import Text.Pandoc.Readers.Markdown (yamlToRefs) import Text.Pandoc.Builder (Inlines, Many(..), deleteMeta, setMeta) @@ -267,6 +268,11 @@ getRefs locale format idpred mbfp raw = do (T.unpack <$> mbfp) raw return $ mapMaybe metaValueToReference rs + Format_ris -> do + Pandoc meta _ <- readRIS def (UTF8.toText raw) + case lookupMeta "references" meta of + Just (MetaList rs) -> return $ mapMaybe metaValueToReference rs + _ -> return [] -- assumes we walk in same order as query insertResolvedCitations :: Inline -> State [Inlines] Inline @@ -343,6 +349,7 @@ data BibFormat = | Format_bibtex | Format_json | Format_yaml + | Format_ris deriving (Show, Eq, Ord) formatFromExtension :: FilePath -> Maybe BibFormat @@ -353,6 +360,7 @@ formatFromExtension fp = case dropWhile (== '.') $ takeExtension fp of "json" -> Just Format_json "yaml" -> Just Format_yaml "yml" -> Just Format_yaml + "ris" -> Just Format_ris _ -> Nothing