{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Citeproc
( module Citeproc.Types
, module Citeproc.Style
, module Citeproc.Locale
, citeproc
, Result(..)
) where
import Data.Semigroup
import qualified Data.Text as T
import qualified Data.Set as Set
import Citeproc.Types
import Citeproc.Style
import Citeproc.Locale
import Citeproc.Eval
citeproc :: CiteprocOutput a
=> CiteprocOptions
-> Style a
-> Maybe Lang
-> [Reference a]
-> [Citation a]
-> Result a
citeproc opts style mblang refs citations =
Result{ resultCitations = rCitations
, resultBibliography = rBibliography
, resultWarnings = warnings ++ noPrintedFormWarnings }
where
rCitations = map (trimR . movePunct . renderOutput opts) citationOs
rBibliography = map (\(ident, out) ->
(ident, trimR . movePunct .
renderOutput opts{ linkCitations = False } $ out))
bibliographyOs
locale = mergeLocales mblang style
trimR = dropTextWhileEnd (== ' ')
movePunct = case localePunctuationInQuote locale of
Just True -> movePunctuationInsideQuotes
_ -> id
(citationOs, bibliographyOs, warnings) =
evalStyle style mblang refs citations
noPrintedFormWarnings = Set.toList $ mconcat $
zipWith npfCitation citations rCitations ++
map npfBibentry rBibliography
npfBibentry (ident, out) =
if out == mempty
then Set.singleton $ "Bibliography entry with no printed form: " <>
ident
else mempty
npfCitation citation res =
if res == mempty
then Set.singleton $ "Citation with no printed form: " <>
T.intercalate ","
(map (unItemId . citationItemId)
(citationItems citation))
else mempty