{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
module Text.CSL.Input.Bibtex
( readBibtex
, readBibtexString
, Lang(..)
, langToLocale
, getLangFromEnv
)
where
import Prelude
import Control.Applicative
import qualified Control.Exception as E
import Control.Monad
import Control.Monad.RWS hiding ((<>))
import Data.Char (isAlphaNum, isDigit, isUpper, toLower,
toUpper)
import Data.List (foldl', intercalate)
import Data.List.Split (splitOn, splitWhen, wordsBy)
import qualified Data.Map as Map
import Data.Maybe
import qualified Data.Text as T
import System.Environment (getEnvironment)
import Text.CSL.Compat.Pandoc (readLaTeX)
import Text.CSL.Exception (CiteprocException (ErrorReadingBib, ErrorReadingBibFile))
import Text.CSL.Parser (parseLocale)
import Text.CSL.Reference
import Text.CSL.Style (Agent (..), emptyAgent, CslTerm (..),
Formatted (..), Locale (..))
import Text.CSL.Util (onBlocks, protectCase, safeRead,
splitStrWhen, trim, unTitlecase,
addSpaceAfterPeriod)
import Text.Pandoc.Definition
import qualified Text.Pandoc.UTF8 as UTF8
import qualified Text.Pandoc.Walk as Walk
import Text.Parsec hiding (State, many, (<|>))
blocksToFormatted :: [Block] -> Bib Formatted
blocksToFormatted :: [Block] -> Bib Formatted
blocksToFormatted bs :: [Block]
bs =
case [Block]
bs of
[Plain xs :: [Inline]
xs] -> [Inline] -> Bib Formatted
inlinesToFormatted [Inline]
xs
[Para xs :: [Inline]
xs] -> [Inline] -> Bib Formatted
inlinesToFormatted [Inline]
xs
_ -> [Inline] -> Bib Formatted
inlinesToFormatted ([Inline] -> Bib Formatted) -> [Inline] -> Bib Formatted
forall a b. (a -> b) -> a -> b
$ (Inline -> [Inline]) -> [Block] -> [Inline]
forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
Walk.query (Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[]) [Block]
bs
adjustSpans :: Lang -> Inline -> [Inline]
adjustSpans :: Lang -> Inline -> [Inline]
adjustSpans _ (Span ("",[],[]) xs :: [Inline]
xs) = [Inline]
xs
adjustSpans lang :: Lang
lang (RawInline (Format "latex") s :: Text
s)
| Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "\\hyphen" Bool -> Bool -> Bool
|| Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "\\hyphen " = [Text -> Inline
Str "-"]
| Bool
otherwise = ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
Walk.walk ((Inline -> [Inline]) -> [Inline] -> [Inline]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Lang -> Inline -> [Inline]
adjustSpans Lang
lang))
([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (a -> b) -> a -> b
$ Lang -> String -> [Inline]
parseRawLaTeX Lang
lang (Text -> String
T.unpack Text
s)
adjustSpans _ x :: Inline
x = [Inline
x]
parseRawLaTeX :: Lang -> String -> [Inline]
parseRawLaTeX :: Lang -> String -> [Inline]
parseRawLaTeX lang :: Lang
lang ('\\':xs :: String
xs) =
case String -> [Block]
latex' String
contents of
[Para ys :: [Inline]
ys] -> String -> [Inline] -> [Inline]
forall a. (Eq a, IsString a) => a -> [Inline] -> [Inline]
f String
command [Inline]
ys
[Plain ys :: [Inline]
ys] -> String -> [Inline] -> [Inline]
forall a. (Eq a, IsString a) => a -> [Inline] -> [Inline]
f String
command [Inline]
ys
_ -> []
where (command' :: String
command', contents' :: String
contents') = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='{') String
xs
command :: String
command = String -> String
trim String
command'
contents :: String
contents = Int -> String -> String
forall a. Int -> [a] -> [a]
drop 1 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
forall a. [a] -> [a]
reverse (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
drop 1 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
forall a. [a] -> [a]
reverse String
contents'
f :: a -> [Inline] -> [Inline]
f "mkbibquote" ils :: [Inline]
ils = [QuoteType -> [Inline] -> Inline
Quoted QuoteType
DoubleQuote [Inline]
ils]
f "mkbibemph" ils :: [Inline]
ils = [[Inline] -> Inline
Emph [Inline]
ils]
f "mkbibitalic" ils :: [Inline]
ils = [[Inline] -> Inline
Emph [Inline]
ils]
f "mkbibbold" ils :: [Inline]
ils = [[Inline] -> Inline
Strong [Inline]
ils]
f "mkbibparens" ils :: [Inline]
ils = [Text -> Inline
Str "("] [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline]
ils [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Text -> Inline
Str ")"]
f "mkbibbrackets" ils :: [Inline]
ils = [Text -> Inline
Str "["] [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline]
ils [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Text -> Inline
Str "]"]
f "autocap" ils :: [Inline]
ils = [Inline]
ils
f "textnormal" ils :: [Inline]
ils = [Attr -> [Inline] -> Inline
Span ("",["nodecor"],[]) [Inline]
ils]
f "bibstring" [Str s :: Text
s] = [Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Lang -> String -> String
resolveKey' Lang
lang (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
s]
f _ ils :: [Inline]
ils = [Attr -> [Inline] -> Inline
Span Attr
nullAttr [Inline]
ils]
parseRawLaTeX _ _ = []
inlinesToFormatted :: [Inline] -> Bib Formatted
inlinesToFormatted :: [Inline] -> Bib Formatted
inlinesToFormatted ils :: [Inline]
ils = do
Lang
lang <- (BibState -> Lang) -> RWST Item () BibState Maybe Lang
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets BibState -> Lang
localeLanguage
Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return (Formatted -> Bib Formatted) -> Formatted -> Bib Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
Walk.walk ((Inline -> [Inline]) -> [Inline] -> [Inline]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Lang -> Inline -> [Inline]
adjustSpans Lang
lang)) [Inline]
ils
data Item = Item{ Item -> String
identifier :: String
, Item -> String
entryType :: String
, Item -> Map String String
fields :: Map.Map String String
}
getLangFromEnv :: IO Lang
getLangFromEnv :: IO Lang
getLangFromEnv = do
[(String, String)]
env <- IO [(String, String)]
getEnvironment
Lang -> IO Lang
forall (m :: * -> *) a. Monad m => a -> m a
return (Lang -> IO Lang) -> Lang -> IO Lang
forall a b. (a -> b) -> a -> b
$ case String -> [(String, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "LANG" [(String, String)]
env of
Just x :: String
x -> case (Char -> Bool) -> String -> [String]
forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '-')
((Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='.') String
x) of
(w :: String
w:z :: String
z:_) -> String -> String -> Lang
Lang String
w String
z
[w :: String
w] | Bool -> Bool
not (String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
w) -> String -> String -> Lang
Lang String
w String
forall a. Monoid a => a
mempty
_ -> String -> String -> Lang
Lang "en" "US"
Nothing -> String -> String -> Lang
Lang "en" "US"
readBibtex :: (String -> Bool) -> Bool -> Bool -> FilePath -> IO [Reference]
readBibtex :: (String -> Bool) -> Bool -> Bool -> String -> IO [Reference]
readBibtex idpred :: String -> Bool
idpred isBibtex :: Bool
isBibtex caseTransform :: Bool
caseTransform f :: String
f = do
String
contents <- String -> IO String
UTF8.readFile String
f
IO [Reference]
-> (CiteprocException -> IO [Reference]) -> IO [Reference]
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
E.catch ((String -> Bool) -> Bool -> Bool -> String -> IO [Reference]
readBibtexString String -> Bool
idpred Bool
isBibtex Bool
caseTransform String
contents)
(\e :: CiteprocException
e -> case CiteprocException
e of
ErrorReadingBib es :: String
es -> CiteprocException -> IO [Reference]
forall e a. Exception e => e -> IO a
E.throwIO (CiteprocException -> IO [Reference])
-> CiteprocException -> IO [Reference]
forall a b. (a -> b) -> a -> b
$ String -> String -> CiteprocException
ErrorReadingBibFile String
f String
es
_ -> CiteprocException -> IO [Reference]
forall e a. Exception e => e -> IO a
E.throwIO CiteprocException
e)
readBibtexString :: (String -> Bool) -> Bool -> Bool -> String
-> IO [Reference]
readBibtexString :: (String -> Bool) -> Bool -> Bool -> String -> IO [Reference]
readBibtexString idpred :: String -> Bool
idpred isBibtex :: Bool
isBibtex caseTransform :: Bool
caseTransform contents :: String
contents = do
Lang
lang <- IO Lang
getLangFromEnv
Locale
locale <- String -> IO Locale
parseLocale (Lang -> String
langToLocale Lang
lang)
case Parsec String (Map String String) [Item]
-> Map String String
-> String
-> String
-> Either ParseError [Item]
forall s t u a.
Stream s Identity t =>
Parsec s u a -> u -> String -> s -> Either ParseError a
runParser (Parsec String (Map String String) [Item]
bibEntries Parsec String (Map String String) [Item]
-> ParsecT String (Map String String) Identity ()
-> Parsec String (Map String String) [Item]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof) (Map String String
forall k a. Map k a
Map.empty) "stdin" String
contents of
Left err :: ParseError
err -> CiteprocException -> IO [Reference]
forall e a. Exception e => e -> IO a
E.throwIO (CiteprocException -> IO [Reference])
-> CiteprocException -> IO [Reference]
forall a b. (a -> b) -> a -> b
$ String -> CiteprocException
ErrorReadingBib (String -> CiteprocException) -> String -> CiteprocException
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
drop 8 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ ParseError -> String
forall a. Show a => a -> String
show ParseError
err
Right xs :: [Item]
xs -> [Reference] -> IO [Reference]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Reference] -> IO [Reference]) -> [Reference] -> IO [Reference]
forall a b. (a -> b) -> a -> b
$ (Item -> Maybe Reference) -> [Item] -> [Reference]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe
(Lang -> Locale -> Bool -> Bool -> Item -> Maybe Reference
itemToReference Lang
lang Locale
locale Bool
isBibtex Bool
caseTransform)
((Item -> Bool) -> [Item] -> [Item]
forall a. (a -> Bool) -> [a] -> [a]
filter (String -> Bool
idpred (String -> Bool) -> (Item -> String) -> Item -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Item -> String
identifier)
(Bool -> [Item] -> [Item]
resolveCrossRefs Bool
isBibtex
[Item]
xs))
type BibParser = Parsec String (Map.Map String String)
bibEntries :: BibParser [Item]
bibEntries :: Parsec String (Map String String) [Item]
bibEntries = do
ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT String (Map String String) Identity ()
nonEntry
ParsecT String (Map String String) Identity Item
-> Parsec String (Map String String) [Item]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ParsecT String (Map String String) Identity Item
bibItem ParsecT String (Map String String) Identity Item
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity Item
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT String (Map String String) Identity ()
nonEntry)
where nonEntry :: ParsecT String (Map String String) Identity ()
nonEntry = ParsecT String (Map String String) Identity ()
bibSkip ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '@' ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
(ParsecT String (Map String String) Identity ()
bibComment ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String (Map String String) Identity ()
bibPreamble ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String (Map String String) Identity ()
bibString))
bibSkip :: BibParser ()
bibSkip :: ParsecT String (Map String String) Identity ()
bibSkip = ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ((Char -> Bool) -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='@'))
bibComment :: BibParser ()
= do
String -> BibParser String
cistring "comment"
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
BibParser String -> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void BibParser String
inBraces ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String (Map String String) Identity ()
bibSkip ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () -> ParsecT String (Map String String) Identity ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
bibPreamble :: BibParser ()
bibPreamble :: ParsecT String (Map String String) Identity ()
bibPreamble = do
String -> BibParser String
cistring "preamble"
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
BibParser String -> ParsecT String (Map String String) Identity ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void BibParser String
inBraces
bibString :: BibParser ()
bibString :: ParsecT String (Map String String) Identity ()
bibString = do
String -> BibParser String
cistring "string"
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{'
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
(k :: String
k,v :: String
v) <- BibParser (String, String)
entField
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '}'
(Map String String -> Map String String)
-> ParsecT String (Map String String) Identity ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState (String -> String -> Map String String -> Map String String
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
k String
v)
() -> ParsecT String (Map String String) Identity ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
inBraces :: BibParser String
inBraces :: BibParser String
inBraces = BibParser String -> BibParser String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (BibParser String -> BibParser String)
-> BibParser String -> BibParser String
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{'
[String]
res <- BibParser String
-> ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity [String]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill
( ParsecT String (Map String String) Identity Char
-> BibParser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (String -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf "{}\\")
BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String (Map String String) Identity Char
-> BibParser String -> BibParser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ( (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{' ParsecT String (Map String String) Identity Char
-> BibParser String -> BibParser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> BibParser String
forall (m :: * -> *) a. Monad m => a -> m a
return "\\{")
BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '}' ParsecT String (Map String String) Identity Char
-> BibParser String -> BibParser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> BibParser String
forall (m :: * -> *) a. Monad m => a -> m a
return "\\}")
BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> BibParser String
forall (m :: * -> *) a. Monad m => a -> m a
return "\\"))
BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (String -> String
braced (String -> String) -> BibParser String -> BibParser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BibParser String
inBraces)
) (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '}')
String -> BibParser String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> BibParser String) -> String -> BibParser String
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String]
res
braced :: String -> String
braced :: String -> String
braced s :: String
s = "{" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ "}"
inQuotes :: BibParser String
inQuotes :: BibParser String
inQuotes = do
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '"'
[String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String)
-> ParsecT String (Map String String) Identity [String]
-> BibParser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BibParser String
-> ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity [String]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ( ParsecT String (Map String String) Identity Char
-> BibParser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (String -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf "\"\\{")
BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT String (Map String String) Identity Char
-> BibParser String -> BibParser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (\c :: Char
c -> ['\\',Char
c]) (Char -> String)
-> ParsecT String (Map String String) Identity Char
-> BibParser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar)
BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> String
braced (String -> String) -> BibParser String -> BibParser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BibParser String
inBraces
) (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '"')
fieldName :: BibParser String
fieldName :: BibParser String
fieldName =
String -> String
resolveAlias (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (String -> String) -> BibParser String -> BibParser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String (Map String String) Identity Char
-> BibParser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity Char
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity Char
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf "-_:+")
isBibtexKeyChar :: Char -> Bool
isBibtexKeyChar :: Char -> Bool
isBibtexKeyChar c :: Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (".:;?!`'()/*@_+=-[]*&" :: String)
bibItem :: BibParser Item
bibItem :: ParsecT String (Map String String) Identity Item
bibItem = do
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '@'
String
enttype <- (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (String -> String) -> BibParser String -> BibParser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String (Map String String) Identity Char
-> BibParser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '{'
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
String
entid <- ParsecT String (Map String String) Identity Char
-> BibParser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Char -> Bool) -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isBibtexKeyChar)
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ','
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
[(String, String)]
entfields <- BibParser (String, String)
entField BibParser (String, String)
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity [(String, String)]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
`sepEndBy` (Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ',' ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces)
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '}'
Item -> ParsecT String (Map String String) Identity Item
forall (m :: * -> *) a. Monad m => a -> m a
return (Item -> ParsecT String (Map String String) Identity Item)
-> Item -> ParsecT String (Map String String) Identity Item
forall a b. (a -> b) -> a -> b
$ String -> String -> Map String String -> Item
Item String
entid String
enttype ([(String, String)] -> Map String String
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(String, String)]
entfields)
entField :: BibParser (String, String)
entField :: BibParser (String, String)
entField = do
String
k <- BibParser String
fieldName
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '='
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
[String]
vs <- (BibParser String
expandString BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BibParser String
inQuotes BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BibParser String
inBraces BibParser String -> BibParser String -> BibParser String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> BibParser String
rawWord) BibParser String
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity [String]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
`sepBy`
ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '#' ParsecT String (Map String String) Identity Char
-> ParsecT String (Map String String) Identity ()
-> ParsecT String (Map String String) Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces)
ParsecT String (Map String String) Identity ()
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m ()
spaces
(String, String) -> BibParser (String, String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String
k, [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String]
vs)
resolveAlias :: String -> String
resolveAlias :: String -> String
resolveAlias "archiveprefix" = "eprinttype"
resolveAlias "primaryclass" = "eprintclass"
resolveAlias s :: String
s = String
s
rawWord :: BibParser String
rawWord :: BibParser String
rawWord = ParsecT String (Map String String) Identity Char
-> BibParser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String (Map String String) Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
alphaNum
expandString :: BibParser String
expandString :: BibParser String
expandString = do
String
k <- BibParser String
fieldName
Map String String
strs <- ParsecT String (Map String String) Identity (Map String String)
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
k Map String String
strs of
Just v :: String
v -> String -> BibParser String
forall (m :: * -> *) a. Monad m => a -> m a
return String
v
Nothing -> String -> BibParser String
forall (m :: * -> *) a. Monad m => a -> m a
return String
k
cistring :: String -> BibParser String
cistring :: String -> BibParser String
cistring s :: String
s = BibParser String -> BibParser String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (String -> BibParser String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
go String
s)
where go :: String -> ParsecT s u m String
go [] = String -> ParsecT s u m String
forall (m :: * -> *) a. Monad m => a -> m a
return []
go (c :: Char
c:cs :: String
cs) = do
Char
x <- Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char (Char -> Char
toLower Char
c) ParsecT s u m Char -> ParsecT s u m Char -> ParsecT s u m Char
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> ParsecT s u m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char (Char -> Char
toUpper Char
c)
String
xs <- String -> ParsecT s u m String
go String
cs
String -> ParsecT s u m String
forall (m :: * -> *) a. Monad m => a -> m a
return (Char
xChar -> String -> String
forall a. a -> [a] -> [a]
:String
xs)
resolveCrossRefs :: Bool -> [Item] -> [Item]
resolveCrossRefs :: Bool -> [Item] -> [Item]
resolveCrossRefs isBibtex :: Bool
isBibtex entries :: [Item]
entries =
(Item -> Item) -> [Item] -> [Item]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> [Item] -> Item -> Item
resolveCrossRef Bool
isBibtex [Item]
entries) [Item]
entries
splitKeys :: String -> [String]
splitKeys :: String -> [String]
splitKeys = (Char -> Bool) -> String -> [String]
forall a. (a -> Bool) -> [a] -> [[a]]
wordsBy (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ' ' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ',')
getXrefFields :: Bool -> Item -> [Item] -> String -> [(String, String)]
getXrefFields :: Bool -> Item -> [Item] -> String -> [(String, String)]
getXrefFields isBibtex :: Bool
isBibtex baseEntry :: Item
baseEntry entries :: [Item]
entries keys :: String
keys = do
let keys' :: [String]
keys' = String -> [String]
splitKeys String
keys
Item
xrefEntry <- [Item
e | Item
e <- [Item]
entries, Item -> String
identifier Item
e String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
keys']
(k :: String
k, v :: String
v) <- Map String String -> [(String, String)]
forall k a. Map k a -> [(k, a)]
Map.toList (Map String String -> [(String, String)])
-> Map String String -> [(String, String)]
forall a b. (a -> b) -> a -> b
$ Item -> Map String String
fields Item
xrefEntry
if String
k String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "crossref" Bool -> Bool -> Bool
|| String
k String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "xdata"
then do
[(String, String)]
xs <- (String -> [(String, String)]) -> [String] -> [[(String, String)]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Bool -> Item -> [Item] -> String -> [(String, String)]
getXrefFields Bool
isBibtex Item
baseEntry [Item]
entries)
(String -> [String]
splitKeys String
v)
(x :: String
x, y :: String
y) <- [(String, String)]
xs
Bool -> [()]
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> [()]) -> Bool -> [()]
forall a b. (a -> b) -> a -> b
$ Maybe String -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe String -> Bool) -> Maybe String -> Bool
forall a b. (a -> b) -> a -> b
$ String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
x (Map String String -> Maybe String)
-> Map String String -> Maybe String
forall a b. (a -> b) -> a -> b
$ Item -> Map String String
fields Item
xrefEntry
(String, String) -> [(String, String)]
forall (m :: * -> *) a. Monad m => a -> m a
return (String
x, String
y)
else do
String
k' <- if Bool
isBibtex
then String -> [String]
forall (m :: * -> *) a. Monad m => a -> m a
return String
k
else String -> String -> String -> [String]
transformKey (Item -> String
entryType Item
xrefEntry) (Item -> String
entryType Item
baseEntry) String
k
Bool -> [()]
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> [()]) -> Bool -> [()]
forall a b. (a -> b) -> a -> b
$ Maybe String -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe String -> Bool) -> Maybe String -> Bool
forall a b. (a -> b) -> a -> b
$ String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
k' (Map String String -> Maybe String)
-> Map String String -> Maybe String
forall a b. (a -> b) -> a -> b
$ Item -> Map String String
fields Item
baseEntry
(String, String) -> [(String, String)]
forall (m :: * -> *) a. Monad m => a -> m a
return (String
k',String
v)
resolveCrossRef :: Bool -> [Item] -> Item -> Item
resolveCrossRef :: Bool -> [Item] -> Item -> Item
resolveCrossRef isBibtex :: Bool
isBibtex entries :: [Item]
entries entry :: Item
entry =
(String -> String -> Item -> Item)
-> Item -> Map String String -> Item
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey String -> String -> Item -> Item
forall a. (Eq a, IsString a) => a -> String -> Item -> Item
go Item
entry (Item -> Map String String
fields Item
entry)
where go :: a -> String -> Item -> Item
go key :: a
key val :: String
val entry' :: Item
entry' =
if a
key a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== "crossref" Bool -> Bool -> Bool
|| a
key a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== "xdata"
then Item
entry'{ fields :: Map String String
fields = Item -> Map String String
fields Item
entry' Map String String -> Map String String -> Map String String
forall a. Semigroup a => a -> a -> a
<>
[(String, String)] -> Map String String
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList (Bool -> Item -> [Item] -> String -> [(String, String)]
getXrefFields Bool
isBibtex
Item
entry [Item]
entries String
val) }
else Item
entry'
transformKey :: String -> String -> String -> [String]
transformKey :: String -> String -> String -> [String]
transformKey _ _ "ids" = []
transformKey _ _ "crossref" = []
transformKey _ _ "xref" = []
transformKey _ _ "entryset" = []
transformKey _ _ "entrysubtype" = []
transformKey _ _ "execute" = []
transformKey _ _ "label" = []
transformKey _ _ "options" = []
transformKey _ _ "presort" = []
transformKey _ _ "related" = []
transformKey _ _ "relatedoptions" = []
transformKey _ _ "relatedstring" = []
transformKey _ _ "relatedtype" = []
transformKey _ _ "shorthand" = []
transformKey _ _ "shorthandintro" = []
transformKey _ _ "sortkey" = []
transformKey x :: String
x y :: String
y "author"
| String
x String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["mvbook", "book"] Bool -> Bool -> Bool
&&
String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["inbook", "bookinbook", "suppbook"] = ["bookauthor", "author"]
transformKey x :: String
x y :: String
y "author"
| String
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "mvbook" Bool -> Bool -> Bool
&& String
y String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "book" = ["bookauthor", "author"]
transformKey "mvbook" y :: String
y z :: String
z
| String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["book", "inbook", "bookinbook", "suppbook"] = String -> [String]
standardTrans String
z
transformKey x :: String
x y :: String
y z :: String
z
| String
x String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["mvcollection", "mvreference"] Bool -> Bool -> Bool
&&
String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["collection", "reference", "incollection", "inreference",
"suppcollection"] = String -> [String]
standardTrans String
z
transformKey "mvproceedings" y :: String
y z :: String
z
| String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["proceedings", "inproceedings"] = String -> [String]
standardTrans String
z
transformKey "book" y :: String
y z :: String
z
| String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["inbook", "bookinbook", "suppbook"] = String -> [String]
bookTrans String
z
transformKey x :: String
x y :: String
y z :: String
z
| String
x String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["collection", "reference"] Bool -> Bool -> Bool
&&
String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["incollection", "inreference", "suppcollection"] = String -> [String]
bookTrans String
z
transformKey "proceedings" "inproceedings" z :: String
z = String -> [String]
bookTrans String
z
transformKey "periodical" y :: String
y z :: String
z
| String
y String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["article", "suppperiodical"] =
case String
z of
"title" -> ["journaltitle"]
"subtitle" -> ["journalsubtitle"]
"shorttitle" -> []
"sorttitle" -> []
"indextitle" -> []
"indexsorttitle" -> []
_ -> [String
z]
transformKey _ _ x :: String
x = [String
x]
standardTrans :: String -> [String]
standardTrans :: String -> [String]
standardTrans z :: String
z =
case String
z of
"title" -> ["maintitle"]
"subtitle" -> ["mainsubtitle"]
"titleaddon" -> ["maintitleaddon"]
"shorttitle" -> []
"sorttitle" -> []
"indextitle" -> []
"indexsorttitle" -> []
_ -> [String
z]
bookTrans :: String -> [String]
bookTrans :: String -> [String]
bookTrans z :: String
z =
case String
z of
"title" -> ["booktitle"]
"subtitle" -> ["booksubtitle"]
"titleaddon" -> ["booktitleaddon"]
"shorttitle" -> []
"sorttitle" -> []
"indextitle" -> []
"indexsorttitle" -> []
_ -> [String
z]
data Lang = Lang String String
langToLocale :: Lang -> String
langToLocale :: Lang -> String
langToLocale (Lang x :: String
x y :: String
y) = String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ (if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
y then [] else '-'Char -> String -> String
forall a. a -> [a] -> [a]
:String
y)
resolveKey :: Lang -> Formatted -> Formatted
resolveKey :: Lang -> Formatted -> Formatted
resolveKey lang :: Lang
lang (Formatted ils :: [Inline]
ils) = [Inline] -> Formatted
Formatted ((Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
Walk.walk Inline -> Inline
go [Inline]
ils)
where go :: Inline -> Inline
go (Str s :: Text
s) = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Lang -> String -> String
resolveKey' Lang
lang (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
s
go x :: Inline
x = Inline
x
resolveKey' :: Lang -> String -> String
resolveKey' :: Lang -> String -> String
resolveKey' (Lang "ca" "AD") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"inpreparation" -> "en preparació"
"submitted" -> "enviat"
"forthcoming" -> "disponible en breu"
"inpress" -> "a impremta"
"prepublished" -> "pre-publicat"
"mathesis" -> "tesi de màster"
"phdthesis" -> "tesi doctoral"
"candthesis" -> "tesi de candidatura"
"techreport" -> "informe tècnic"
"resreport" -> "informe de recerca"
"software" -> "programari"
"datacd" -> "CD de dades"
"audiocd" -> "CD d’àudio"
"patent" -> "patent"
"patentde" -> "patent alemana"
"patenteu" -> "patent europea"
"patentfr" -> "patent francesa"
"patentuk" -> "patent britànica"
"patentus" -> "patent estatunidenca"
"patreq" -> "soŀlicitud de patent"
"patreqde" -> "soŀlicitud de patent alemana"
"patreqeu" -> "soŀlicitud de patent europea"
"patreqfr" -> "soŀlicitud de patent francesa"
"patrequk" -> "soŀlicitud de patent britànica"
"patrequs" -> "soŀlicitud de patent estatunidenca"
"countryde" -> "Alemanya"
"countryeu" -> "Unió Europea"
"countryep" -> "Unió Europea"
"countryfr" -> "França"
"countryuk" -> "Regne Unit"
"countryus" -> "Estats Units d’Amèrica"
"newseries" -> "sèrie nova"
"oldseries" -> "sèrie antiga"
_ -> String
k
resolveKey' (Lang "da" "DK") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"forthcoming" -> "kommende"
"inpress" -> "i tryk"
"mathesis" -> "speciale"
"phdthesis" -> "ph.d.-afhandling"
"candthesis" -> "kandidatafhandling"
"techreport" -> "teknisk rapport"
"resreport" -> "forskningsrapport"
"software" -> "software"
"datacd" -> "data-cd"
"audiocd" -> "lyd-cd"
"patent" -> "patent"
"patentde" -> "tysk patent"
"patenteu" -> "europæisk patent"
"patentfr" -> "fransk patent"
"patentuk" -> "britisk patent"
"patentus" -> "amerikansk patent"
"patreq" -> "ansøgning om patent"
"patreqde" -> "ansøgning om tysk patent"
"patreqeu" -> "ansøgning om europæisk patent"
"patreqfr" -> "ansøgning om fransk patent"
"patrequk" -> "ansøgning om britisk patent"
"patrequs" -> "ansøgning om amerikansk patent"
"countryde" -> "Tyskland"
"countryeu" -> "Europæiske Union"
"countryep" -> "Europæiske Union"
"countryfr" -> "Frankrig"
"countryuk" -> "Storbritanien"
"countryus" -> "USA"
"newseries" -> "ny serie"
"oldseries" -> "gammel serie"
_ -> String
k
resolveKey' (Lang "de" "DE") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"inpreparation" -> "in Vorbereitung"
"submitted" -> "eingereicht"
"forthcoming" -> "im Erscheinen"
"inpress" -> "im Druck"
"prepublished" -> "Vorveröffentlichung"
"mathesis" -> "Magisterarbeit"
"phdthesis" -> "Dissertation"
"techreport" -> "Technischer Bericht"
"resreport" -> "Forschungsbericht"
"software" -> "Computer-Software"
"datacd" -> "CD-ROM"
"audiocd" -> "Audio-CD"
"patent" -> "Patent"
"patentde" -> "deutsches Patent"
"patenteu" -> "europäisches Patent"
"patentfr" -> "französisches Patent"
"patentuk" -> "britisches Patent"
"patentus" -> "US-Patent"
"patreq" -> "Patentanmeldung"
"patreqde" -> "deutsche Patentanmeldung"
"patreqeu" -> "europäische Patentanmeldung"
"patreqfr" -> "französische Patentanmeldung"
"patrequk" -> "britische Patentanmeldung"
"patrequs" -> "US-Patentanmeldung"
"countryde" -> "Deutschland"
"countryeu" -> "Europäische Union"
"countryep" -> "Europäische Union"
"countryfr" -> "Frankreich"
"countryuk" -> "Großbritannien"
"countryus" -> "USA"
"newseries" -> "neue Folge"
"oldseries" -> "alte Folge"
_ -> String
k
resolveKey' (Lang "en" "US") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"audiocd" -> "audio CD"
"by" -> "by"
"candthesis" -> "Candidate thesis"
"countryde" -> "Germany"
"countryep" -> "European Union"
"countryeu" -> "European Union"
"countryfr" -> "France"
"countryuk" -> "United Kingdom"
"countryus" -> "United States of America"
"datacd" -> "data CD"
"edition" -> "ed."
"forthcoming" -> "forthcoming"
"inpreparation" -> "in preparation"
"inpress" -> "in press"
"introduction" -> "introduction"
"jourser" -> "ser."
"mathesis" -> "Master’s thesis"
"newseries" -> "new series"
"nodate" -> "n. d."
"number" -> "no."
"numbers" -> "nos."
"oldseries" -> "old series"
"patent" -> "patent"
"patentde" -> "German patent"
"patenteu" -> "European patent"
"patentfr" -> "French patent"
"patentuk" -> "British patent"
"patentus" -> "U.S. patent"
"patreq" -> "patent request"
"patreqde" -> "German patent request"
"patreqeu" -> "European patent request"
"patreqfr" -> "French patent request"
"patrequk" -> "British patent request"
"patrequs" -> "U.S. patent request"
"phdthesis" -> "PhD thesis"
"prepublished" -> "pre-published"
"pseudonym" -> "pseud."
"recorded" -> "recorded"
"resreport" -> "research report"
"reviewof" -> "Review of"
"revisededition" -> "rev. ed."
"software" -> "computer software"
"submitted" -> "submitted"
"techreport" -> "technical report"
"volume" -> "vol."
_ -> String
k
resolveKey' (Lang "es" "ES") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"forthcoming" -> "previsto"
"inpress" -> "en imprenta"
"mathesis" -> "Tesis de licenciatura"
"phdthesis" -> "Tesis doctoral"
"techreport" -> "informe técnico"
"patent" -> "patente"
"patentde" -> "patente alemana"
"patenteu" -> "patente europea"
"patentfr" -> "patente francesa"
"patentuk" -> "patente británica"
"patentus" -> "patente americana"
"patreq" -> "solicitud de patente"
"patreqde" -> "solicitud de patente alemana"
"patreqeu" -> "solicitud de patente europea"
"patreqfr" -> "solicitud de patente francesa"
"patrequk" -> "solicitud de patente británica"
"patrequs" -> "solicitud de patente americana"
"countryde" -> "Alemania"
"countryeu" -> "Unión Europea"
"countryep" -> "Unión Europea"
"countryfr" -> "Francia"
"countryuk" -> "Reino Unido"
"countryus" -> "Estados Unidos de América"
"newseries" -> "nueva época"
"oldseries" -> "antigua época"
_ -> String
k
resolveKey' (Lang "fi" "FI") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"forthcoming" -> "tulossa"
"inpress" -> "painossa"
"mathesis" -> "tutkielma"
"phdthesis" -> "tohtorinväitöskirja"
"candthesis" -> "kandidat"
"techreport" -> "tekninen raportti"
"resreport" -> "tutkimusraportti"
"software" -> "ohjelmisto"
"datacd" -> "data-CD"
"audiocd" -> "ääni-CD"
"patent" -> "patentti"
"patentde" -> "saksalainen patentti"
"patenteu" -> "Euroopan Unionin patentti"
"patentfr" -> "ranskalainen patentti"
"patentuk" -> "englantilainen patentti"
"patentus" -> "yhdysvaltalainen patentti"
"patreq" -> "patenttihakemus"
"patreqde" -> "saksalainen patenttihakemus"
"patreqeu" -> "Euroopan Unionin patenttihakemus"
"patreqfr" -> "ranskalainen patenttihakemus"
"patrequk" -> "englantilainen patenttihakemus"
"patrequs" -> "yhdysvaltalainen patenttihakemus"
"countryde" -> "Saksa"
"countryeu" -> "Euroopan Unioni"
"countryep" -> "Euroopan Unioni"
"countryfr" -> "Ranska"
"countryuk" -> "Iso-Britannia"
"countryus" -> "Yhdysvallat"
"newseries" -> "uusi sarja"
"oldseries" -> "vanha sarja"
_ -> String
k
resolveKey' (Lang "fr" "FR") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"inpreparation" -> "en préparation"
"submitted" -> "soumis"
"forthcoming" -> "à paraître"
"inpress" -> "sous presse"
"prepublished" -> "prépublié"
"mathesis" -> "mémoire de master"
"phdthesis" -> "thèse de doctorat"
"candthesis" -> "thèse de candidature"
"techreport" -> "rapport technique"
"resreport" -> "rapport scientifique"
"software" -> "logiciel"
"datacd" -> "cédérom"
"audiocd" -> "disque compact audio"
"patent" -> "brevet"
"patentde" -> "brevet allemand"
"patenteu" -> "brevet européen"
"patentfr" -> "brevet français"
"patentuk" -> "brevet britannique"
"patentus" -> "brevet américain"
"patreq" -> "demande de brevet"
"patreqde" -> "demande de brevet allemand"
"patreqeu" -> "demande de brevet européen"
"patreqfr" -> "demande de brevet français"
"patrequk" -> "demande de brevet britannique"
"patrequs" -> "demande de brevet américain"
"countryde" -> "Allemagne"
"countryeu" -> "Union européenne"
"countryep" -> "Union européenne"
"countryfr" -> "France"
"countryuk" -> "Royaume-Uni"
"countryus" -> "États-Unis"
"newseries" -> "nouvelle série"
"oldseries" -> "ancienne série"
_ -> String
k
resolveKey' (Lang "it" "IT") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"forthcoming" -> "futuro"
"inpress" -> "in stampa"
"mathesis" -> "tesi di laurea magistrale"
"phdthesis" -> "tesi di dottorato"
"techreport" -> "rapporto tecnico"
"resreport" -> "rapporto di ricerca"
"patent" -> "brevetto"
"patentde" -> "brevetto tedesco"
"patenteu" -> "brevetto europeo"
"patentfr" -> "brevetto francese"
"patentuk" -> "brevetto britannico"
"patentus" -> "brevetto americano"
"patreq" -> "brevetto richiesto"
"patreqde" -> "brevetto tedesco richiesto"
"patreqeu" -> "brevetto europeo richiesto"
"patreqfr" -> "brevetto francese richiesto"
"patrequk" -> "brevetto britannico richiesto"
"patrequs" -> "brevetto U.S.A. richiesto"
"countryde" -> "Germania"
"countryeu" -> "Unione Europea"
"countryep" -> "Unione Europea"
"countryfr" -> "Francia"
"countryuk" -> "Regno Unito"
"countryus" -> "Stati Uniti d’America"
"newseries" -> "nuova serie"
"oldseries" -> "vecchia serie"
_ -> String
k
resolveKey' (Lang "nl" "NL") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"inpreparation" -> "in voorbereiding"
"submitted" -> "ingediend"
"forthcoming" -> "onderweg"
"inpress" -> "in druk"
"prepublished" -> "voorpublicatie"
"mathesis" -> "masterscriptie"
"phdthesis" -> "proefschrift"
"techreport" -> "technisch rapport"
"resreport" -> "onderzoeksrapport"
"software" -> "computersoftware"
"datacd" -> "cd-rom"
"audiocd" -> "audio-cd"
"patent" -> "patent"
"patentde" -> "Duits patent"
"patenteu" -> "Europees patent"
"patentfr" -> "Frans patent"
"patentuk" -> "Brits patent"
"patentus" -> "Amerikaans patent"
"patreq" -> "patentaanvraag"
"patreqde" -> "Duitse patentaanvraag"
"patreqeu" -> "Europese patentaanvraag"
"patreqfr" -> "Franse patentaanvraag"
"patrequk" -> "Britse patentaanvraag"
"patrequs" -> "Amerikaanse patentaanvraag"
"countryde" -> "Duitsland"
"countryeu" -> "Europese Unie"
"countryep" -> "Europese Unie"
"countryfr" -> "Frankrijk"
"countryuk" -> "Verenigd Koninkrijk"
"countryus" -> "Verenigde Staten van Amerika"
"newseries" -> "nieuwe reeks"
"oldseries" -> "oude reeks"
_ -> String
k
resolveKey' (Lang "pl" "PL") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"inpreparation" -> "przygotowanie"
"submitted" -> "prezentacja"
"forthcoming" -> "przygotowanie"
"inpress" -> "wydrukowane"
"prepublished" -> "przedwydanie"
"mathesis" -> "praca magisterska"
"phdthesis" -> "praca doktorska"
"techreport" -> "sprawozdanie techniczne"
"resreport" -> "sprawozdanie naukowe"
"software" -> "oprogramowanie"
"datacd" -> "CD-ROM"
"audiocd" -> "audio CD"
"patent" -> "patent"
"patentde" -> "patent Niemiec"
"patenteu" -> "patent Europy"
"patentfr" -> "patent Francji"
"patentuk" -> "patent Wielkiej Brytanji"
"patentus" -> "patent USA"
"patreq" -> "podanie na patent"
"patreqeu" -> "podanie na patent Europy"
"patrequs" -> "podanie na patent USA"
"countryde" -> "Niemcy"
"countryeu" -> "Unia Europejska"
"countryep" -> "Unia Europejska"
"countryfr" -> "Francja"
"countryuk" -> "Wielka Brytania"
"countryus" -> "Stany Zjednoczone Ameryki"
"newseries" -> "nowa serja"
"oldseries" -> "stara serja"
_ -> String
k
resolveKey' (Lang "pt" "PT") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"techreport" -> "relatório técnico"
"resreport" -> "relatório de pesquisa"
"software" -> "software"
"datacd" -> "CD-ROM"
"patent" -> "patente"
"patentde" -> "patente alemã"
"patenteu" -> "patente européia"
"patentfr" -> "patente francesa"
"patentuk" -> "patente britânica"
"patentus" -> "patente americana"
"patreq" -> "pedido de patente"
"patreqde" -> "pedido de patente alemã"
"patreqeu" -> "pedido de patente européia"
"patreqfr" -> "pedido de patente francesa"
"patrequk" -> "pedido de patente britânica"
"patrequs" -> "pedido de patente americana"
"countryde" -> "Alemanha"
"countryeu" -> "União Europeia"
"countryep" -> "União Europeia"
"countryfr" -> "França"
"countryuk" -> "Reino Unido"
"countryus" -> "Estados Unidos da América"
"newseries" -> "nova série"
"oldseries" -> "série antiga"
"forthcoming" -> "a publicar"
"inpress" -> "na imprensa"
"mathesis" -> "tese de mestrado"
"phdthesis" -> "tese de doutoramento"
"audiocd" -> "CD áudio"
_ -> String
k
resolveKey' (Lang "pt" "BR") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"techreport" -> "relatório técnico"
"resreport" -> "relatório de pesquisa"
"software" -> "software"
"datacd" -> "CD-ROM"
"patent" -> "patente"
"patentde" -> "patente alemã"
"patenteu" -> "patente européia"
"patentfr" -> "patente francesa"
"patentuk" -> "patente britânica"
"patentus" -> "patente americana"
"patreq" -> "pedido de patente"
"patreqde" -> "pedido de patente alemã"
"patreqeu" -> "pedido de patente européia"
"patreqfr" -> "pedido de patente francesa"
"patrequk" -> "pedido de patente britânica"
"patrequs" -> "pedido de patente americana"
"countryde" -> "Alemanha"
"countryeu" -> "União Europeia"
"countryep" -> "União Europeia"
"countryfr" -> "França"
"countryuk" -> "Reino Unido"
"countryus" -> "Estados Unidos da América"
"newseries" -> "nova série"
"oldseries" -> "série antiga"
"inpreparation" -> "em preparação"
"forthcoming" -> "aceito para publicação"
"inpress" -> "no prelo"
"prepublished" -> "pré-publicado"
"mathesis" -> "dissertação de mestrado"
"phdthesis" -> "tese de doutorado"
"audiocd" -> "CD de áudio"
_ -> String
k
resolveKey' (Lang "sv" "SE") k :: String
k =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
k of
"forthcoming" -> "kommande"
"inpress" -> "i tryck"
"mathesis" -> "examensarbete"
"phdthesis" -> "doktorsavhandling"
"candthesis" -> "kandidatavhandling"
"techreport" -> "teknisk rapport"
"resreport" -> "forskningsrapport"
"software" -> "datorprogram"
"datacd" -> "data-cd"
"audiocd" -> "ljud-cd"
"patent" -> "patent"
"patentde" -> "tyskt patent"
"patenteu" -> "europeiskt patent"
"patentfr" -> "franskt patent"
"patentuk" -> "brittiskt patent"
"patentus" -> "amerikanskt patent"
"patreq" -> "patentansökan"
"patreqde" -> "ansökan om tyskt patent"
"patreqeu" -> "ansökan om europeiskt patent"
"patreqfr" -> "ansökan om franskt patent"
"patrequk" -> "ansökan om brittiskt patent"
"patrequs" -> "ansökan om amerikanskt patent"
"countryde" -> "Tyskland"
"countryeu" -> "Europeiska unionen"
"countryep" -> "Europeiska unionen"
"countryfr" -> "Frankrike"
"countryuk" -> "Storbritannien"
"countryus" -> "USA"
"newseries" -> "ny följd"
"oldseries" -> "gammal följd"
_ -> String
k
resolveKey' _ k :: String
k = Lang -> String -> String
resolveKey' (String -> String -> Lang
Lang "en" "US") String
k
parseMonth :: String -> Maybe Int
parseMonth :: String -> Maybe Int
parseMonth s :: String
s =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
s of
"jan" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 1
"feb" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 2
"mar" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 3
"apr" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 4
"may" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 5
"jun" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 6
"jul" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 7
"aug" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 8
"sep" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 9
"oct" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 10
"nov" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 11
"dec" -> Int -> Maybe Int
forall a. a -> Maybe a
Just 12
_ -> Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe Int) -> Text -> Maybe Int
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
s
data BibState = BibState{
BibState -> Bool
untitlecase :: Bool
, BibState -> Lang
localeLanguage :: Lang
}
type Bib = RWST Item () BibState Maybe
notFound :: String -> Bib a
notFound :: String -> Bib a
notFound f :: String
f = String -> Bib a
forall (m :: * -> *) a. MonadFail m => String -> m a
Prelude.fail (String -> Bib a) -> String -> Bib a
forall a b. (a -> b) -> a -> b
$ String
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ " not found"
getField :: String -> Bib Formatted
getField :: String -> Bib Formatted
getField f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> String -> Bib Formatted
latex String
x
Nothing -> String -> Bib Formatted
forall a. String -> Bib a
notFound String
f
getPeriodicalTitle :: String -> Bib Formatted
getPeriodicalTitle :: String -> Bib Formatted
getPeriodicalTitle f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> [Block] -> Bib Formatted
blocksToFormatted ([Block] -> Bib Formatted) -> [Block] -> Bib Formatted
forall a b. (a -> b) -> a -> b
$ ([Inline] -> [Inline]) -> [Block] -> [Block]
onBlocks [Inline] -> [Inline]
protectCase ([Block] -> [Block]) -> [Block] -> [Block]
forall a b. (a -> b) -> a -> b
$ String -> [Block]
latex' (String -> [Block]) -> String -> [Block]
forall a b. (a -> b) -> a -> b
$ String -> String
trim String
x
Nothing -> String -> Bib Formatted
forall a. String -> Bib a
notFound String
f
getTitle :: String -> Bib Formatted
getTitle :: String -> Bib Formatted
getTitle f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> String -> Bib Formatted
latexTitle String
x
Nothing -> String -> Bib Formatted
forall a. String -> Bib a
notFound String
f
getShortTitle :: Bool -> String -> Bib Formatted
getShortTitle :: Bool -> String -> Bib Formatted
getShortTitle requireColon :: Bool
requireColon f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
Bool
utc <- (BibState -> Bool) -> RWST Item () BibState Maybe Bool
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets BibState -> Bool
untitlecase
let processTitle :: [Block] -> [Block]
processTitle = if Bool
utc then ([Inline] -> [Inline]) -> [Block] -> [Block]
onBlocks [Inline] -> [Inline]
unTitlecase else [Block] -> [Block]
forall a. a -> a
id
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> case [Block] -> [Block]
processTitle ([Block] -> [Block]) -> [Block] -> [Block]
forall a b. (a -> b) -> a -> b
$ String -> [Block]
latex' String
x of
bs :: [Block]
bs | Bool -> Bool
not Bool
requireColon Bool -> Bool -> Bool
|| [Block] -> Bool
containsColon [Block]
bs ->
[Block] -> Bib Formatted
blocksToFormatted ([Block] -> Bib Formatted) -> [Block] -> Bib Formatted
forall a b. (a -> b) -> a -> b
$ [Block] -> [Block]
upToColon [Block]
bs
| Bool
otherwise -> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Nothing -> String -> Bib Formatted
forall a. String -> Bib a
notFound String
f
containsColon :: [Block] -> Bool
containsColon :: [Block] -> Bool
containsColon [Para xs :: [Inline]
xs] = Text -> Inline
Str ":" Inline -> [Inline] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Inline]
xs
containsColon [Plain xs :: [Inline]
xs] = [Block] -> Bool
containsColon [[Inline] -> Block
Para [Inline]
xs]
containsColon _ = Bool
False
upToColon :: [Block] -> [Block]
upToColon :: [Block] -> [Block]
upToColon [Para xs :: [Inline]
xs] = [[Inline] -> Block
Para ([Inline] -> Block) -> [Inline] -> Block
forall a b. (a -> b) -> a -> b
$ (Inline -> Bool) -> [Inline] -> [Inline]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
/= Text -> Inline
Str ":") [Inline]
xs]
upToColon [Plain xs :: [Inline]
xs] = [Block] -> [Block]
upToColon [[Inline] -> Block
Para [Inline]
xs]
upToColon bs :: [Block]
bs = [Block]
bs
getDates :: String -> Bib [RefDate]
getDates :: String -> Bib [RefDate]
getDates f :: String
f = String -> [RefDate]
parseEDTFDate (String -> [RefDate])
-> RWST Item () BibState Maybe String -> Bib [RefDate]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField String
f
isNumber :: String -> Bool
isNumber :: String -> Bool
isNumber ('-':d :: Char
d:ds :: String
ds) = (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isDigit (Char
dChar -> String -> String
forall a. a -> [a] -> [a]
:String
ds)
isNumber (d :: Char
d:ds :: String
ds) = (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isDigit (Char
dChar -> String -> String
forall a. a -> [a] -> [a]
:String
ds)
isNumber _ = Bool
False
fixLeadingDash :: String -> String
fixLeadingDash :: String -> String
fixLeadingDash (c :: Char
c:d :: Char
d:ds :: String
ds)
| (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '–' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '—') Bool -> Bool -> Bool
&& Char -> Bool
isDigit Char
d = '-'Char -> String -> String
forall a. a -> [a] -> [a]
:Char
dChar -> String -> String
forall a. a -> [a] -> [a]
:String
ds
fixLeadingDash xs :: String
xs = String
xs
getOldDates :: String -> Bib [RefDate]
getOldDates :: String -> Bib [RefDate]
getOldDates prefix :: String
prefix = do
String
year' <- String -> String
fixLeadingDash (String -> String)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField (String
prefix String -> String -> String
forall a. [a] -> [a] -> [a]
++ "year") RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return ""
Maybe Int
month' <- (String -> Maybe Int
parseMonth
(String -> Maybe Int)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField (String
prefix String -> String -> String
forall a. [a] -> [a] -> [a]
++ "month")) RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> RWST Item () BibState Maybe (Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
forall a. Maybe a
Nothing
Maybe Int
day' <- (Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe Int) -> (String -> Text) -> String -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Maybe Int)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField (String
prefix String -> String -> String
forall a. [a] -> [a] -> [a]
++ "day")) RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> RWST Item () BibState Maybe (Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
forall a. Maybe a
Nothing
String
endyear' <- (String -> String
fixLeadingDash (String -> String)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField (String
prefix String -> String -> String
forall a. [a] -> [a] -> [a]
++ "endyear"))
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return ""
Maybe Int
endmonth' <- (String -> Maybe Int
parseMonth (String -> Maybe Int)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField (String
prefix String -> String -> String
forall a. [a] -> [a] -> [a]
++ "endmonth"))
RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> RWST Item () BibState Maybe (Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
forall a. Maybe a
Nothing
Maybe Int
endday' <- (Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe Int) -> (String -> Text) -> String -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Maybe Int)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField (String
prefix String -> String -> String
forall a. [a] -> [a] -> [a]
++ "endday")) RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
-> RWST Item () BibState Maybe (Maybe Int)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> RWST Item () BibState Maybe (Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
forall a. Maybe a
Nothing
let start' :: RefDate
start' = RefDate :: Maybe Int
-> Maybe Int
-> Maybe Season
-> Maybe Int
-> Literal
-> Bool
-> RefDate
RefDate { year :: Maybe Int
year = Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe Int) -> Text -> Maybe Int
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
year'
, month :: Maybe Int
month = Maybe Int
month'
, season :: Maybe Season
season = Maybe Season
forall a. Maybe a
Nothing
, day :: Maybe Int
day = Maybe Int
day'
, other :: Literal
other = String -> Literal
Literal (String -> Literal) -> String -> Literal
forall a b. (a -> b) -> a -> b
$ if String -> Bool
isNumber String
year' then "" else String
year'
, circa :: Bool
circa = Bool
False
}
let end' :: RefDate
end' = RefDate :: Maybe Int
-> Maybe Int
-> Maybe Season
-> Maybe Int
-> Literal
-> Bool
-> RefDate
RefDate { year :: Maybe Int
year = Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text -> Maybe Int) -> Text -> Maybe Int
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
endyear'
, month :: Maybe Int
month = Maybe Int
endmonth'
, day :: Maybe Int
day = Maybe Int
endday'
, season :: Maybe Season
season = Maybe Season
forall a. Maybe a
Nothing
, other :: Literal
other = String -> Literal
Literal (String -> Literal) -> String -> Literal
forall a b. (a -> b) -> a -> b
$ if String -> Bool
isNumber String
endyear' then "" else String
endyear'
, circa :: Bool
circa = Bool
False
}
let hasyear :: RefDate -> Bool
hasyear r :: RefDate
r = Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (RefDate -> Maybe Int
year RefDate
r)
[RefDate] -> Bib [RefDate]
forall (m :: * -> *) a. Monad m => a -> m a
return ([RefDate] -> Bib [RefDate]) -> [RefDate] -> Bib [RefDate]
forall a b. (a -> b) -> a -> b
$ (RefDate -> Bool) -> [RefDate] -> [RefDate]
forall a. (a -> Bool) -> [a] -> [a]
filter RefDate -> Bool
hasyear [RefDate
start', RefDate
end']
getRawField :: String -> Bib String
getRawField :: String -> RWST Item () BibState Maybe String
getRawField f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
x
Nothing -> String -> RWST Item () BibState Maybe String
forall a. String -> Bib a
notFound String
f
getAuthorList :: Options -> String -> Bib [Agent]
getAuthorList :: [(String, String)] -> String -> Bib [Agent]
getAuthorList opts :: [(String, String)]
opts f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> [(String, String)] -> String -> Bib [Agent]
latexAuthors [(String, String)]
opts String
x
Nothing -> String -> Bib [Agent]
forall a. String -> Bib a
notFound String
f
getLiteralList :: String -> Bib [Formatted]
getLiteralList :: String -> Bib [Formatted]
getLiteralList f :: String
f = do
Map String String
fs <- (Item -> Map String String)
-> RWST Item () BibState Maybe (Map String String)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> Map String String
fields
case String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup String
f Map String String
fs of
Just x :: String
x -> [Block] -> Bib [Formatted]
toLiteralList ([Block] -> Bib [Formatted]) -> [Block] -> Bib [Formatted]
forall a b. (a -> b) -> a -> b
$ String -> [Block]
latex' String
x
Nothing -> String -> Bib [Formatted]
forall a. String -> Bib a
notFound String
f
getLiteralList' :: String -> Bib Formatted
getLiteralList' :: String -> Bib Formatted
getLiteralList' f :: String
f = ([Inline] -> Formatted
Formatted ([Inline] -> Formatted)
-> ([Formatted] -> [Inline]) -> [Formatted] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Text -> Inline
Str ";", Inline
Space] ([[Inline]] -> [Inline])
-> ([Formatted] -> [[Inline]]) -> [Formatted] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Formatted -> [Inline]) -> [Formatted] -> [[Inline]]
forall a b. (a -> b) -> [a] -> [b]
map Formatted -> [Inline]
unFormatted)
([Formatted] -> Formatted) -> Bib [Formatted] -> Bib Formatted
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Bib [Formatted]
getLiteralList String
f
splitByAnd :: [Inline] -> [[Inline]]
splitByAnd :: [Inline] -> [[Inline]]
splitByAnd = [Inline] -> [Inline] -> [[Inline]]
forall a. Eq a => [a] -> [a] -> [[a]]
splitOn [Inline
Space, Text -> Inline
Str "and", Inline
Space]
toLiteralList :: [Block] -> Bib [Formatted]
toLiteralList :: [Block] -> Bib [Formatted]
toLiteralList [Para xs :: [Inline]
xs] =
([Inline] -> Bib Formatted) -> [[Inline]] -> Bib [Formatted]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Inline] -> Bib Formatted
inlinesToFormatted ([[Inline]] -> Bib [Formatted]) -> [[Inline]] -> Bib [Formatted]
forall a b. (a -> b) -> a -> b
$ [Inline] -> [[Inline]]
splitByAnd [Inline]
xs
toLiteralList [Plain xs :: [Inline]
xs] = [Block] -> Bib [Formatted]
toLiteralList [[Inline] -> Block
Para [Inline]
xs]
toLiteralList _ = Bib [Formatted]
forall (m :: * -> *) a. MonadPlus m => m a
mzero
toAuthorList :: Options -> [Block] -> Bib [Agent]
toAuthorList :: [(String, String)] -> [Block] -> Bib [Agent]
toAuthorList opts :: [(String, String)]
opts [Para xs :: [Inline]
xs] =
(Agent -> Bool) -> [Agent] -> [Agent]
forall a. (a -> Bool) -> [a] -> [a]
filter (Agent -> Agent -> Bool
forall a. Eq a => a -> a -> Bool
/= Agent
emptyAgent) ([Agent] -> [Agent]) -> Bib [Agent] -> Bib [Agent]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Inline] -> RWST Item () BibState Maybe Agent)
-> [[Inline]] -> Bib [Agent]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([(String, String)] -> [Inline] -> RWST Item () BibState Maybe Agent
toAuthor [(String, String)]
opts ([Inline] -> RWST Item () BibState Maybe Agent)
-> ([Inline] -> [Inline])
-> [Inline]
-> RWST Item () BibState Maybe Agent
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
addSpaceAfterPeriod)
([Inline] -> [[Inline]]
splitByAnd [Inline]
xs)
toAuthorList opts :: [(String, String)]
opts [Plain xs :: [Inline]
xs] = [(String, String)] -> [Block] -> Bib [Agent]
toAuthorList [(String, String)]
opts [[Inline] -> Block
Para [Inline]
xs]
toAuthorList _ _ = Bib [Agent]
forall (m :: * -> *) a. MonadPlus m => m a
mzero
toAuthor :: Options -> [Inline] -> Bib Agent
toAuthor :: [(String, String)] -> [Inline] -> RWST Item () BibState Maybe Agent
toAuthor _ [Str "others"] =
Agent -> RWST Item () BibState Maybe Agent
forall (m :: * -> *) a. Monad m => a -> m a
return
Agent :: [Formatted]
-> Formatted
-> Formatted
-> Formatted
-> Formatted
-> Formatted
-> Bool
-> Bool
-> Agent
Agent { givenName :: [Formatted]
givenName = []
, droppingPart :: Formatted
droppingPart = Formatted
forall a. Monoid a => a
mempty
, nonDroppingPart :: Formatted
nonDroppingPart = Formatted
forall a. Monoid a => a
mempty
, familyName :: Formatted
familyName = Formatted
forall a. Monoid a => a
mempty
, nameSuffix :: Formatted
nameSuffix = Formatted
forall a. Monoid a => a
mempty
, literal :: Formatted
literal = [Inline] -> Formatted
Formatted [Text -> Inline
Str "others"]
, commaSuffix :: Bool
commaSuffix = Bool
False
, parseNames :: Bool
parseNames = Bool
False
}
toAuthor _ [Span ("",[],[]) ils :: [Inline]
ils] =
Agent -> RWST Item () BibState Maybe Agent
forall (m :: * -> *) a. Monad m => a -> m a
return
Agent :: [Formatted]
-> Formatted
-> Formatted
-> Formatted
-> Formatted
-> Formatted
-> Bool
-> Bool
-> Agent
Agent { givenName :: [Formatted]
givenName = []
, droppingPart :: Formatted
droppingPart = Formatted
forall a. Monoid a => a
mempty
, nonDroppingPart :: Formatted
nonDroppingPart = Formatted
forall a. Monoid a => a
mempty
, familyName :: Formatted
familyName = Formatted
forall a. Monoid a => a
mempty
, nameSuffix :: Formatted
nameSuffix = Formatted
forall a. Monoid a => a
mempty
, literal :: Formatted
literal = [Inline] -> Formatted
Formatted [Inline]
ils
, commaSuffix :: Bool
commaSuffix = Bool
False
, parseNames :: Bool
parseNames = Bool
False
}
toAuthor _ ils :: [Inline]
ils@(Str ys :: Text
ys:_) | (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '=') Text
ys = do
let commaParts :: [[Inline]]
commaParts = (Inline -> Bool) -> [Inline] -> [[Inline]]
forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Inline
Str ",")
([Inline] -> [[Inline]]) -> [Inline] -> [[Inline]]
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> [Inline] -> [Inline]
splitStrWhen (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ',' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '=' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\160')
([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (a -> b) -> a -> b
$ [Inline]
ils
let addPart :: Agent -> [Inline] -> Agent
addPart ag :: Agent
ag (Str "given" : Str "=" : xs :: [Inline]
xs) =
Agent
ag{ givenName :: [Formatted]
givenName = Agent -> [Formatted]
givenName Agent
ag [Formatted] -> [Formatted] -> [Formatted]
forall a. [a] -> [a] -> [a]
++ [[Inline] -> Formatted
Formatted [Inline]
xs] }
addPart ag :: Agent
ag (Str "family" : Str "=" : xs :: [Inline]
xs) =
Agent
ag{ familyName :: Formatted
familyName = [Inline] -> Formatted
Formatted [Inline]
xs }
addPart ag :: Agent
ag (Str "prefix" : Str "=" : xs :: [Inline]
xs) =
Agent
ag{ droppingPart :: Formatted
droppingPart = [Inline] -> Formatted
Formatted [Inline]
xs }
addPart ag :: Agent
ag (Str "useprefix" : Str "=" : Str "true" : _) =
Agent
ag{ nonDroppingPart :: Formatted
nonDroppingPart = Agent -> Formatted
droppingPart Agent
ag, droppingPart :: Formatted
droppingPart = Formatted
forall a. Monoid a => a
mempty }
addPart ag :: Agent
ag (Str "suffix" : Str "=" : xs :: [Inline]
xs) =
Agent
ag{ nameSuffix :: Formatted
nameSuffix = [Inline] -> Formatted
Formatted [Inline]
xs }
addPart ag :: Agent
ag (Space : xs :: [Inline]
xs) = Agent -> [Inline] -> Agent
addPart Agent
ag [Inline]
xs
addPart ag :: Agent
ag _ = Agent
ag
Agent -> RWST Item () BibState Maybe Agent
forall (m :: * -> *) a. Monad m => a -> m a
return (Agent -> RWST Item () BibState Maybe Agent)
-> Agent -> RWST Item () BibState Maybe Agent
forall a b. (a -> b) -> a -> b
$ (Agent -> [Inline] -> Agent) -> Agent -> [[Inline]] -> Agent
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Agent -> [Inline] -> Agent
addPart Agent
emptyAgent [[Inline]]
commaParts
toAuthor opts :: [(String, String)]
opts ils :: [Inline]
ils = do
let useprefix :: Bool
useprefix = String -> [(String, String)] -> Bool
optionSet "useprefix" [(String, String)]
opts
let usecomma :: Bool
usecomma = String -> [(String, String)] -> Bool
optionSet "juniorcomma" [(String, String)]
opts
let bibtex :: Bool
bibtex = String -> [(String, String)] -> Bool
optionSet "bibtex" [(String, String)]
opts
let words' :: [Inline] -> [[Inline]]
words' = (Inline -> Bool) -> [Inline] -> [[Inline]]
forall a. (a -> Bool) -> [a] -> [[a]]
wordsBy (\x :: Inline
x -> Inline
x Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Inline
Space Bool -> Bool -> Bool
|| Inline
x Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Inline
Str "\160")
let commaParts :: [[[Inline]]]
commaParts = ([Inline] -> [[Inline]]) -> [[Inline]] -> [[[Inline]]]
forall a b. (a -> b) -> [a] -> [b]
map [Inline] -> [[Inline]]
words' ([[Inline]] -> [[[Inline]]]) -> [[Inline]] -> [[[Inline]]]
forall a b. (a -> b) -> a -> b
$ (Inline -> Bool) -> [Inline] -> [[Inline]]
forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Inline
Str ",")
([Inline] -> [[Inline]]) -> [Inline] -> [[Inline]]
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> [Inline] -> [Inline]
splitStrWhen (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ',' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\160') [Inline]
ils
let (first :: [[Inline]]
first, vonlast :: [[Inline]]
vonlast, jr :: [[Inline]]
jr) =
case [[[Inline]]]
commaParts of
[fvl :: [[Inline]]
fvl] -> let (caps' :: [[Inline]]
caps', rest' :: [[Inline]]
rest') = ([Inline] -> Bool) -> [[Inline]] -> ([[Inline]], [[Inline]])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span [Inline] -> Bool
isCapitalized [[Inline]]
fvl
in if [[Inline]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Inline]]
rest' Bool -> Bool -> Bool
&& Bool -> Bool
not ([[Inline]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Inline]]
caps')
then ([[Inline]] -> [[Inline]]
forall a. [a] -> [a]
init [[Inline]]
caps', [[[Inline]] -> [Inline]
forall a. [a] -> a
last [[Inline]]
caps'], [])
else ([[Inline]]
caps', [[Inline]]
rest', [])
[vl :: [[Inline]]
vl,f :: [[Inline]]
f] -> ([[Inline]]
f, [[Inline]]
vl, [])
(vl :: [[Inline]]
vl:j :: [[Inline]]
j:f :: [[Inline]]
f:_) -> ([[Inline]]
f, [[Inline]]
vl, [[Inline]]
j )
[] -> ([], [], [])
let (von :: [[Inline]]
von, lastname :: [[Inline]]
lastname) =
if Bool
bibtex
then case ([Inline] -> Bool) -> [[Inline]] -> ([[Inline]], [[Inline]])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span [Inline] -> Bool
isCapitalized ([[Inline]] -> ([[Inline]], [[Inline]]))
-> [[Inline]] -> ([[Inline]], [[Inline]])
forall a b. (a -> b) -> a -> b
$ [[Inline]] -> [[Inline]]
forall a. [a] -> [a]
reverse [[Inline]]
vonlast of
([],w :: [Inline]
w:ws :: [[Inline]]
ws) -> ([[Inline]] -> [[Inline]]
forall a. [a] -> [a]
reverse [[Inline]]
ws, [[Inline]
w])
(vs :: [[Inline]]
vs, ws :: [[Inline]]
ws) -> ([[Inline]] -> [[Inline]]
forall a. [a] -> [a]
reverse [[Inline]]
ws, [[Inline]] -> [[Inline]]
forall a. [a] -> [a]
reverse [[Inline]]
vs)
else case ([Inline] -> Bool) -> [[Inline]] -> ([[Inline]], [[Inline]])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break [Inline] -> Bool
isCapitalized [[Inline]]
vonlast of
(vs :: [[Inline]]
vs@(_:_), []) -> ([[Inline]] -> [[Inline]]
forall a. [a] -> [a]
init [[Inline]]
vs, [[[Inline]] -> [Inline]
forall a. [a] -> a
last [[Inline]]
vs])
(vs :: [[Inline]]
vs, ws :: [[Inline]]
ws) -> ([[Inline]]
vs, [[Inline]]
ws)
let prefix :: Formatted
prefix = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Inline
Space] [[Inline]]
von
let family :: Formatted
family = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Inline
Space] [[Inline]]
lastname
let suffix :: Formatted
suffix = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Inline
Space] [[Inline]]
jr
let givens :: [Formatted]
givens = ([Inline] -> Formatted) -> [[Inline]] -> [Formatted]
forall a b. (a -> b) -> [a] -> [b]
map [Inline] -> Formatted
Formatted [[Inline]]
first
Agent -> RWST Item () BibState Maybe Agent
forall (m :: * -> *) a. Monad m => a -> m a
return Agent :: [Formatted]
-> Formatted
-> Formatted
-> Formatted
-> Formatted
-> Formatted
-> Bool
-> Bool
-> Agent
Agent
{ givenName :: [Formatted]
givenName = [Formatted]
givens
, droppingPart :: Formatted
droppingPart = if Bool
useprefix then Formatted
forall a. Monoid a => a
mempty else Formatted
prefix
, nonDroppingPart :: Formatted
nonDroppingPart = if Bool
useprefix then Formatted
prefix else Formatted
forall a. Monoid a => a
mempty
, familyName :: Formatted
familyName = Formatted
family
, nameSuffix :: Formatted
nameSuffix = Formatted
suffix
, literal :: Formatted
literal = Formatted
forall a. Monoid a => a
mempty
, commaSuffix :: Bool
commaSuffix = Bool
usecomma
, parseNames :: Bool
parseNames = Bool
False
}
isCapitalized :: [Inline] -> Bool
isCapitalized :: [Inline] -> Bool
isCapitalized (Str (Text -> Maybe (Char, Text)
T.uncons -> Just (c :: Char
c,cs :: Text
cs)) : rest :: [Inline]
rest)
| Char -> Bool
isUpper Char
c = Bool
True
| Char -> Bool
isDigit Char
c = [Inline] -> Bool
isCapitalized (Text -> Inline
Str Text
cs Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
rest)
| Bool
otherwise = Bool
False
isCapitalized (_:rest :: [Inline]
rest) = [Inline] -> Bool
isCapitalized [Inline]
rest
isCapitalized [] = Bool
True
optionSet :: String -> Options -> Bool
optionSet :: String -> [(String, String)] -> Bool
optionSet key :: String
key opts :: [(String, String)]
opts = case String -> [(String, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
key [(String, String)]
opts of
Just "true" -> Bool
True
Just s :: String
s -> String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
forall a. Monoid a => a
mempty
_ -> Bool
False
latex' :: String -> [Block]
latex' :: String -> [Block]
latex' s :: String
s = (Inline -> Inline) -> [Block] -> [Block]
forall a b. Walkable a b => (a -> a) -> b -> b
Walk.walk Inline -> Inline
removeSoftBreak [Block]
bs
where Pandoc _ bs :: [Block]
bs = String -> Pandoc
readLaTeX String
s
removeSoftBreak :: Inline -> Inline
removeSoftBreak :: Inline -> Inline
removeSoftBreak SoftBreak = Inline
Space
removeSoftBreak x :: Inline
x = Inline
x
latex :: String -> Bib Formatted
latex :: String -> Bib Formatted
latex s :: String
s = [Block] -> Bib Formatted
blocksToFormatted ([Block] -> Bib Formatted) -> [Block] -> Bib Formatted
forall a b. (a -> b) -> a -> b
$ String -> [Block]
latex' (String -> [Block]) -> String -> [Block]
forall a b. (a -> b) -> a -> b
$ String -> String
trim String
s
latexTitle :: String -> Bib Formatted
latexTitle :: String -> Bib Formatted
latexTitle s :: String
s = do
Bool
utc <- (BibState -> Bool) -> RWST Item () BibState Maybe Bool
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets BibState -> Bool
untitlecase
let processTitle :: [Block] -> [Block]
processTitle = if Bool
utc then ([Inline] -> [Inline]) -> [Block] -> [Block]
onBlocks [Inline] -> [Inline]
unTitlecase else [Block] -> [Block]
forall a. a -> a
id
[Block] -> Bib Formatted
blocksToFormatted ([Block] -> Bib Formatted) -> [Block] -> Bib Formatted
forall a b. (a -> b) -> a -> b
$ [Block] -> [Block]
processTitle ([Block] -> [Block]) -> [Block] -> [Block]
forall a b. (a -> b) -> a -> b
$ String -> [Block]
latex' String
s
latexAuthors :: Options -> String -> Bib [Agent]
latexAuthors :: [(String, String)] -> String -> Bib [Agent]
latexAuthors opts :: [(String, String)]
opts = [(String, String)] -> [Block] -> Bib [Agent]
toAuthorList [(String, String)]
opts ([Block] -> Bib [Agent])
-> (String -> [Block]) -> String -> Bib [Agent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Block]
latex' (String -> [Block]) -> (String -> String) -> String -> [Block]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
trim
bib :: Bib Reference -> Item -> Maybe Reference
bib :: Bib Reference -> Item -> Maybe Reference
bib m :: Bib Reference
m entry :: Item
entry = (Reference, ()) -> Reference
forall a b. (a, b) -> a
fst ((Reference, ()) -> Reference)
-> Maybe (Reference, ()) -> Maybe Reference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Control.Applicative.<$> Bib Reference -> Item -> BibState -> Maybe (Reference, ())
forall (m :: * -> *) r w s a.
Monad m =>
RWST r w s m a -> r -> s -> m (a, w)
evalRWST Bib Reference
m Item
entry (Bool -> Lang -> BibState
BibState Bool
True (String -> String -> Lang
Lang "en" "US"))
toLocale :: String -> String
toLocale :: String -> String
toLocale "english" = "en-US"
toLocale "usenglish" = "en-US"
toLocale "american" = "en-US"
toLocale "british" = "en-GB"
toLocale "ukenglish" = "en-GB"
toLocale "canadian" = "en-US"
toLocale "australian" = "en-GB"
toLocale "newzealand" = "en-GB"
toLocale "afrikaans" = "af-ZA"
toLocale "arabic" = "ar"
toLocale "basque" = "eu"
toLocale "bulgarian" = "bg-BG"
toLocale "catalan" = "ca-AD"
toLocale "croatian" = "hr-HR"
toLocale "czech" = "cs-CZ"
toLocale "danish" = "da-DK"
toLocale "dutch" = "nl-NL"
toLocale "estonian" = "et-EE"
toLocale "finnish" = "fi-FI"
toLocale "canadien" = "fr-CA"
toLocale "acadian" = "fr-CA"
toLocale "french" = "fr-FR"
toLocale "francais" = "fr-FR"
toLocale "austrian" = "de-AT"
toLocale "naustrian" = "de-AT"
toLocale "german" = "de-DE"
toLocale "germanb" = "de-DE"
toLocale "ngerman" = "de-DE"
toLocale "greek" = "el-GR"
toLocale "polutonikogreek" = "el-GR"
toLocale "hebrew" = "he-IL"
toLocale "hungarian" = "hu-HU"
toLocale "icelandic" = "is-IS"
toLocale "italian" = "it-IT"
toLocale "japanese" = "ja-JP"
toLocale "latvian" = "lv-LV"
toLocale "lithuanian" = "lt-LT"
toLocale "magyar" = "hu-HU"
toLocale "mongolian" = "mn-MN"
toLocale "norsk" = "nb-NO"
toLocale "nynorsk" = "nn-NO"
toLocale "farsi" = "fa-IR"
toLocale "polish" = "pl-PL"
toLocale "brazil" = "pt-BR"
toLocale "brazilian" = "pt-BR"
toLocale "portugues" = "pt-PT"
toLocale "portuguese" = "pt-PT"
toLocale "romanian" = "ro-RO"
toLocale "russian" = "ru-RU"
toLocale "serbian" = "sr-RS"
toLocale "serbianc" = "sr-RS"
toLocale "slovak" = "sk-SK"
toLocale "slovene" = "sl-SL"
toLocale "spanish" = "es-ES"
toLocale "swedish" = "sv-SE"
toLocale "thai" = "th-TH"
toLocale "turkish" = "tr-TR"
toLocale "ukrainian" = "uk-UA"
toLocale "vietnamese" = "vi-VN"
toLocale "latin" = "la"
toLocale x :: String
x = String
x
concatWith :: Char -> [Formatted] -> Formatted
concatWith :: Char -> [Formatted] -> Formatted
concatWith sep :: Char
sep = [Inline] -> Formatted
Formatted ([Inline] -> Formatted)
-> ([Formatted] -> [Inline]) -> [Formatted] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Inline] -> [Inline] -> [Inline])
-> [Inline] -> [[Inline]] -> [Inline]
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' [Inline] -> [Inline] -> [Inline]
go [Inline]
forall a. Monoid a => a
mempty ([[Inline]] -> [Inline])
-> ([Formatted] -> [[Inline]]) -> [Formatted] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Formatted -> [Inline]) -> [Formatted] -> [[Inline]]
forall a b. (a -> b) -> [a] -> [b]
map Formatted -> [Inline]
unFormatted
where go :: [Inline] -> [Inline] -> [Inline]
go :: [Inline] -> [Inline] -> [Inline]
go accum :: [Inline]
accum [] = [Inline]
accum
go accum :: [Inline]
accum s :: [Inline]
s = case [Inline] -> [Inline]
forall a. [a] -> [a]
reverse [Inline]
accum of
[] -> [Inline]
s
(Str x :: Text
x:_)
| Bool -> Bool
not (Text -> Bool
T.null Text
x) Bool -> Bool -> Bool
&& Text -> Char
T.last Text
x Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ("!?.,:;" :: String)
-> [Inline]
accum [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ (Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
s)
_ -> [Inline]
accum [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ (Text -> Inline
Str (Char -> Text
T.singleton Char
sep) Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
s)
type Options = [(String, String)]
parseOptions :: String -> Options
parseOptions :: String -> [(String, String)]
parseOptions = (String -> (String, String)) -> [String] -> [(String, String)]
forall a b. (a -> b) -> [a] -> [b]
map String -> (String, String)
breakOpt ([String] -> [(String, String)])
-> (String -> [String]) -> String -> [(String, String)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> String -> [String]
forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==',')
where breakOpt :: String -> (String, String)
breakOpt x :: String
x = case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='=') String
x of
(w :: String
w,v :: String
v) -> ((Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
trim String
w,
(Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> String
trim (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
drop 1 String
v)
ordinalize :: Locale -> String -> String
ordinalize :: Locale -> String -> String
ordinalize locale :: Locale
locale n :: String
n =
case [CslTerm -> String
termSingular CslTerm
c | CslTerm
c <- [CslTerm]
terms, CslTerm -> String
cslTerm CslTerm
c String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== ("ordinal-" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
pad0 String
n)] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
[CslTerm -> String
termSingular CslTerm
c | CslTerm
c <- [CslTerm]
terms, CslTerm -> String
cslTerm CslTerm
c String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "ordinal"] of
(suff :: String
suff:_) -> String
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
suff
[] -> String
n
where pad0 :: String -> String
pad0 [c :: Char
c] = ['0',Char
c]
pad0 s :: String
s = String
s
terms :: [CslTerm]
terms = Locale -> [CslTerm]
localeTerms Locale
locale
itemToReference :: Lang -> Locale -> Bool -> Bool -> Item -> Maybe Reference
itemToReference :: Lang -> Locale -> Bool -> Bool -> Item -> Maybe Reference
itemToReference lang :: Lang
lang locale :: Locale
locale bibtex :: Bool
bibtex caseTransform :: Bool
caseTransform = Bib Reference -> Item -> Maybe Reference
bib (Bib Reference -> Item -> Maybe Reference)
-> Bib Reference -> Item -> Maybe Reference
forall a b. (a -> b) -> a -> b
$ do
(BibState -> BibState) -> RWST Item () BibState Maybe ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((BibState -> BibState) -> RWST Item () BibState Maybe ())
-> (BibState -> BibState) -> RWST Item () BibState Maybe ()
forall a b. (a -> b) -> a -> b
$ \st :: BibState
st -> BibState
st{ localeLanguage :: Lang
localeLanguage = Lang
lang,
untitlecase :: Bool
untitlecase = case Lang
lang of
Lang "en" _ -> Bool
caseTransform
_ -> Bool
False }
String
id' <- (Item -> String) -> RWST Item () BibState Maybe String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> String
identifier
[String]
otherIds <- ((String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
trim ([String] -> [String])
-> (String -> [String]) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> String -> [String]
forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==',') (String -> [String])
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField "ids")
RWST Item () BibState Maybe [String]
-> RWST Item () BibState Maybe [String]
-> RWST Item () BibState Maybe [String]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [String] -> RWST Item () BibState Maybe [String]
forall (m :: * -> *) a. Monad m => a -> m a
return []
String
et <- (Item -> String) -> RWST Item () BibState Maybe String
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Item -> String
entryType
Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> RWST Item () BibState Maybe ())
-> Bool -> RWST Item () BibState Maybe ()
forall a b. (a -> b) -> a -> b
$ String
et String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= "xdata"
[(String, String)]
opts <- (String -> [(String, String)]
parseOptions (String -> [(String, String)])
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe [(String, String)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField "options") RWST Item () BibState Maybe [(String, String)]
-> RWST Item () BibState Maybe [(String, String)]
-> RWST Item () BibState Maybe [(String, String)]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [(String, String)]
-> RWST Item () BibState Maybe [(String, String)]
forall (m :: * -> *) a. Monad m => a -> m a
return []
let getAuthorList' :: String -> Bib [Agent]
getAuthorList' = [(String, String)] -> String -> Bib [Agent]
getAuthorList
(("bibtex", (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Bool -> String
forall a. Show a => a -> String
show Bool
bibtex)(String, String) -> [(String, String)] -> [(String, String)]
forall a. a -> [a] -> [a]
:[(String, String)]
opts)
String
st <- String -> RWST Item () BibState Maybe String
getRawField "entrysubtype" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
Bool
isEvent <- (Bool
True Bool
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (String -> RWST Item () BibState Maybe String
getRawField "eventdate"
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
getRawField "eventtitle"
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
getRawField "venue")) RWST Item () BibState Maybe Bool
-> RWST Item () BibState Maybe Bool
-> RWST Item () BibState Maybe Bool
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> RWST Item () BibState Maybe Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Formatted
reftype' <- Lang -> Formatted -> Formatted
resolveKey Lang
lang (Formatted -> Formatted) -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Bib Formatted
getField "type" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
let (reftype :: RefType
reftype, refgenre :: Formatted
refgenre) = case String
et of
"article"
| String
st String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "magazine" -> (RefType
ArticleMagazine,Formatted
forall a. Monoid a => a
mempty)
| String
st String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "newspaper" -> (RefType
ArticleNewspaper,Formatted
forall a. Monoid a => a
mempty)
| Bool
otherwise -> (RefType
ArticleJournal,Formatted
forall a. Monoid a => a
mempty)
"book" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"booklet" -> (RefType
Pamphlet,Formatted
forall a. Monoid a => a
mempty)
"bookinbook" -> (RefType
Chapter,Formatted
forall a. Monoid a => a
mempty)
"collection" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"dataset" -> (RefType
Dataset,Formatted
forall a. Monoid a => a
mempty)
"electronic" -> (RefType
Webpage,Formatted
forall a. Monoid a => a
mempty)
"inbook" -> (RefType
Chapter,Formatted
forall a. Monoid a => a
mempty)
"incollection" -> (RefType
Chapter,Formatted
forall a. Monoid a => a
mempty)
"inreference" -> (RefType
EntryEncyclopedia,Formatted
forall a. Monoid a => a
mempty)
"inproceedings" -> (RefType
PaperConference,Formatted
forall a. Monoid a => a
mempty)
"manual" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"mastersthesis" -> (RefType
Thesis, if Formatted
reftype' Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
== Formatted
forall a. Monoid a => a
mempty
then [Inline] -> Formatted
Formatted [Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Lang -> String -> String
resolveKey' Lang
lang "mathesis"]
else Formatted
reftype')
"misc" -> (RefType
NoType,Formatted
forall a. Monoid a => a
mempty)
"mvbook" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"mvcollection" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"mvproceedings" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"mvreference" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"online" -> (RefType
Webpage,Formatted
forall a. Monoid a => a
mempty)
"patent" -> (RefType
Patent,Formatted
forall a. Monoid a => a
mempty)
"periodical"
| String
st String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "magazine" -> (RefType
ArticleMagazine,Formatted
forall a. Monoid a => a
mempty)
| String
st String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "newspaper" -> (RefType
ArticleNewspaper,Formatted
forall a. Monoid a => a
mempty)
| Bool
otherwise -> (RefType
ArticleJournal,Formatted
forall a. Monoid a => a
mempty)
"phdthesis" -> (RefType
Thesis, if Formatted
reftype' Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
== Formatted
forall a. Monoid a => a
mempty
then [Inline] -> Formatted
Formatted [Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Lang -> String -> String
resolveKey' Lang
lang "phdthesis"]
else Formatted
reftype')
"proceedings" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"reference" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"report" -> (RefType
Report,Formatted
forall a. Monoid a => a
mempty)
"software" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"suppbook" -> (RefType
Chapter,Formatted
forall a. Monoid a => a
mempty)
"suppcollection" -> (RefType
Chapter,Formatted
forall a. Monoid a => a
mempty)
"suppperiodical"
| String
st String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "magazine" -> (RefType
ArticleMagazine,Formatted
forall a. Monoid a => a
mempty)
| String
st String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "newspaper" -> (RefType
ArticleNewspaper,Formatted
forall a. Monoid a => a
mempty)
| Bool
otherwise -> (RefType
ArticleJournal,Formatted
forall a. Monoid a => a
mempty)
"techreport" -> (RefType
Report,Formatted
forall a. Monoid a => a
mempty)
"thesis" -> (RefType
Thesis,Formatted
forall a. Monoid a => a
mempty)
"unpublished" -> (if Bool
isEvent then RefType
Speech else RefType
Manuscript,Formatted
forall a. Monoid a => a
mempty)
"www" -> (RefType
Webpage,Formatted
forall a. Monoid a => a
mempty)
"artwork" -> (RefType
Graphic,Formatted
forall a. Monoid a => a
mempty)
"audio" -> (RefType
Song,Formatted
forall a. Monoid a => a
mempty)
"commentary" -> (RefType
Book,Formatted
forall a. Monoid a => a
mempty)
"image" -> (RefType
Graphic,Formatted
forall a. Monoid a => a
mempty)
"jurisdiction" -> (RefType
LegalCase,Formatted
forall a. Monoid a => a
mempty)
"legislation" -> (RefType
Legislation,Formatted
forall a. Monoid a => a
mempty)
"legal" -> (RefType
Treaty,Formatted
forall a. Monoid a => a
mempty)
"letter" -> (RefType
PersonalCommunication,Formatted
forall a. Monoid a => a
mempty)
"movie" -> (RefType
MotionPicture,Formatted
forall a. Monoid a => a
mempty)
"music" -> (RefType
Song,Formatted
forall a. Monoid a => a
mempty)
"performance" -> (RefType
Speech,Formatted
forall a. Monoid a => a
mempty)
"review" -> (RefType
Review,Formatted
forall a. Monoid a => a
mempty)
"standard" -> (RefType
Legislation,Formatted
forall a. Monoid a => a
mempty)
"video" -> (RefType
MotionPicture,Formatted
forall a. Monoid a => a
mempty)
"data" -> (RefType
Dataset,Formatted
forall a. Monoid a => a
mempty)
"letters" -> (RefType
PersonalCommunication,Formatted
forall a. Monoid a => a
mempty)
"newsarticle" -> (RefType
ArticleNewspaper,Formatted
forall a. Monoid a => a
mempty)
_ -> (RefType
NoType,Formatted
forall a. Monoid a => a
mempty)
let defaultHyphenation :: String
defaultHyphenation = case Lang
lang of
Lang x :: String
x y :: String
y -> String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ "-" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
y
let getLangId :: RWST Item () BibState Maybe String
getLangId = do
String
langid <- (String -> String
trim (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower) (String -> String)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> RWST Item () BibState Maybe String
getRawField "langid"
String
idopts <- (String -> String
trim (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower) (String -> String)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
String -> RWST Item () BibState Maybe String
getRawField "langidopts" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return ""
case (String
langid, String
idopts) of
("english","variant=british") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "british"
("english","variant=american") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "american"
("english","variant=us") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "american"
("english","variant=usmax") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "american"
("english","variant=uk") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "british"
("english","variant=australian") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "australian"
("english","variant=newzealand") -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return "newzealand"
(x :: String
x,_) -> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
x
String
hyphenation <- ((String -> String
toLocale (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower) (String -> String)
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(RWST Item () BibState Maybe String
getLangId RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
getRawField "hyphenation"))
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
[Agent]
author' <- String -> Bib [Agent]
getAuthorList' "author" Bib [Agent] -> Bib [Agent] -> Bib [Agent]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Agent] -> Bib [Agent]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[Agent]
containerAuthor' <- String -> Bib [Agent]
getAuthorList' "bookauthor" Bib [Agent] -> Bib [Agent] -> Bib [Agent]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Agent] -> Bib [Agent]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[Agent]
translator' <- String -> Bib [Agent]
getAuthorList' "translator" Bib [Agent] -> Bib [Agent] -> Bib [Agent]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Agent] -> Bib [Agent]
forall (m :: * -> *) a. Monad m => a -> m a
return []
String
editortype <- String -> RWST Item () BibState Maybe String
getRawField "editortype" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
[Agent]
editor'' <- String -> Bib [Agent]
getAuthorList' "editor" Bib [Agent] -> Bib [Agent] -> Bib [Agent]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Agent] -> Bib [Agent]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[Agent]
director'' <- String -> Bib [Agent]
getAuthorList' "director" Bib [Agent] -> Bib [Agent] -> Bib [Agent]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Agent] -> Bib [Agent]
forall (m :: * -> *) a. Monad m => a -> m a
return []
let (editor' :: [Agent]
editor', director' :: [Agent]
director') = case String
editortype of
"director" -> ([], [Agent]
editor'')
_ -> ([Agent]
editor'', [Agent]
director'')
let isArticle :: Bool
isArticle = String
et String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["article", "periodical", "suppperiodical", "review"]
let isPeriodical :: Bool
isPeriodical = String
et String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "periodical"
let isChapterlike :: Bool
isChapterlike = String
et String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem`
["inbook","incollection","inproceedings","inreference","bookinbook"]
Bool
hasMaintitle <- (Bool
True Bool
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ String -> RWST Item () BibState Maybe String
getRawField "maintitle") RWST Item () BibState Maybe Bool
-> RWST Item () BibState Maybe Bool
-> RWST Item () BibState Maybe Bool
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> RWST Item () BibState Maybe Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
let hyphenation' :: String
hyphenation' = if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
hyphenation
then String
defaultHyphenation
else String
hyphenation
let la :: String
la = case (Char -> Bool) -> String -> [String]
forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '-') String
hyphenation' of
(x :: String
x:_) -> String
x
[] -> String
forall a. Monoid a => a
mempty
(BibState -> BibState) -> RWST Item () BibState Maybe ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((BibState -> BibState) -> RWST Item () BibState Maybe ())
-> (BibState -> BibState) -> RWST Item () BibState Maybe ()
forall a b. (a -> b) -> a -> b
$ \s :: BibState
s -> BibState
s{ untitlecase :: Bool
untitlecase = Bool
caseTransform Bool -> Bool -> Bool
&& String
la String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "en" }
Formatted
title' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isPeriodical RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "issuetitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "maintitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getTitle "title"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
subtitle' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isPeriodical RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "issuesubtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "mainsubtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getTitle "subtitle"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
titleaddon' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "maintitleaddon")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getTitle "titleaddon"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
volumeTitle' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "title")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "booktitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
volumeSubtitle' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "subtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "booksubtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
volumeTitleAddon' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "titleaddon")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
hasMaintitle RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "booktitleaddon")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
containerTitle' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isPeriodical RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getPeriodicalTitle "title")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "maintitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "booktitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getPeriodicalTitle "journaltitle"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getPeriodicalTitle "journal"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
containerSubtitle' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isPeriodical RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getPeriodicalTitle "subtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "mainsubtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "booksubtitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getPeriodicalTitle "journalsubtitle"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
containerTitleAddon' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isPeriodical RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getPeriodicalTitle "titleaddon")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "maintitleaddon")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isChapterlike RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getTitle "booktitleaddon")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
containerTitleShort' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isPeriodical RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe () -> RWST Item () BibState Maybe ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
hasMaintitle)
RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Bib Formatted
getField "shorttitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getPeriodicalTitle "shortjournal"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
let fixSeriesTitle :: Formatted -> Formatted
fixSeriesTitle (Formatted [Str xs :: Text
xs]) | (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isDigit Text
xs =
[Inline] -> Formatted
Formatted [Text -> Inline
Str (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Locale -> String -> String
ordinalize Locale
locale (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
xs),
Inline
Space, Text -> Inline
Str (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Lang -> String -> String
resolveKey' Lang
lang "ser.")]
fixSeriesTitle x :: Formatted
x = Formatted
x
Formatted
seriesTitle' <- (Formatted -> Formatted
fixSeriesTitle (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lang -> Formatted -> Formatted
resolveKey Lang
lang) (Formatted -> Formatted) -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
String -> Bib Formatted
getTitle "series" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
shortTitle' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not Bool
hasMaintitle Bool -> Bool -> Bool
|| Bool
isChapterlike) RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
String -> Bib Formatted
getTitle "shorttitle")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> if (Formatted
subtitle' Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
/= Formatted
forall a. Monoid a => a
mempty Bool -> Bool -> Bool
|| Formatted
titleaddon' Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
/= Formatted
forall a. Monoid a => a
mempty) Bool -> Bool -> Bool
&&
Bool -> Bool
not Bool
hasMaintitle
then Bool -> String -> Bib Formatted
getShortTitle Bool
False "title"
else Bool -> String -> Bib Formatted
getShortTitle Bool
True "title"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
eventTitle' <- String -> Bib Formatted
getTitle "eventtitle" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
origTitle' <- String -> Bib Formatted
getTitle "origtitle" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
[Maybe Formatted]
pubfields <- (String -> RWST Item () BibState Maybe (Maybe Formatted))
-> [String] -> RWST Item () BibState Maybe [Maybe Formatted]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\f :: String
f -> Formatted -> Maybe Formatted
forall a. a -> Maybe a
Just (Formatted -> Maybe Formatted)
-> Bib Formatted -> RWST Item () BibState Maybe (Maybe Formatted)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap`
(if Bool
bibtex Bool -> Bool -> Bool
|| String
f String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "howpublished"
then String -> Bib Formatted
getField String
f
else String -> Bib Formatted
getLiteralList' String
f)
RWST Item () BibState Maybe (Maybe Formatted)
-> RWST Item () BibState Maybe (Maybe Formatted)
-> RWST Item () BibState Maybe (Maybe Formatted)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Formatted -> RWST Item () BibState Maybe (Maybe Formatted)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Formatted
forall a. Maybe a
Nothing)
["school","institution","organization", "howpublished","publisher"]
let publisher' :: Formatted
publisher' = Char -> [Formatted] -> Formatted
concatWith ';' ([Formatted] -> Formatted) -> [Formatted] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Maybe Formatted] -> [Formatted]
forall a. [Maybe a] -> [a]
catMaybes [Maybe Formatted]
pubfields
Formatted
origpublisher' <- String -> Bib Formatted
getField "origpublisher" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
venue' <- String -> Bib Formatted
getField "venue" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
address' <- (if Bool
bibtex
then String -> Bib Formatted
getField "address"
else String -> Bib Formatted
getLiteralList' "address"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (String
et String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= "patent") RWST Item () BibState Maybe () -> Bib Formatted -> Bib Formatted
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
String -> Bib Formatted
getLiteralList' "location"))
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
origLocation' <- (if Bool
bibtex
then String -> Bib Formatted
getField "origlocation"
else String -> Bib Formatted
getLiteralList' "origlocation")
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
jurisdiction' <- if String
et String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "patent"
then ((Char -> [Formatted] -> Formatted
concatWith ';' ([Formatted] -> Formatted)
-> ([Formatted] -> [Formatted]) -> [Formatted] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Formatted -> Formatted) -> [Formatted] -> [Formatted]
forall a b. (a -> b) -> [a] -> [b]
map (Lang -> Formatted -> Formatted
resolveKey Lang
lang)) ([Formatted] -> Formatted) -> Bib [Formatted] -> Bib Formatted
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
String -> Bib [Formatted]
getLiteralList "location") Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
else Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
pages' <- String -> Bib Formatted
getField "pages" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
volume' <- String -> Bib Formatted
getField "volume" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
part' <- String -> Bib Formatted
getField "part" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
volumes' <- String -> Bib Formatted
getField "volumes" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
pagetotal' <- String -> Bib Formatted
getField "pagetotal" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
chapter' <- String -> Bib Formatted
getField "chapter" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
edition' <- String -> Bib Formatted
getField "edition" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
version' <- String -> Bib Formatted
getField "version" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
(number' :: Formatted
number', collectionNumber' :: Formatted
collectionNumber', issue' :: Formatted
issue') <-
(String -> Bib Formatted
getField "number" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty) Bib Formatted
-> (Formatted
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted))
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \x :: Formatted
x ->
if String
et String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["book","collection","proceedings","reference",
"mvbook","mvcollection","mvproceedings", "mvreference",
"bookinbook","inbook", "incollection","inproceedings",
"inreference", "suppbook","suppcollection"]
then (Formatted, Formatted, Formatted)
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (m :: * -> *) a. Monad m => a -> m a
return (Formatted
forall a. Monoid a => a
mempty,Formatted
x,Formatted
forall a. Monoid a => a
mempty)
else if Bool
isArticle
then (String -> Bib Formatted
getField "issue" Bib Formatted
-> (Formatted
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted))
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \y :: Formatted
y ->
(Formatted, Formatted, Formatted)
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (m :: * -> *) a. Monad m => a -> m a
return (Formatted
forall a. Monoid a => a
mempty,Formatted
forall a. Monoid a => a
mempty,Char -> [Formatted] -> Formatted
concatWith ',' [Formatted
x,Formatted
y]))
RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Formatted, Formatted, Formatted)
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (m :: * -> *) a. Monad m => a -> m a
return (Formatted
forall a. Monoid a => a
mempty,Formatted
forall a. Monoid a => a
mempty,Formatted
x)
else (Formatted, Formatted, Formatted)
-> RWST Item () BibState Maybe (Formatted, Formatted, Formatted)
forall (m :: * -> *) a. Monad m => a -> m a
return (Formatted
x,Formatted
forall a. Monoid a => a
mempty,Formatted
forall a. Monoid a => a
mempty)
[RefDate]
issued' <- String -> Bib [RefDate]
getDates "date" Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib [RefDate]
getOldDates String
forall a. Monoid a => a
mempty Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [RefDate] -> Bib [RefDate]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[RefDate]
eventDate' <- String -> Bib [RefDate]
getDates "eventdate" Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib [RefDate]
getOldDates "event"
Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [RefDate] -> Bib [RefDate]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[RefDate]
origDate' <- String -> Bib [RefDate]
getDates "origdate" Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib [RefDate]
getOldDates "orig"
Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [RefDate] -> Bib [RefDate]
forall (m :: * -> *) a. Monad m => a -> m a
return []
[RefDate]
accessed' <- String -> Bib [RefDate]
getDates "urldate" Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib [RefDate]
getOldDates "url" Bib [RefDate] -> Bib [RefDate] -> Bib [RefDate]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [RefDate] -> Bib [RefDate]
forall (m :: * -> *) a. Monad m => a -> m a
return []
String
url' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (String
et String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "online" Bool -> Bool -> Bool
|| String -> [(String, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "url" [(String, String)]
opts Maybe String -> Maybe String -> Bool
forall a. Eq a => a -> a -> Bool
/= String -> Maybe String
forall a. a -> Maybe a
Just "false")
RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> RWST Item () BibState Maybe String
getRawField "url")
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do String
etype <- String -> RWST Item () BibState Maybe String
getRawField "eprinttype"
String
eprint <- String -> RWST Item () BibState Maybe String
getRawField "eprint"
let baseUrl :: String
baseUrl =
case (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
etype of
"arxiv" -> "http://arxiv.org/abs/"
"jstor" -> "http://www.jstor.org/stable/"
"pubmed" -> "http://www.ncbi.nlm.nih.gov/pubmed/"
"googlebooks" -> "http://books.google.com?id="
_ -> ""
if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
baseUrl
then RWST Item () BibState Maybe String
forall (m :: * -> *) a. MonadPlus m => m a
mzero
else String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> RWST Item () BibState Maybe String)
-> String -> RWST Item () BibState Maybe String
forall a b. (a -> b) -> a -> b
$ String
baseUrl String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
eprint)
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
String
doi' <- (Bool -> RWST Item () BibState Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (String -> [(String, String)] -> Maybe String
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "doi" [(String, String)]
opts Maybe String -> Maybe String -> Bool
forall a. Eq a => a -> a -> Bool
/= String -> Maybe String
forall a. a -> Maybe a
Just "false") RWST Item () BibState Maybe ()
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> RWST Item () BibState Maybe String
getRawField "doi")
RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
String
isbn' <- String -> RWST Item () BibState Maybe String
getRawField "isbn" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
String
issn' <- String -> RWST Item () BibState Maybe String
getRawField "issn" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
String
pmid' <- String -> RWST Item () BibState Maybe String
getRawField "pmid" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
String
pmcid' <- String -> RWST Item () BibState Maybe String
getRawField "pmcid" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
String
callNumber' <- String -> RWST Item () BibState Maybe String
getRawField "library" RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
-> RWST Item () BibState Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> RWST Item () BibState Maybe String
forall (m :: * -> *) a. Monad m => a -> m a
return String
forall a. Monoid a => a
mempty
Formatted
annotation' <- String -> Bib Formatted
getField "annotation" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> Bib Formatted
getField "annote"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
abstract' <- String -> Bib Formatted
getField "abstract" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
keywords' <- String -> Bib Formatted
getField "keywords" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
note' <- if String
et String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "periodical"
then Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
else String -> Bib Formatted
getField "note" Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
addendum' <- if Bool
bibtex
then Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
else String -> Bib Formatted
getField "addendum"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
Formatted
pubstate' <- Lang -> Formatted -> Formatted
resolveKey Lang
lang (Formatted -> Formatted) -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap`
( String -> Bib Formatted
getField "pubstate"
Bib Formatted -> Bib Formatted -> Bib Formatted
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> case [RefDate]
issued' of
(x :: RefDate
x:_) | RefDate -> Literal
other RefDate
x Literal -> Literal -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Literal
Literal "forthcoming" ->
Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return ([Inline] -> Formatted
Formatted [Text -> Inline
Str "forthcoming"])
_ -> Formatted -> Bib Formatted
forall (m :: * -> *) a. Monad m => a -> m a
return Formatted
forall a. Monoid a => a
mempty
)
let convertEnDash :: Inline -> Inline
convertEnDash (Str s :: Text
s) = Text -> Inline
Str ((Char -> Char) -> Text -> Text
T.map (\c :: Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '–' then '-' else Char
c) Text
s)
convertEnDash x :: Inline
x = Inline
x
let takeDigits :: [Inline] -> [Inline]
takeDigits (Str xs :: Text
xs : _) =
case (Char -> Bool) -> Text -> Text
T.takeWhile Char -> Bool
isDigit Text
xs of
"" -> []
ds :: Text
ds -> [Text -> Inline
Str Text
ds]
takeDigits x :: [Inline]
x = [Inline]
x
Reference -> Bib Reference
forall (m :: * -> *) a. Monad m => a -> m a
return (Reference -> Bib Reference) -> Reference -> Bib Reference
forall a b. (a -> b) -> a -> b
$ Reference
emptyReference
{ refId :: Literal
refId = String -> Literal
Literal String
id'
, refOtherIds :: [Literal]
refOtherIds = (String -> Literal) -> [String] -> [Literal]
forall a b. (a -> b) -> [a] -> [b]
map String -> Literal
Literal [String]
otherIds
, refType :: RefType
refType = RefType
reftype
, author :: [Agent]
author = [Agent]
author'
, editor :: [Agent]
editor = [Agent]
editor'
, translator :: [Agent]
translator = [Agent]
translator'
, director :: [Agent]
director = [Agent]
director'
, containerAuthor :: [Agent]
containerAuthor = [Agent]
containerAuthor'
, issued :: [RefDate]
issued = [RefDate]
issued'
, eventDate :: [RefDate]
eventDate = [RefDate]
eventDate'
, accessed :: [RefDate]
accessed = [RefDate]
accessed'
, originalDate :: [RefDate]
originalDate = [RefDate]
origDate'
, title :: Formatted
title = Char -> [Formatted] -> Formatted
concatWith '.' [
Char -> [Formatted] -> Formatted
concatWith ':' [Formatted
title', Formatted
subtitle']
, Formatted
titleaddon' ]
, titleShort :: Formatted
titleShort = Formatted
shortTitle'
, containerTitle :: Formatted
containerTitle = Char -> [Formatted] -> Formatted
concatWith '.' [
Char -> [Formatted] -> Formatted
concatWith ':' [ Formatted
containerTitle'
, Formatted
containerSubtitle']
, Formatted
containerTitleAddon' ]
, collectionTitle :: Formatted
collectionTitle = Formatted
seriesTitle'
, volumeTitle :: Formatted
volumeTitle = Char -> [Formatted] -> Formatted
concatWith '.' [
Char -> [Formatted] -> Formatted
concatWith ':' [ Formatted
volumeTitle'
, Formatted
volumeSubtitle']
, Formatted
volumeTitleAddon' ]
, containerTitleShort :: Formatted
containerTitleShort = Formatted
containerTitleShort'
, collectionNumber :: Formatted
collectionNumber = Formatted
collectionNumber'
, originalTitle :: Formatted
originalTitle = Formatted
origTitle'
, publisher :: Formatted
publisher = Formatted
publisher'
, originalPublisher :: Formatted
originalPublisher = Formatted
origpublisher'
, publisherPlace :: Formatted
publisherPlace = Formatted
address'
, originalPublisherPlace :: Formatted
originalPublisherPlace = Formatted
origLocation'
, jurisdiction :: Formatted
jurisdiction = Formatted
jurisdiction'
, event :: Formatted
event = Formatted
eventTitle'
, eventPlace :: Formatted
eventPlace = Formatted
venue'
, page :: Formatted
page = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$
(Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
Walk.walk Inline -> Inline
convertEnDash ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (a -> b) -> a -> b
$ Formatted -> [Inline]
unFormatted Formatted
pages'
, pageFirst :: Formatted
pageFirst = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Inline]
takeDigits ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (a -> b) -> a -> b
$ Formatted -> [Inline]
unFormatted Formatted
pages'
, numberOfPages :: Formatted
numberOfPages = Formatted
pagetotal'
, version :: Formatted
version = Formatted
version'
, volume :: Formatted
volume = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Text -> Inline
Str "."]
([[Inline]] -> [Inline]) -> [[Inline]] -> [Inline]
forall a b. (a -> b) -> a -> b
$ ([Inline] -> Bool) -> [[Inline]] -> [[Inline]]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> ([Inline] -> Bool) -> [Inline] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null)
[Formatted -> [Inline]
unFormatted Formatted
volume', Formatted -> [Inline]
unFormatted Formatted
part']
, numberOfVolumes :: Formatted
numberOfVolumes = Formatted
volumes'
, issue :: Formatted
issue = Formatted
issue'
, chapterNumber :: Formatted
chapterNumber = Formatted
chapter'
, status :: Formatted
status = Formatted
pubstate'
, edition :: Formatted
edition = Formatted
edition'
, genre :: Formatted
genre = if Formatted
refgenre Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
== Formatted
forall a. Monoid a => a
mempty
then Formatted
reftype'
else Formatted
refgenre
, note :: Formatted
note = Char -> [Formatted] -> Formatted
concatWith '.' [Formatted
note', Formatted
addendum']
, annote :: Formatted
annote = Formatted
annotation'
, abstract :: Formatted
abstract = Formatted
abstract'
, keyword :: Formatted
keyword = Formatted
keywords'
, number :: Formatted
number = Formatted
number'
, url :: Literal
url = String -> Literal
Literal String
url'
, doi :: Literal
doi = String -> Literal
Literal String
doi'
, isbn :: Literal
isbn = String -> Literal
Literal String
isbn'
, issn :: Literal
issn = String -> Literal
Literal String
issn'
, pmcid :: Literal
pmcid = String -> Literal
Literal String
pmcid'
, pmid :: Literal
pmid = String -> Literal
Literal String
pmid'
, language :: Literal
language = String -> Literal
Literal String
hyphenation
, callNumber :: Literal
callNumber = String -> Literal
Literal String
callNumber'
}