packages feed

citation-resolve 0.4 → 0.4.1

raw patch · 2 files changed

+22/−2 lines, 2 filesdep −binary-search

Dependencies removed: binary-search

Files

citation-resolve.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                citation-resolve-version:             0.4+version:             0.4.1 synopsis:            convert document IDs such as DOI, ISBN, arXiv ID to bibliographic reference. description:            This modules provides a way to convert document identifiers, such@@ -92,7 +92,6 @@                        Build-Depends:        base >=4.5 && < 5-    , binary-search     , hspec >= 1.3     , QuickCheck >= 2.5 
src/Text/CSL/Input/Identifier.hs view
@@ -14,10 +14,13 @@        (resolveEither, resolve, withDatabaseFile, Database(..), database, databaseMap, HasDatabase(..))        where +import qualified Control.Lens as Lens import           Control.Monad.IO.Class import           Control.Monad.State as State import           Control.Monad.Trans.Either import           Data.Default+import qualified Data.Map as Map+import qualified Data.Text as Text import           Text.CSL.Reference (emptyReference, Reference) import           Text.CSL.Input.Identifier.Internal @@ -45,6 +48,23 @@ resolve :: (MonadIO m, MonadState s m, HasDatabase s) => String -> m Reference resolve = liftM (either (const emptyReference) id) . runEitherT . resolveEither ++-- | Access the resolver database and generate the BibTeX item string for the document,+--   using the url as the citation-key.++toBibTeXItem :: (MonadIO m, MonadState s m, HasDatabase s) => String -> m Text.Text+toBibTeXItem url = do +  _ <- resolve url+  dbMap <- Lens.use databaseMap+  let ret = case Map.lookup url dbMap of+        Nothing -> ""+        Just str -> let (s0,s1) = break (=='{') str+                        (_,s2) = break (==',') s1+                    in s0 ++ "{" ++ url ++ s2+          +  return $ Text.pack ret++ -- | Resolve the document id using the default database.  resolveDef :: String -> IO Reference@@ -52,4 +72,5 @@   fn <- getDataFileName "default.db"   let go = withDatabaseFile fn $ resolve url   State.evalStateT go (def :: Database)+