diff options
| author | John MacFarlane <[email protected]> | 2022-02-04 23:47:19 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-02-04 23:47:19 -0800 |
| commit | 1402051da5814196737e38b42b9582710441c5ad (patch) | |
| tree | 20c44bbe799dece498147463fb341b5d4155ca54 | |
| parent | 7cfce2142635fb990480f896ae117a287640c72b (diff) | |
Add framework for RIS reader.ris
| -rw-r--r-- | pandoc.cabal | 1 | ||||
| -rw-r--r-- | src/Text/Pandoc/App/FormatHeuristics.hs | 1 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers.hs | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/RIS.hs | 47 |
4 files changed, 52 insertions, 0 deletions
diff --git a/pandoc.cabal b/pandoc.cabal index 66df92a17..35cc543ca 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -547,6 +547,7 @@ library Text.Pandoc.Readers.Creole, Text.Pandoc.Readers.BibTeX, Text.Pandoc.Readers.EndNote, + Text.Pandoc.Readers.RIS, Text.Pandoc.Readers.CslJson, Text.Pandoc.Readers.MediaWiki, Text.Pandoc.Readers.Vimwiki, diff --git a/src/Text/Pandoc/App/FormatHeuristics.hs b/src/Text/Pandoc/App/FormatHeuristics.hs index 2bcdde484..ebf8db4c5 100644 --- a/src/Text/Pandoc/App/FormatHeuristics.hs +++ b/src/Text/Pandoc/App/FormatHeuristics.hs @@ -69,6 +69,7 @@ formatFromFilePath x = ".org" -> Just "org" ".pdf" -> Just "pdf" -- so we get an "unknown reader" error ".pptx" -> Just "pptx" + ".ris" -> Just "ris" ".roff" -> Just "ms" ".rst" -> Just "rst" ".rtf" -> Just "rtf" diff --git a/src/Text/Pandoc/Readers.hs b/src/Text/Pandoc/Readers.hs index 19b22b041..95f5f5b61 100644 --- a/src/Text/Pandoc/Readers.hs +++ b/src/Text/Pandoc/Readers.hs @@ -56,6 +56,7 @@ module Text.Pandoc.Readers , readBibTeX , readBibLaTeX , readEndNoteXML + , readRIS , readRTF -- * Miscellaneous , getReader @@ -105,6 +106,7 @@ import Text.Pandoc.Readers.CSV import Text.Pandoc.Readers.CslJson import Text.Pandoc.Readers.BibTeX import Text.Pandoc.Readers.EndNote +import Text.Pandoc.Readers.RIS import Text.Pandoc.Readers.RTF import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.Sources (ToSources(..), sourcesToText) @@ -154,6 +156,7 @@ readers = [("native" , TextReader readNative) ,("bibtex" , TextReader readBibTeX) ,("biblatex" , TextReader readBibLaTeX) ,("endnotexml" , TextReader readEndNoteXML) + ,("ris" , TextReader readRIS) ,("rtf" , TextReader readRTF) ] diff --git a/src/Text/Pandoc/Readers/RIS.hs b/src/Text/Pandoc/Readers/RIS.hs new file mode 100644 index 000000000..0685d8665 --- /dev/null +++ b/src/Text/Pandoc/Readers/RIS.hs @@ -0,0 +1,47 @@ +{- | + Module : Text.Pandoc.Readers.RIS + Copyright : Copyright (C) 2022 John MacFarlane + License : GNU GPL, version 2 or above + + Maintainer : John MacFarlane <[email protected]> + Stability : alpha + Portability : portable + +Parses RIS bibliographies into a Pandoc document +with empty body and `references` and `nocite` fields +in the metadata. A wildcard `nocite` is used so that +if the document is rendered in another format, the +entire bibliography will be printed. +-} +module Text.Pandoc.Readers.RIS + ( readRIS + ) +where + +import Text.Pandoc.Options +import Text.Pandoc.Definition +import Citeproc (Reference(..), ItemId(..), Val(..), Date(..), DateParts(..)) +import qualified Citeproc +import Text.Pandoc.Builder as B +import Text.Pandoc.Error (PandocError(..)) +import Text.Pandoc.Class (PandocMonad) +import Text.Pandoc.Citeproc.MetaValue (referenceToMetaValue) +import Text.Pandoc.Sources (Sources(..), ToSources(..), sourcesToText) +import Text.Pandoc.Citeproc.BibTeX (toName) +import Control.Applicative ((<|>)) +import Control.Monad.Except (throwError) +import Control.Monad (mzero, unless) +import qualified Data.Text.Lazy as TL +import qualified Data.Text as T +import Data.Text (Text) +import qualified Data.Map as M +import Safe (readMay) + +-- | Read RIS from an input string and return a Pandoc document. +-- The document will have only metadata, with an empty body. +-- The metadata will contain a `references` field with the +-- bibliography entries, and a `nocite` field with the wildcard `[@*]`. +readRIS :: (PandocMonad m, ToSources a) + => ReaderOptions -> a -> m Pandoc +readRIS _opts inp = undefined + |
