{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts  #-}
{-# LANGUAGE PatternGuards     #-}
{-# LANGUAGE ViewPatterns      #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Text.CSL.Proc
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Andrea Rossato <andrea.rossato@unitn.it>
-- Stability   :  unstable
-- Portability :  unportable
--
-- This module provides functions for processing the evaluated
-- 'Output' for disambiguation and citation collapsing.
--
-----------------------------------------------------------------------------

module Text.CSL.Proc where

import Prelude
import           Control.Applicative    ((<|>))
import           Control.Arrow          (second, (&&&), (>>>))
import           Control.Monad.State    (execState, modify)
import           Data.Aeson
import           Data.Char              (isDigit, isLetter)
import           Data.List
import           Data.Maybe             (mapMaybe)
import           Data.Ord               (comparing)
import           Data.Text              (Text)
import qualified Data.Text              as T
import           Text.CSL.Eval
import           Text.CSL.Proc.Collapse
import           Text.CSL.Proc.Disamb
import           Text.CSL.Reference
import           Text.CSL.Style
import           Text.CSL.Util          (proc, proc', query, tr', uncamelize)
import           Text.Pandoc.Definition (Block (Para),
                                         Inline (Note, Space, Str))
data ProcOpts
    = ProcOpts
      { ProcOpts -> BibOpts
bibOpts       :: BibOpts
      , ProcOpts -> Bool
linkCitations :: Bool
      }
    deriving ( Int -> ProcOpts -> ShowS
[ProcOpts] -> ShowS
ProcOpts -> String
(Int -> ProcOpts -> ShowS)
-> (ProcOpts -> String) -> ([ProcOpts] -> ShowS) -> Show ProcOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProcOpts] -> ShowS
$cshowList :: [ProcOpts] -> ShowS
show :: ProcOpts -> String
$cshow :: ProcOpts -> String
showsPrec :: Int -> ProcOpts -> ShowS
$cshowsPrec :: Int -> ProcOpts -> ShowS
Show, ReadPrec [ProcOpts]
ReadPrec ProcOpts
Int -> ReadS ProcOpts
ReadS [ProcOpts]
(Int -> ReadS ProcOpts)
-> ReadS [ProcOpts]
-> ReadPrec ProcOpts
-> ReadPrec [ProcOpts]
-> Read ProcOpts
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProcOpts]
$creadListPrec :: ReadPrec [ProcOpts]
readPrec :: ReadPrec ProcOpts
$creadPrec :: ReadPrec ProcOpts
readList :: ReadS [ProcOpts]
$creadList :: ReadS [ProcOpts]
readsPrec :: Int -> ReadS ProcOpts
$creadsPrec :: Int -> ReadS ProcOpts
Read, ProcOpts -> ProcOpts -> Bool
(ProcOpts -> ProcOpts -> Bool)
-> (ProcOpts -> ProcOpts -> Bool) -> Eq ProcOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProcOpts -> ProcOpts -> Bool
$c/= :: ProcOpts -> ProcOpts -> Bool
== :: ProcOpts -> ProcOpts -> Bool
$c== :: ProcOpts -> ProcOpts -> Bool
Eq )

data BibOpts
    = Select  [(Text, Text)] [(Text, Text)]
    | Include [(Text, Text)] [(Text, Text)]
    | Exclude [(Text, Text)] [(Text, Text)]
    deriving ( Int -> BibOpts -> ShowS
[BibOpts] -> ShowS
BibOpts -> String
(Int -> BibOpts -> ShowS)
-> (BibOpts -> String) -> ([BibOpts] -> ShowS) -> Show BibOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BibOpts] -> ShowS
$cshowList :: [BibOpts] -> ShowS
show :: BibOpts -> String
$cshow :: BibOpts -> String
showsPrec :: Int -> BibOpts -> ShowS
$cshowsPrec :: Int -> BibOpts -> ShowS
Show, ReadPrec [BibOpts]
ReadPrec BibOpts
Int -> ReadS BibOpts
ReadS [BibOpts]
(Int -> ReadS BibOpts)
-> ReadS [BibOpts]
-> ReadPrec BibOpts
-> ReadPrec [BibOpts]
-> Read BibOpts
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BibOpts]
$creadListPrec :: ReadPrec [BibOpts]
readPrec :: ReadPrec BibOpts
$creadPrec :: ReadPrec BibOpts
readList :: ReadS [BibOpts]
$creadList :: ReadS [BibOpts]
readsPrec :: Int -> ReadS BibOpts
$creadsPrec :: Int -> ReadS BibOpts
Read, BibOpts -> BibOpts -> Bool
(BibOpts -> BibOpts -> Bool)
-> (BibOpts -> BibOpts -> Bool) -> Eq BibOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BibOpts -> BibOpts -> Bool
$c/= :: BibOpts -> BibOpts -> Bool
== :: BibOpts -> BibOpts -> Bool
$c== :: BibOpts -> BibOpts -> Bool
Eq )

newtype FieldVal = FieldVal{
                      FieldVal -> (Text, Text)
unFieldVal :: (Text, Text)
                    } deriving Int -> FieldVal -> ShowS
[FieldVal] -> ShowS
FieldVal -> String
(Int -> FieldVal -> ShowS)
-> (FieldVal -> String) -> ([FieldVal] -> ShowS) -> Show FieldVal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldVal] -> ShowS
$cshowList :: [FieldVal] -> ShowS
show :: FieldVal -> String
$cshow :: FieldVal -> String
showsPrec :: Int -> FieldVal -> ShowS
$cshowsPrec :: Int -> FieldVal -> ShowS
Show

instance FromJSON FieldVal where
  parseJSON :: Value -> Parser FieldVal
parseJSON (Object Object
v) = do
    Text
x <- Object
v Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"field"
    Text
y <- Object
v Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"value"
    FieldVal -> Parser FieldVal
forall (m :: * -> *) a. Monad m => a -> m a
return (FieldVal -> Parser FieldVal) -> FieldVal -> Parser FieldVal
forall a b. (a -> b) -> a -> b
$ (Text, Text) -> FieldVal
FieldVal (Text
x,Text
y)
  parseJSON Value
_ = String -> Parser FieldVal
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Could not parse FieldVal"

instance FromJSON BibOpts where
  parseJSON :: Value -> Parser BibOpts
parseJSON (Object Object
v) = do
    [FieldVal]
quash <- Object
v Object -> Text -> Parser (Maybe [FieldVal])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"quash"Parser (Maybe [FieldVal]) -> [FieldVal] -> Parser [FieldVal]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
    let quash' :: [(Text, Text)]
quash' = (FieldVal -> (Text, Text)) -> [FieldVal] -> [(Text, Text)]
forall a b. (a -> b) -> [a] -> [b]
map FieldVal -> (Text, Text)
unFieldVal [FieldVal]
quash
    (Object
v Object -> Text -> Parser [FieldVal]
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"select" Parser [FieldVal]
-> ([FieldVal] -> Parser BibOpts) -> Parser BibOpts
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[FieldVal]
x -> BibOpts -> Parser BibOpts
forall (m :: * -> *) a. Monad m => a -> m a
return (BibOpts -> Parser BibOpts) -> BibOpts -> Parser BibOpts
forall a b. (a -> b) -> a -> b
$ [(Text, Text)] -> [(Text, Text)] -> BibOpts
Select ((FieldVal -> (Text, Text)) -> [FieldVal] -> [(Text, Text)]
forall a b. (a -> b) -> [a] -> [b]
map FieldVal -> (Text, Text)
unFieldVal [FieldVal]
x) [(Text, Text)]
quash')
     Parser BibOpts -> Parser BibOpts -> Parser BibOpts
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
     (Object
v Object -> Text -> Parser [FieldVal]
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"include" Parser [FieldVal]
-> ([FieldVal] -> Parser BibOpts) -> Parser BibOpts
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[FieldVal]
x -> BibOpts -> Parser BibOpts
forall (m :: * -> *) a. Monad m => a -> m a
return (BibOpts -> Parser BibOpts) -> BibOpts -> Parser BibOpts
forall a b. (a -> b) -> a -> b
$ [(Text, Text)] -> [(Text, Text)] -> BibOpts
Include ((FieldVal -> (Text, Text)) -> [FieldVal] -> [(Text, Text)]
forall a b. (a -> b) -> [a] -> [b]
map FieldVal -> (Text, Text)
unFieldVal [FieldVal]
x) [(Text, Text)]
quash')
     Parser BibOpts -> Parser BibOpts -> Parser BibOpts
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
     (Object
v Object -> Text -> Parser [FieldVal]
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"exclude" Parser [FieldVal]
-> ([FieldVal] -> Parser BibOpts) -> Parser BibOpts
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[FieldVal]
x -> BibOpts -> Parser BibOpts
forall (m :: * -> *) a. Monad m => a -> m a
return (BibOpts -> Parser BibOpts) -> BibOpts -> Parser BibOpts
forall a b. (a -> b) -> a -> b
$ [(Text, Text)] -> [(Text, Text)] -> BibOpts
Exclude ((FieldVal -> (Text, Text)) -> [FieldVal] -> [(Text, Text)]
forall a b. (a -> b) -> [a] -> [b]
map FieldVal -> (Text, Text)
unFieldVal [FieldVal]
x) [(Text, Text)]
quash')
     Parser BibOpts -> Parser BibOpts -> Parser BibOpts
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
     BibOpts -> Parser BibOpts
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Text, Text)] -> [(Text, Text)] -> BibOpts
Select [] [(Text, Text)]
quash')
  parseJSON Value
_ = BibOpts -> Parser BibOpts
forall (m :: * -> *) a. Monad m => a -> m a
return (BibOpts -> Parser BibOpts) -> BibOpts -> Parser BibOpts
forall a b. (a -> b) -> a -> b
$ [(Text, Text)] -> [(Text, Text)] -> BibOpts
Select [] []

procOpts :: ProcOpts
procOpts :: ProcOpts
procOpts = ProcOpts :: BibOpts -> Bool -> ProcOpts
ProcOpts
      { bibOpts :: BibOpts
bibOpts = [(Text, Text)] -> [(Text, Text)] -> BibOpts
Select [] []
      , linkCitations :: Bool
linkCitations = Bool
False
      }

-- | With a 'Style', a list of 'Reference's and the list of citation
-- groups (the list of citations with their locator), produce the
-- 'Formatted' for each citation group.
processCitations :: ProcOpts -> Style -> [Reference] -> Citations -> [Formatted]
processCitations :: ProcOpts -> Style -> [Reference] -> Citations -> [Formatted]
processCitations ProcOpts
ops Style
s [Reference]
rs
    = BiblioData -> [Formatted]
citations (BiblioData -> [Formatted])
-> (Citations -> BiblioData) -> Citations -> [Formatted]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProcOpts -> Style -> [Reference] -> Citations -> BiblioData
citeproc ProcOpts
ops Style
s [Reference]
rs

-- | With a 'Style' and the list of 'Reference's produce the
-- 'Formatted' for the bibliography.
processBibliography :: ProcOpts -> Style -> [Reference] -> [Formatted]
processBibliography :: ProcOpts -> Style -> [Reference] -> [Formatted]
processBibliography ProcOpts
ops Style
s [Reference]
rs
    = BiblioData -> [Formatted]
bibliography (BiblioData -> [Formatted]) -> BiblioData -> [Formatted]
forall a b. (a -> b) -> a -> b
$ ProcOpts -> Style -> [Reference] -> Citations -> BiblioData
citeproc ProcOpts
ops Style
s [Reference]
rs [(Reference -> Cite) -> [Reference] -> [Cite]
forall a b. (a -> b) -> [a] -> [b]
map (\Reference
r -> Cite
emptyCite { citeId :: Text
citeId = Literal -> Text
unLiteral (Literal -> Text) -> Literal -> Text
forall a b. (a -> b) -> a -> b
$ Reference -> Literal
refId Reference
r}) [Reference]
rs]

-- | With a 'Style', a list of 'Reference's and the list of
-- 'Citations', produce the 'Formatted' for each citation group
-- and the bibliography.
citeproc :: ProcOpts -> Style -> [Reference] -> Citations -> BiblioData
citeproc :: ProcOpts -> Style -> [Reference] -> Citations -> BiblioData
citeproc ProcOpts
ops Style
s [Reference]
rs Citations
cs
    = [Formatted] -> [Formatted] -> [Text] -> BiblioData
BD [Formatted]
citsOutput [Formatted]
biblioOutput ([Text] -> BiblioData) -> [Text] -> BiblioData
forall a b. (a -> b) -> a -> b
$ (Reference -> Text) -> [Reference] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Literal -> Text
unLiteral (Literal -> Text) -> (Reference -> Literal) -> Reference -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reference -> Literal
refId) [Reference]
biblioRefs
    where
      -- the list of bib entries, as a list of Reference, with
      -- position, locator and year suffix set.
      biblioRefs :: [Reference]
biblioRefs   = Style -> [Reference] -> [Reference]
procRefs Style
s ([Reference] -> [Reference])
-> (Citations -> [Reference]) -> Citations -> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cite -> Maybe Reference) -> [Cite] -> [Reference]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ([Reference] -> Cite -> Maybe Reference
getReference [Reference]
rs) ([Cite] -> [Reference])
-> (Citations -> [Cite]) -> Citations -> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     (Cite -> Cite -> Bool) -> [Cite] -> [Cite]
forall a. (a -> a -> Bool) -> [a] -> [a]
nubBy (\Cite
a Cite
b -> Cite -> Text
citeId Cite
a Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Cite -> Text
citeId Cite
b) ([Cite] -> [Cite]) -> (Citations -> [Cite]) -> Citations -> [Cite]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Citations -> [Cite]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (Citations -> [Reference]) -> Citations -> [Reference]
forall a b. (a -> b) -> a -> b
$ Citations
cs
      biblioOutput :: [Formatted]
biblioOutput = if Text
"disambiguate-add-year-suffix" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Style -> [Text]
getCitDisambOptions Style
s
                     then ([Output] -> Formatted) -> [[Output]] -> [Formatted]
forall a b. (a -> b) -> [a] -> [b]
map ([Output] -> Formatted
formatOutputList ([Output] -> Formatted)
-> ([Output] -> [Output]) -> [Output] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                               (Output -> Output) -> [Output] -> [Output]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc ([(Text, Text)] -> Output -> Output
updateYearSuffixes [(Text, Text)]
yearS) ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Output -> Output) -> [Output] -> [Output]
forall a b. (a -> b) -> [a] -> [b]
map Output -> Output
addYearSuffix) ([[Output]] -> [Formatted]) -> [[Output]] -> [Formatted]
forall a b. (a -> b) -> a -> b
$
                          BibOpts -> Style -> [Reference] -> [[Output]]
procBiblio (ProcOpts -> BibOpts
bibOpts ProcOpts
ops) Style
s [Reference]
biblioRefs
                     else ([Output] -> Formatted) -> [[Output]] -> [Formatted]
forall a b. (a -> b) -> [a] -> [b]
map [Output] -> Formatted
formatOutputList ([[Output]] -> [Formatted]) -> [[Output]] -> [Formatted]
forall a b. (a -> b) -> a -> b
$
                          String -> [[Output]] -> [[Output]]
forall a. String -> a -> a
tr' String
"citeproc:after procBiblio" ([[Output]] -> [[Output]]) -> [[Output]] -> [[Output]]
forall a b. (a -> b) -> a -> b
$
                          BibOpts -> Style -> [Reference] -> [[Output]]
procBiblio (ProcOpts -> BibOpts
bibOpts ProcOpts
ops) Style
s [Reference]
biblioRefs
      citsAndRefs :: [[(Cite, Maybe Reference)]]
citsAndRefs  = [Reference] -> Citations -> [[(Cite, Maybe Reference)]]
processCites [Reference]
biblioRefs Citations
cs
      ([(Text, Text)]
yearS,[CitationGroup]
citG) = Style
-> [Reference]
-> Citations
-> [CitationGroup]
-> ([(Text, Text)], [CitationGroup])
disambCitations Style
s [Reference]
biblioRefs Citations
cs ([CitationGroup] -> ([(Text, Text)], [CitationGroup]))
-> [CitationGroup] -> ([(Text, Text)], [CitationGroup])
forall a b. (a -> b) -> a -> b
$ ([(Cite, Maybe Reference)] -> CitationGroup)
-> [[(Cite, Maybe Reference)]] -> [CitationGroup]
forall a b. (a -> b) -> [a] -> [b]
map (Style -> [(Cite, Maybe Reference)] -> CitationGroup
procGroup Style
s) [[(Cite, Maybe Reference)]]
citsAndRefs
      citsOutput :: [Formatted]
citsOutput   = (CitationGroup -> Formatted) -> [CitationGroup] -> [Formatted]
forall a b. (a -> b) -> [a] -> [b]
map (Style -> CitationGroup -> Formatted
formatCitLayout Style
s) ([CitationGroup] -> [Formatted])
-> ([CitationGroup] -> [CitationGroup])
-> [CitationGroup]
-> [Formatted]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     String -> [CitationGroup] -> [CitationGroup]
forall a. String -> a -> a
tr' String
"citeproc:collapsed" ([CitationGroup] -> [CitationGroup])
-> ([CitationGroup] -> [CitationGroup])
-> [CitationGroup]
-> [CitationGroup]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     Style -> [CitationGroup] -> [CitationGroup]
collapseCitGroups Style
s ([CitationGroup] -> [CitationGroup])
-> ([CitationGroup] -> [CitationGroup])
-> [CitationGroup]
-> [CitationGroup]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     (if ProcOpts -> Bool
linkCitations ProcOpts
ops Bool -> Bool -> Bool
&& Style -> Text
styleClass Style
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"in-text"
                         then ((Cite, Output) -> (Cite, Output))
-> [CitationGroup] -> [CitationGroup]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc (Cite, Output) -> (Cite, Output)
addLink
                         else [CitationGroup] -> [CitationGroup]
forall a. a -> a
id) ([CitationGroup] -> [CitationGroup])
-> ([CitationGroup] -> [CitationGroup])
-> [CitationGroup]
-> [CitationGroup]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     String -> [CitationGroup] -> [CitationGroup]
forall a. String -> a -> a
tr' String
"citeproc:citG" ([CitationGroup] -> [Formatted]) -> [CitationGroup] -> [Formatted]
forall a b. (a -> b) -> a -> b
$
                     [CitationGroup]
citG
      addLink :: (Cite, Output) -> (Cite, Output)
      addLink :: (Cite, Output) -> (Cite, Output)
addLink (Cite
cit, Output
outp) = (Cite
cit, (Output -> Output) -> Output -> Output
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc (Text -> Output -> Output
addLink' (Cite -> Text
citeId Cite
cit)) Output
outp)
      addLink' :: Text -> Output -> Output
addLink' Text
citeid (OYear Text
y Text
_ Formatting
f) =
         Text -> Text -> Formatting -> Output
OYear Text
y Text
citeid Formatting
f{hyperlink :: Text
hyperlink = Text
"#ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
citeid}
      addLink' Text
citeid (OYearSuf Text
y Text
_ [Output]
d Formatting
f) =
         Text -> Text -> [Output] -> Formatting -> Output
OYearSuf Text
y Text
citeid [Output]
d Formatting
f{hyperlink :: Text
hyperlink = Text
"#ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
citeid}
      addLink' Text
citeid (OCitNum Int
n Formatting
f) =
         Int -> Formatting -> Output
OCitNum Int
n Formatting
f{hyperlink :: Text
hyperlink = Text
"#ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
citeid}
      addLink' Text
citeid (OCitLabel Text
l Formatting
f) =
         Text -> Formatting -> Output
OCitLabel Text
l Formatting
f{hyperlink :: Text
hyperlink = Text
"#ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
citeid}
      addLink' Text
citeid (Output xs :: [Output]
xs@(OStr Text
_ Formatting
_: [Output]
_) Formatting
f) =
         [Output] -> Formatting -> Output
Output [Output]
xs Formatting
f{hyperlink :: Text
hyperlink = Text
"#ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
citeid}
      addLink' Text
_ Output
x = Output
x

-- | Given the CSL 'Style' and the list of 'Reference's sort the list
-- according to the 'Style' and assign the citation number to each
-- 'Reference'.
procRefs :: Style -> [Reference] -> [Reference]
procRefs :: Style -> [Reference] -> [Reference]
procRefs Style {biblio :: Style -> Maybe Bibliography
biblio = Maybe Bibliography
mb, csMacros :: Style -> [MacroMap]
csMacros = [MacroMap]
ms , styleLocale :: Style -> [Locale]
styleLocale = [Locale]
l, styleAbbrevs :: Style -> Abbreviations
styleAbbrevs = Abbreviations
as, csOptions :: Style -> [(Text, Text)]
csOptions = [(Text, Text)]
opts} [Reference]
rs
    = [Reference]
-> (Bibliography -> [Reference])
-> Maybe Bibliography
-> [Reference]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Reference] -> [Reference]
setCNum [Reference]
rs) Bibliography -> [Reference]
process Maybe Bibliography
mb
    where
      opts' :: Bibliography -> [(Text, Text)]
opts'   Bibliography
b = [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
mergeOptions (Bibliography -> [(Text, Text)]
bibOptions Bibliography
b) [(Text, Text)]
opts
      setCNum :: [Reference] -> [Reference]
setCNum   = ((Reference, Int) -> Reference)
-> [(Reference, Int)] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map (\(Reference
x,Int
y) -> Reference
x { citationNumber :: CNum
citationNumber = Int -> CNum
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
y }) ([(Reference, Int)] -> [Reference])
-> ([Reference] -> [(Reference, Int)])
-> [Reference]
-> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Reference] -> [Int] -> [(Reference, Int)])
-> [Int] -> [Reference] -> [(Reference, Int)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Reference] -> [Int] -> [(Reference, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([Int
1..] :: [Int])
      sort_ :: Bibliography -> Maybe Reference -> [Sorting]
sort_   Bibliography
b = EvalMode
-> [Locale]
-> [MacroMap]
-> [(Text, Text)]
-> [Sort]
-> Abbreviations
-> Maybe Reference
-> [Sorting]
evalSorting (Cite -> EvalMode
EvalSorting Cite
emptyCite {citePosition :: Text
citePosition = Text
"first"}) [Locale]
l [MacroMap]
ms (Bibliography -> [(Text, Text)]
opts' Bibliography
b) (Bibliography -> [Sort]
bibSort Bibliography
b) Abbreviations
as
      process :: Bibliography -> [Reference]
process Bibliography
b = [Reference] -> [Reference]
setCNum ([Reference] -> [Reference])
-> ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Reference, [Sorting])] -> [Reference]
forall a. Show a => [(a, [Sorting])] -> [a]
sortItems ([(Reference, [Sorting])] -> [Reference])
-> ([Reference] -> [(Reference, [Sorting])])
-> [Reference]
-> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reference -> (Reference, [Sorting]))
-> [Reference] -> [(Reference, [Sorting])]
forall a b. (a -> b) -> [a] -> [b]
map (Reference -> Reference
forall a. a -> a
id (Reference -> Reference)
-> (Reference -> [Sorting]) -> Reference -> (Reference, [Sorting])
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Bibliography -> Maybe Reference -> [Sorting]
sort_ Bibliography
b (Maybe Reference -> [Sorting])
-> (Reference -> Maybe Reference) -> Reference -> [Sorting]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reference -> Maybe Reference
forall a. a -> Maybe a
Just) ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall a b. (a -> b) -> a -> b
$ [Reference]
rs

sortItems :: Show a => [(a,[Sorting])] -> [a]
sortItems :: [(a, [Sorting])] -> [a]
sortItems [] = []
sortItems [(a, [Sorting])]
l
    = case [[Sorting]] -> [Sorting]
forall a. [a] -> a
head ([[Sorting]] -> [Sorting])
-> ([[(a, [Sorting])]] -> [[Sorting]])
-> [[(a, [Sorting])]]
-> [Sorting]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(a, [Sorting])] -> [[Sorting]])
-> [[(a, [Sorting])]] -> [[Sorting]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((a, [Sorting]) -> [Sorting]) -> [(a, [Sorting])] -> [[Sorting]]
forall a b. (a -> b) -> [a] -> [b]
map (a, [Sorting]) -> [Sorting]
forall a b. (a, b) -> b
snd) ([[(a, [Sorting])]] -> [Sorting])
-> [[(a, [Sorting])]] -> [Sorting]
forall a b. (a -> b) -> a -> b
$ [[(a, [Sorting])]]
result of
        [] -> ([(a, [Sorting])] -> [a]) -> [[(a, [Sorting])]] -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((a, [Sorting]) -> a) -> [(a, [Sorting])] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a, [Sorting]) -> a
forall a b. (a, b) -> a
fst) [[(a, [Sorting])]]
result
        [Sorting]
_  -> if ([(a, [Sorting])] -> Bool) -> [[(a, [Sorting])]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) Int
1 (Int -> Bool)
-> ([(a, [Sorting])] -> Int) -> [(a, [Sorting])] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(a, [Sorting])] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length) [[(a, [Sorting])]]
result
              then ([(a, [Sorting])] -> [a]) -> [[(a, [Sorting])]] -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap [(a, [Sorting])] -> [a]
forall a. Show a => [(a, [Sorting])] -> [a]
sortItems [[(a, [Sorting])]]
result
              else ([(a, [Sorting])] -> [a]) -> [[(a, [Sorting])]] -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((a, [Sorting]) -> a) -> [(a, [Sorting])] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a, [Sorting]) -> a
forall a b. (a, b) -> a
fst) [[(a, [Sorting])]]
result
    where
      result :: [[(a, [Sorting])]]
result = [(a, [Sorting])] -> [[(a, [Sorting])]]
forall a. [(a, [Sorting])] -> [[(a, [Sorting])]]
process [(a, [Sorting])]
l
      process :: [(a, [Sorting])] -> [[(a, [Sorting])]]
process = ((a, [Sorting]) -> (a, [Sorting]) -> Ordering)
-> [(a, [Sorting])] -> [(a, [Sorting])]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((a, [Sorting]) -> [Sorting])
-> (a, [Sorting]) -> (a, [Sorting]) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (((a, [Sorting]) -> [Sorting])
 -> (a, [Sorting]) -> (a, [Sorting]) -> Ordering)
-> ((a, [Sorting]) -> [Sorting])
-> (a, [Sorting])
-> (a, [Sorting])
-> Ordering
forall a b. (a -> b) -> a -> b
$ Int -> [Sorting] -> [Sorting]
forall a. Int -> [a] -> [a]
take Int
1 ([Sorting] -> [Sorting])
-> ((a, [Sorting]) -> [Sorting]) -> (a, [Sorting]) -> [Sorting]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, [Sorting]) -> [Sorting]
forall a b. (a, b) -> b
snd)                 ([(a, [Sorting])] -> [(a, [Sorting])])
-> ([(a, [Sorting])] -> [[(a, [Sorting])]])
-> [(a, [Sorting])]
-> [[(a, [Sorting])]]
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                ((a, [Sorting]) -> (a, [Sorting]) -> Bool)
-> [(a, [Sorting])] -> [[(a, [Sorting])]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (\(a, [Sorting])
a (a, [Sorting])
b -> Int -> [Sorting] -> [Sorting]
forall a. Int -> [a] -> [a]
take Int
1 ((a, [Sorting]) -> [Sorting]
forall a b. (a, b) -> b
snd (a, [Sorting])
a) [Sorting] -> [Sorting] -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> [Sorting] -> [Sorting]
forall a. Int -> [a] -> [a]
take Int
1 ((a, [Sorting]) -> [Sorting]
forall a b. (a, b) -> b
snd (a, [Sorting])
b)) ([(a, [Sorting])] -> [[(a, [Sorting])]])
-> ([[(a, [Sorting])]] -> [[(a, [Sorting])]])
-> [(a, [Sorting])]
-> [[(a, [Sorting])]]
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                ([(a, [Sorting])] -> [(a, [Sorting])])
-> [[(a, [Sorting])]] -> [[(a, [Sorting])]]
forall a b. (a -> b) -> [a] -> [b]
map (((a, [Sorting]) -> (a, [Sorting]))
-> [(a, [Sorting])] -> [(a, [Sorting])]
forall a b. (a -> b) -> [a] -> [b]
map (((a, [Sorting]) -> (a, [Sorting]))
 -> [(a, [Sorting])] -> [(a, [Sorting])])
-> ((a, [Sorting]) -> (a, [Sorting]))
-> [(a, [Sorting])]
-> [(a, [Sorting])]
forall a b. (a -> b) -> a -> b
$ ([Sorting] -> [Sorting]) -> (a, [Sorting]) -> (a, [Sorting])
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second (Int -> [Sorting] -> [Sorting]
forall a. Int -> [a] -> [a]
drop Int
1))

-- | With a 'Style' and a sorted list of 'Reference's produce the
-- evaluated output for the bibliography.
procBiblio :: BibOpts -> Style -> [Reference] -> [[Output]]
procBiblio :: BibOpts -> Style -> [Reference] -> [[Output]]
procBiblio BibOpts
bos Style {biblio :: Style -> Maybe Bibliography
biblio = Maybe Bibliography
mb, csMacros :: Style -> [MacroMap]
csMacros = [MacroMap]
ms , styleLocale :: Style -> [Locale]
styleLocale = [Locale]
l,
                       styleAbbrevs :: Style -> Abbreviations
styleAbbrevs = Abbreviations
as, csOptions :: Style -> [(Text, Text)]
csOptions = [(Text, Text)]
opts} [Reference]
rs
    = ([Output] -> [Output]) -> [[Output]] -> [[Output]]
forall a b. (a -> b) -> [a] -> [b]
map [Output] -> [Output]
addSpaceAfterCitNum ([[Output]] -> [[Output]]) -> [[Output]] -> [[Output]]
forall a b. (a -> b) -> a -> b
$ [[Output]]
-> (Bibliography -> [[Output]]) -> Maybe Bibliography -> [[Output]]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Bibliography -> [[Output]]
process Maybe Bibliography
mb
    where
      -- handle second-field-align (sort of)
      addSpaceAfterCitNum :: [Output] -> [Output]
addSpaceAfterCitNum [Output (OCitNum Int
n Formatting
f : [Output]
xs) Formatting
f']
        | Maybe Text
secondFieldAlign Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"flush"  =
            [[Output] -> Formatting -> Output
Output (Int -> Formatting -> Output
OCitNum Int
n Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: Output
OSpace Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
xs) Formatting
f']
        | Maybe Text
secondFieldAlign Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"margin" =
            [[Output] -> Formatting -> Output
Output (Int -> Formatting -> Output
OCitNum Int
n Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: Output
OSpace Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
xs) Formatting
f']
        | Bool
otherwise = [[Output] -> Formatting -> Output
Output (Int -> Formatting -> Output
OCitNum Int
n Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
xs) Formatting
f']
      addSpaceAfterCitNum [Output]
xs = [Output]
xs

      secondFieldAlign :: Maybe Text
secondFieldAlign = Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"second-field-align" ([(Text, Text)] -> Maybe Text) -> [(Text, Text)] -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [(Text, Text)]
-> (Bibliography -> [(Text, Text)])
-> Maybe Bibliography
-> [(Text, Text)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Bibliography -> [(Text, Text)]
bibOptions Maybe Bibliography
mb

      process :: Bibliography -> [[Output]]
      process :: Bibliography -> [[Output]]
process Bibliography
b   = ([Output] -> [Output]) -> [[Output]] -> [[Output]]
forall a b. (a -> b) -> [a] -> [b]
map (Formatting -> Text -> [Output] -> [Output]
formatBiblioLayout (Layout -> Formatting
layFormat (Layout -> Formatting) -> Layout -> Formatting
forall a b. (a -> b) -> a -> b
$ Bibliography -> Layout
bibLayout Bibliography
b) (Layout -> Text
layDelim (Layout -> Text) -> Layout -> Text
forall a b. (a -> b) -> a -> b
$ Bibliography -> Layout
bibLayout Bibliography
b)) ([[Output]] -> [[Output]]) -> [[Output]] -> [[Output]]
forall a b. (a -> b) -> a -> b
$ Bibliography -> [[Output]]
render Bibliography
b

      render :: Bibliography -> [[Output]]
      render :: Bibliography -> [[Output]]
render  Bibliography
b   = Bibliography -> [[Output]] -> [[Output]]
subsequentAuthorSubstitute Bibliography
b ([[Output]] -> [[Output]])
-> ([Reference] -> [[Output]]) -> [Reference] -> [[Output]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reference -> [Output]) -> [Reference] -> [[Output]]
forall a b. (a -> b) -> [a] -> [b]
map (Bibliography -> Reference -> [Output]
evalBib Bibliography
b) ([Reference] -> [[Output]])
-> ([Reference] -> [Reference]) -> [Reference] -> [[Output]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BibOpts -> [Reference] -> [Reference]
filterRefs BibOpts
bos ([Reference] -> [[Output]]) -> [Reference] -> [[Output]]
forall a b. (a -> b) -> a -> b
$ [Reference]
rs

      evalBib :: Bibliography -> Reference -> [Output]
      evalBib :: Bibliography -> Reference -> [Output]
evalBib Bibliography
b = Layout
-> EvalMode
-> Bool
-> [Locale]
-> [MacroMap]
-> [(Text, Text)]
-> Abbreviations
-> Maybe Reference
-> [Output]
evalLayout (Bibliography -> Layout
bibLayout Bibliography
b) (Cite -> EvalMode
EvalBiblio Cite
emptyCite {citePosition :: Text
citePosition = Text
"first"}) Bool
False [Locale]
l [MacroMap]
ms ([(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
mergeOptions (Bibliography -> [(Text, Text)]
bibOptions Bibliography
b) [(Text, Text)]
opts) Abbreviations
as (Maybe Reference -> [Output])
-> (Reference -> Maybe Reference) -> Reference -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reference -> Maybe Reference
forall a. a -> Maybe a
Just

subsequentAuthorSubstitute :: Bibliography -> [[Output]] -> [[Output]]
subsequentAuthorSubstitute :: Bibliography -> [[Output]] -> [[Output]]
subsequentAuthorSubstitute Bibliography
b = if Text -> Bool
T.null Text
subAuthStr then [[Output]] -> [[Output]]
forall a. a -> a
id else [[Output]] -> [[Output]]
chkCreator
    where
      subAuthStr :: Text
subAuthStr  = Text -> [(Text, Text)] -> Text
getOptionVal Text
"subsequent-author-substitute"      (Bibliography -> [(Text, Text)]
bibOptions Bibliography
b)
      subAuthRule :: Text
subAuthRule = Text -> [(Text, Text)] -> Text
getOptionVal Text
"subsequent-author-substitute-rule" (Bibliography -> [(Text, Text)]
bibOptions Bibliography
b)

      queryContrib :: [Output] -> [Output]
queryContrib = ([Output] -> [Output]) -> [Output] -> [Output]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc' [Output] -> [Output]
rmLabel ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Output -> [Output]) -> [Output] -> [Output]
forall a b m. (Typeable a, Data b, Monoid m) => (a -> m) -> b -> m
query Output -> [Output]
contribsQ
      getContrib :: [Output] -> [Output]
getContrib = if Text -> Bool
T.null Text
subAuthStr
                   then [Output] -> [Output] -> [Output]
forall a b. a -> b -> a
const []
                   else case Text
subAuthRule of
                          Text
"partial-first" -> Int -> [Output] -> [Output]
forall a. Int -> [a] -> [a]
take Int
1  ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Output -> [Output]) -> [Output] -> [Output]
forall a b m. (Typeable a, Data b, Monoid m) => (a -> m) -> b -> m
query Output -> [Output]
namesQ  ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Output] -> [Output]
queryContrib
                          Text
"partial-each"  ->          (Output -> [Output]) -> [Output] -> [Output]
forall a b m. (Typeable a, Data b, Monoid m) => (a -> m) -> b -> m
query Output -> [Output]
namesQ  ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Output] -> [Output]
queryContrib
                          Text
_               ->                          [Output] -> [Output]
queryContrib

      getPartialEach :: [a] -> [[a]] -> [a]
getPartialEach [a]
x [[a]]
xs = [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[a]] -> [a]) -> ([[a]] -> [[a]]) -> [[a]] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[a]] -> [[a]]
forall a. Int -> [a] -> [a]
take Int
1 ([[a]] -> [[a]]) -> ([[a]] -> [[a]]) -> [[a]] -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([a], [Bool]) -> [a]) -> [([a], [Bool])] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map ([a], [Bool]) -> [a]
forall a b. (a, b) -> a
fst ([([a], [Bool])] -> [[a]])
-> ([[a]] -> [([a], [Bool])]) -> [[a]] -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                            (([a], [Bool]) -> ([a], [Bool]) -> Ordering)
-> [([a], [Bool])] -> [([a], [Bool])]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ((([a], [Bool]) -> ([a], [Bool]) -> Ordering)
-> ([a], [Bool]) -> ([a], [Bool]) -> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((([a], [Bool]) -> Int)
-> ([a], [Bool]) -> ([a], [Bool]) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing ((([a], [Bool]) -> Int)
 -> ([a], [Bool]) -> ([a], [Bool]) -> Ordering)
-> (([a], [Bool]) -> Int)
-> ([a], [Bool])
-> ([a], [Bool])
-> Ordering
forall a b. (a -> b) -> a -> b
$ [Bool] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Bool] -> Int)
-> (([a], [Bool]) -> [Bool]) -> ([a], [Bool]) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a], [Bool]) -> [Bool]
forall a b. (a, b) -> b
snd)) ([([a], [Bool])] -> [([a], [Bool])])
-> ([[a]] -> [([a], [Bool])]) -> [[a]] -> [([a], [Bool])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([a], [Bool]) -> Bool) -> [([a], [Bool])] -> [([a], [Bool])]
forall a. (a -> Bool) -> [a] -> [a]
filter (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) Int
0 (Int -> Bool) -> (([a], [Bool]) -> Int) -> ([a], [Bool]) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Bool] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([Bool] -> Int)
-> (([a], [Bool]) -> [Bool]) -> ([a], [Bool]) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a], [Bool]) -> [Bool]
forall a b. (a, b) -> b
snd) ([([a], [Bool])] -> [([a], [Bool])])
-> ([[a]] -> [([a], [Bool])]) -> [[a]] -> [([a], [Bool])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                            [[a]] -> [[Bool]] -> [([a], [Bool])]
forall a b. [a] -> [b] -> [(a, b)]
zip [[a]]
xs ([[Bool]] -> [([a], [Bool])])
-> ([[a]] -> [[Bool]]) -> [[a]] -> [([a], [Bool])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> [Bool]) -> [[a]] -> [[Bool]]
forall a b. (a -> b) -> [a] -> [b]
map ((Bool -> Bool) -> [Bool] -> [Bool]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile Bool -> Bool
forall a. a -> a
id ([Bool] -> [Bool]) -> ([a] -> [Bool]) -> [a] -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  (a -> a -> Bool) -> [a] -> [a] -> [Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==) [a]
x) ([[a]] -> [a]) -> [[a]] -> [a]
forall a b. (a -> b) -> a -> b
$ [[a]]
xs

      chkCreator :: [[Output]] -> [[Output]]
chkCreator = if Text
subAuthRule Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"partial-each" then [[Output]] -> [[Output]] -> [[Output]]
chPartialEach [] else [[Output]] -> [[Output]] -> [[Output]]
chkCr []

      chkCr :: [[Output]] -> [[Output]] -> [[Output]]
chkCr [[Output]]
_ []     = []
      chkCr [[Output]]
a ([Output]
x:[[Output]]
xs) = let contribs :: [Output]
contribs = [Output] -> [Output]
getContrib [Output]
x in
                       if  [Output]
contribs [Output] -> [[Output]] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [[Output]]
a
                       then [Output] -> [Output] -> [Output]
forall b (t :: * -> *). (Data b, Foldable t) => t Output -> b -> b
substituteAuth []
                            [Output]
x [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
: [[Output]] -> [[Output]] -> [[Output]]
chkCr             [[Output]]
a  [[Output]]
xs
                       else [Output]
x [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
: [[Output]] -> [[Output]] -> [[Output]]
chkCr ([Output]
contribs [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
: [[Output]]
a) [[Output]]
xs

      chPartialEach :: [[Output]] -> [[Output]] -> [[Output]]
chPartialEach [[Output]]
_ [] = []
      chPartialEach [[Output]]
a ([Output]
x:[[Output]]
xs) = let contribs :: [Output]
contribs = [Output] -> [Output]
getContrib [Output]
x
                                   partial :: [Output]
partial  = [Output] -> [[Output]] -> [Output]
forall a. Eq a => [a] -> [[a]] -> [a]
getPartialEach [Output]
contribs [[Output]]
a in
                               if Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [Output] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Output]
partial
                               then [Output] -> [Output] -> [Output]
forall b (t :: * -> *). (Data b, Foldable t) => t Output -> b -> b
substituteAuth [Output]
partial [Output]
x [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
:
                                    if [Output] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Output]
partial Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< [Output] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Output]
contribs
                                    then [[Output]] -> [[Output]] -> [[Output]]
chPartialEach ([Output]
contribs [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
: [[Output]]
a) [[Output]]
xs
                                    else [[Output]] -> [[Output]] -> [[Output]]
chPartialEach             [[Output]]
a  [[Output]]
xs
                               else [Output]
x  [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
: [[Output]] -> [[Output]] -> [[Output]]
chPartialEach ([Output]
contribs [Output] -> [[Output]] -> [[Output]]
forall a. a -> [a] -> [a]
: [[Output]]
a) [[Output]]
xs

      substituteAuth :: t Output -> b -> b
substituteAuth t Output
a = if Text
subAuthRule Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"complete-each"
                         then (Output -> Output) -> b -> b
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc Output -> Output
chNamas else (Output -> Output) -> b -> b
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc (t Output -> Output -> Output
forall (t :: * -> *). Foldable t => t Output -> Output -> Output
updateContribs t Output
a)

      updateContribs :: t Output -> Output -> Output
updateContribs t Output
a o :: Output
o@(OContrib Text
i Text
r [Output]
y [Output]
ds [[Output]]
os)
          = if Text
r Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"author" Bool -> Bool -> Bool
|| Text
r Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"authorsub" then Text -> Text -> [Output] -> [Output] -> [[Output]] -> Output
OContrib Text
i Text
r [Output]
upCont [Output]
ds [[Output]]
os else Output
o
          where
            upCont :: [Output]
upCont = case Text
subAuthRule of
                       Text
"partial-first" -> [Output] -> [Output]
rmFirstName      [Output]
y
                       Text
"partial-each"  -> t Output -> [Output] -> [Output]
forall (t :: * -> *).
Foldable t =>
t Output -> [Output] -> [Output]
rmSelectedName t Output
a [Output]
y
                       Text
_               -> Text -> Formatting -> Output
OStr Text
subAuthStr Formatting
emptyFormatting Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: (Output -> Output) -> [Output] -> [Output]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc Output -> Output
rmNames [Output]
y
      updateContribs t Output
_ Output
o = Output
o

      contribsQ :: Output -> [Output]
contribsQ Output
o
          | OContrib Text
_ Text
r [Output]
c [Output]
_ [[Output]]
_ <- Output
o = if Text
r Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"author" Bool -> Bool -> Bool
|| Text
r Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"authorsub" then [Output]
c else []
          | Bool
otherwise               = []
      namesQ :: Output -> [Output]
namesQ Output
o
          | OName {} <- Output
o = [Output
o]
          | Bool
otherwise     = []
      rmSelectedName :: t Output -> [Output] -> [Output]
rmSelectedName t Output
_ [] = []
      rmSelectedName t Output
a (Output
o:[Output]
os)
          | OName {} <- Output
o = (if Output
o Output -> t Output -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` t Output
a then Text -> Formatting -> Output
OStr Text
subAuthStr Formatting
emptyFormatting else Output
o) Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: t Output -> [Output] -> [Output]
rmSelectedName t Output
a [Output]
os
          | Bool
otherwise     = Output
o Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: t Output -> [Output] -> [Output]
rmSelectedName t Output
a [Output]
os
      rmFirstName :: [Output] -> [Output]
rmFirstName [] = []
      rmFirstName (Output
o:[Output]
os)
          | OName {} <- Output
o = Text -> Formatting -> Output
OStr Text
subAuthStr Formatting
emptyFormatting Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
os
          | Bool
otherwise     = Output
o Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output] -> [Output]
rmFirstName [Output]
os
      chNamas :: Output -> Output
chNamas Output
o
          | OName Agent
s [Output]
_ [[Output]]
os Formatting
f <- Output
o = Agent -> [Output] -> [[Output]] -> Formatting -> Output
OName Agent
s [Text -> Formatting -> Output
OStr Text
subAuthStr Formatting
emptyFormatting] [[Output]]
os Formatting
f
          | Bool
otherwise           = Output
o
      rmNames :: Output -> Output
rmNames Output
o
          | OName {} <- Output
o = Output
ONull
          | OStr  {} <- Output
o = Output
ONull
          | ODel  {} <- Output
o = Output
ONull
          | Bool
otherwise     = Output
o
      rmLabel :: [Output] -> [Output]
rmLabel [] = []
      rmLabel (Output
o:[Output]
os)
          | OLabel {} <- Output
o =     [Output] -> [Output]
rmLabel [Output]
os
          | Bool
otherwise      = Output
o Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output] -> [Output]
rmLabel [Output]
os

filterRefs :: BibOpts -> [Reference] -> [Reference]
filterRefs :: BibOpts -> [Reference] -> [Reference]
filterRefs BibOpts
bos [Reference]
refs
    | Select  [(Text, Text)]
s [(Text, Text)]
q <- BibOpts
bos = (Reference -> Bool) -> [Reference] -> [Reference]
forall a. (a -> Bool) -> [a] -> [a]
filter ([(Text, Text)] -> Reference -> Bool
forall (t :: * -> *).
Foldable t =>
t (Text, Text) -> Reference -> Bool
select  [(Text, Text)]
s) ([Reference] -> [Reference])
-> ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reference -> Bool) -> [Reference] -> [Reference]
forall a. (a -> Bool) -> [a] -> [a]
filter ([(Text, Text)] -> Reference -> Bool
quash [(Text, Text)]
q) ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall a b. (a -> b) -> a -> b
$ [Reference]
refs
    | Include [(Text, Text)]
i [(Text, Text)]
q <- BibOpts
bos = (Reference -> Bool) -> [Reference] -> [Reference]
forall a. (a -> Bool) -> [a] -> [a]
filter ([(Text, Text)] -> Reference -> Bool
forall (t :: * -> *).
Foldable t =>
t (Text, Text) -> Reference -> Bool
include [(Text, Text)]
i) ([Reference] -> [Reference])
-> ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reference -> Bool) -> [Reference] -> [Reference]
forall a. (a -> Bool) -> [a] -> [a]
filter ([(Text, Text)] -> Reference -> Bool
quash [(Text, Text)]
q) ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall a b. (a -> b) -> a -> b
$ [Reference]
refs
    | Exclude [(Text, Text)]
e [(Text, Text)]
q <- BibOpts
bos = (Reference -> Bool) -> [Reference] -> [Reference]
forall a. (a -> Bool) -> [a] -> [a]
filter ([(Text, Text)] -> Reference -> Bool
forall (t :: * -> *).
Foldable t =>
t (Text, Text) -> Reference -> Bool
exclude [(Text, Text)]
e) ([Reference] -> [Reference])
-> ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reference -> Bool) -> [Reference] -> [Reference]
forall a. (a -> Bool) -> [a] -> [a]
filter ([(Text, Text)] -> Reference -> Bool
quash [(Text, Text)]
q) ([Reference] -> [Reference]) -> [Reference] -> [Reference]
forall a b. (a -> b) -> a -> b
$ [Reference]
refs
    | Bool
otherwise          = [Reference]
refs
    where
      quash :: [(Text, Text)] -> Reference -> Bool
quash  [] Reference
_ = Bool
True
      quash   [(Text, Text)]
q Reference
r = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ((Text, Text) -> Bool) -> [(Text, Text)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Reference -> (Text, Text) -> Bool
lookup_ Reference
r) [(Text, Text)]
q
      select :: t (Text, Text) -> Reference -> Bool
select  t (Text, Text)
s Reference
r =       ((Text, Text) -> Bool) -> t (Text, Text) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Reference -> (Text, Text) -> Bool
lookup_ Reference
r) t (Text, Text)
s
      include :: t (Text, Text) -> Reference -> Bool
include t (Text, Text)
i Reference
r =       ((Text, Text) -> Bool) -> t (Text, Text) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Reference -> (Text, Text) -> Bool
lookup_ Reference
r) t (Text, Text)
i
      exclude :: t (Text, Text) -> Reference -> Bool
exclude t (Text, Text)
e Reference
r =       ((Text, Text) -> Bool) -> t (Text, Text) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not (Bool -> Bool) -> ((Text, Text) -> Bool) -> (Text, Text) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reference -> (Text, Text) -> Bool
lookup_ Reference
r) t (Text, Text)
e
      lookup_ :: Reference -> (Text, Text) -> Bool
      lookup_ :: Reference -> (Text, Text) -> Bool
lookup_ Reference
r (Text
f, Text
v) = case Text
f of
                          Text
"type"       -> Text -> Bool
look Text
"ref-type"
                          Text
"id"         -> Text -> Bool
look Text
"ref-id"
                          Text
"categories" -> Text -> Bool
look Text
"categories"
                          Text
x            -> Text -> Bool
look Text
x
          where
            look :: Text -> Bool
look Text
s = case Text -> [(Text, Value)] -> Maybe Value
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
s (Maybe Reference -> [(Text, Value)]
mkRefMap (Reference -> Maybe Reference
forall a. a -> Maybe a
Just Reference
r)) of
                       Just Value
x | Just RefType
v' <- (Value -> Maybe RefType
forall a. Data a => Value -> Maybe a
fromValue Value
x :: Maybe RefType  ) -> Text
v Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack (ShowS
uncamelize (RefType -> String
forall a. Show a => a -> String
show RefType
v'))
                              | Just Text
v' <- (Value -> Maybe Text
forall a. Data a => Value -> Maybe a
fromValue Value
x :: Maybe Text     ) -> Text
v  Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
v'
                              | Just [Text]
v' <- (Value -> Maybe [Text]
forall a. Data a => Value -> Maybe a
fromValue Value
x :: Maybe [Text]   ) -> Text
v Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
v'
                              | Just [Agent]
v' <- (Value -> Maybe [Agent]
forall a. Data a => Value -> Maybe a
fromValue Value
x :: Maybe [Agent]  ) -> Text -> Bool
T.null Text
v Bool -> Bool -> Bool
&& [Agent] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Agent]
v' Bool -> Bool -> Bool
|| Text
v Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack ([Agent] -> String
forall a. Show a => a -> String
show [Agent]
v')
                              | Just [RefDate]
v' <- (Value -> Maybe [RefDate]
forall a. Data a => Value -> Maybe a
fromValue Value
x :: Maybe [RefDate]) -> Text -> Bool
T.null Text
v Bool -> Bool -> Bool
&& [RefDate] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [RefDate]
v' Bool -> Bool -> Bool
|| Text
v Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack ([RefDate] -> String
forall a. Show a => a -> String
show [RefDate]
v')
                       Maybe Value
_                                                    -> Bool
False

-- | Given the CSL 'Style' and the list of 'Cite's coupled with their
-- 'Reference's, generate a 'CitationGroup'. The citations are sorted
-- according to the 'Style'.
procGroup :: Style -> [(Cite, Maybe Reference)] -> CitationGroup
procGroup :: Style -> [(Cite, Maybe Reference)] -> CitationGroup
procGroup Style {citation :: Style -> Citation
citation = Citation
ct, csMacros :: Style -> [MacroMap]
csMacros = [MacroMap]
ms , styleLocale :: Style -> [Locale]
styleLocale = [Locale]
l,
                  styleAbbrevs :: Style -> Abbreviations
styleAbbrevs = Abbreviations
as, csOptions :: Style -> [(Text, Text)]
csOptions = [(Text, Text)]
opts} [(Cite, Maybe Reference)]
cr
    = [(Cite, Output)]
-> Formatting -> Text -> [(Cite, Output)] -> CitationGroup
CG [(Cite, Output)]
authIn (Layout -> Formatting
layFormat (Layout -> Formatting) -> Layout -> Formatting
forall a b. (a -> b) -> a -> b
$ Citation -> Layout
citLayout Citation
ct) (Layout -> Text
layDelim (Layout -> Text) -> Layout -> Text
forall a b. (a -> b) -> a -> b
$ Citation -> Layout
citLayout Citation
ct) ([(Cite, Output)]
authIn [(Cite, Output)] -> [(Cite, Output)] -> [(Cite, Output)]
forall a. [a] -> [a] -> [a]
++ [(Cite, Output)]
co)
    where
      ([(Cite, Output)]
co, [(Cite, Output)]
authIn) = case [(Cite, Maybe Reference)]
cr of
                       ((Cite, Maybe Reference)
c:[(Cite, Maybe Reference)]
_) -> if Cite -> Bool
authorInText ((Cite, Maybe Reference) -> Cite
forall a b. (a, b) -> a
fst (Cite, Maybe Reference)
c)
                                then (((Cite, Output) -> Bool) -> [(Cite, Output)] -> [(Cite, Output)]
forall a. (a -> Bool) -> [a] -> [a]
filter (((Text, Int) -> (Text, Int) -> Bool)
-> (Cite, Maybe Reference) -> (Cite, Output) -> Bool
forall c b b.
((Text, Int) -> (Text, Int) -> c) -> (Cite, b) -> (Cite, b) -> c
eqCites (Text, Int) -> (Text, Int) -> Bool
forall a. Eq a => a -> a -> Bool
(/=) (Cite, Maybe Reference)
c) [(Cite, Output)]
result,
                                      Int -> [(Cite, Output)] -> [(Cite, Output)]
forall a. Int -> [a] -> [a]
take Int
1 ([(Cite, Output)] -> [(Cite, Output)])
-> ([(Cite, Output)] -> [(Cite, Output)])
-> [(Cite, Output)]
-> [(Cite, Output)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  ((Cite, Output) -> Bool) -> [(Cite, Output)] -> [(Cite, Output)]
forall a. (a -> Bool) -> [a] -> [a]
filter (((Text, Int) -> (Text, Int) -> Bool)
-> (Cite, Maybe Reference) -> (Cite, Output) -> Bool
forall c b b.
((Text, Int) -> (Text, Int) -> c) -> (Cite, b) -> (Cite, b) -> c
eqCites (Text, Int) -> (Text, Int) -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Cite, Maybe Reference)
c) ([(Cite, Output)] -> [(Cite, Output)])
-> [(Cite, Output)] -> [(Cite, Output)]
forall a b. (a -> b) -> a -> b
$ [(Cite, Output)]
result)
                                else ([(Cite, Output)]
result, [])
                       [(Cite, Maybe Reference)]
_     -> ([(Cite, Output)]
result, [])
      eqCites :: ((Text, Int) -> (Text, Int) -> c) -> (Cite, b) -> (Cite, b) -> c
eqCites (Text, Int) -> (Text, Int) -> c
eq (Cite, b)
c = (Cite, b) -> Cite
forall a b. (a, b) -> a
fst ((Cite, b) -> Cite) -> (Cite -> c) -> (Cite, b) -> c
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Cite -> Text
citeId (Cite -> Text) -> (Cite -> Int) -> Cite -> (Text, Int)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Cite -> Int
citeHash (Cite -> (Text, Int)) -> ((Text, Int) -> c) -> Cite -> c
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Text, Int) -> (Text, Int) -> c
eq (Cite -> Text
citeId (Cite -> Text) -> (Cite -> Int) -> Cite -> (Text, Int)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Cite -> Int
citeHash (Cite -> (Text, Int)) -> Cite -> (Text, Int)
forall a b. (a -> b) -> a -> b
$ (Cite, b) -> Cite
forall a b. (a, b) -> a
fst (Cite, b)
c)
      opts' :: [(Text, Text)]
opts'        = [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
mergeOptions (Citation -> [(Text, Text)]
citOptions Citation
ct) [(Text, Text)]
opts
      format :: (Cite, Maybe Reference) -> (Cite, [Output])
format (Cite
c,Maybe Reference
r) = (Cite
c,  Layout
-> EvalMode
-> Bool
-> [Locale]
-> [MacroMap]
-> [(Text, Text)]
-> Abbreviations
-> Maybe Reference
-> [Output]
evalLayout (Citation -> Layout
citLayout Citation
ct) (Cite -> EvalMode
EvalCite Cite
c) Bool
False [Locale]
l [MacroMap]
ms [(Text, Text)]
opts' Abbreviations
as Maybe Reference
r)
      sort_ :: (Cite, Maybe Reference) -> [Sorting]
sort_  (Cite
c,Maybe Reference
r) = EvalMode
-> [Locale]
-> [MacroMap]
-> [(Text, Text)]
-> [Sort]
-> Abbreviations
-> Maybe Reference
-> [Sorting]
evalSorting (Cite -> EvalMode
EvalSorting Cite
c) [Locale]
l [MacroMap]
ms [(Text, Text)]
opts' (Citation -> [Sort]
citSort Citation
ct) Abbreviations
as Maybe Reference
r
      process :: [(Cite, Maybe Reference)] -> [((Cite, Output), [Sorting])]
process      = ((Cite, Maybe Reference) -> ((Cite, Output), [Sorting]))
-> [(Cite, Maybe Reference)] -> [((Cite, Output), [Sorting])]
forall a b. (a -> b) -> [a] -> [b]
map (([Output] -> Output) -> (Cite, [Output]) -> (Cite, Output)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second (([Output] -> Formatting -> Output)
-> Formatting -> [Output] -> Output
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Output] -> Formatting -> Output
Output Formatting
emptyFormatting) ((Cite, [Output]) -> (Cite, Output))
-> ((Cite, Maybe Reference) -> (Cite, [Output]))
-> (Cite, Maybe Reference)
-> (Cite, Output)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cite, Maybe Reference) -> (Cite, [Output])
format ((Cite, Maybe Reference) -> (Cite, Output))
-> ((Cite, Maybe Reference) -> [Sorting])
-> (Cite, Maybe Reference)
-> ((Cite, Output), [Sorting])
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& (Cite, Maybe Reference) -> [Sorting]
sort_)
      result :: [(Cite, Output)]
result       = ([((Cite, Output), [Sorting])] -> [(Cite, Output)])
-> [[((Cite, Output), [Sorting])]] -> [(Cite, Output)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap [((Cite, Output), [Sorting])] -> [(Cite, Output)]
forall a. Show a => [(a, [Sorting])] -> [a]
sortItems ([[((Cite, Output), [Sorting])]] -> [(Cite, Output)])
-> [[((Cite, Output), [Sorting])]] -> [(Cite, Output)]
forall a b. (a -> b) -> a -> b
$ [((Cite, Output), [Sorting])] -> [[((Cite, Output), [Sorting])]]
forall b b. [((Cite, b), b)] -> [[((Cite, b), b)]]
toChunks ([((Cite, Output), [Sorting])] -> [[((Cite, Output), [Sorting])]])
-> [((Cite, Output), [Sorting])] -> [[((Cite, Output), [Sorting])]]
forall a b. (a -> b) -> a -> b
$ [(Cite, Maybe Reference)] -> [((Cite, Output), [Sorting])]
process [(Cite, Maybe Reference)]
cr
      -- toChunks splits the citations up into groups, such that
      -- a citation with a non-null prefix is by itself in its
      -- group, otherwise preserving the order (see #292 for
      -- motivation; we don't want to move prefixed citations
      -- around)
      toChunks :: [((Cite, b), b)] -> [[((Cite, b), b)]]
toChunks  [((Cite, b), b)]
xs = [[((Cite, b), b)]] -> [[((Cite, b), b)]]
forall a. [a] -> [a]
reverse ([[((Cite, b), b)]] -> [[((Cite, b), b)]])
-> [[((Cite, b), b)]] -> [[((Cite, b), b)]]
forall a b. (a -> b) -> a -> b
$ State [[((Cite, b), b)]] ()
-> [[((Cite, b), b)]] -> [[((Cite, b), b)]]
forall s a. State s a -> s -> s
execState ([((Cite, b), b)] -> State [[((Cite, b), b)]] ()
forall (m :: * -> *) b b.
MonadState [[((Cite, b), b)]] m =>
[((Cite, b), b)] -> m ()
toChunks' [((Cite, b), b)]
xs) []
      toChunks' :: [((Cite, b), b)] -> m ()
toChunks' [((Cite, b), b)]
xs = do
        case (((Cite, b), b) -> Bool)
-> [((Cite, b), b)] -> ([((Cite, b), b)], [((Cite, b), b)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break ((Cite, b), b) -> Bool
forall b b. ((Cite, b), b) -> Bool
hasPrefix [((Cite, b), b)]
xs of
                ([], [])   -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                ([], ((Cite, b), b)
y:[((Cite, b), b)]
ys) -> ([[((Cite, b), b)]] -> [[((Cite, b), b)]]) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ([((Cite, b), b)
y][((Cite, b), b)] -> [[((Cite, b), b)]] -> [[((Cite, b), b)]]
forall a. a -> [a] -> [a]
:) m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [((Cite, b), b)] -> m ()
toChunks' [((Cite, b), b)]
ys
                ([((Cite, b), b)]
zs, [((Cite, b), b)]
ys)   -> ([[((Cite, b), b)]] -> [[((Cite, b), b)]]) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ([((Cite, b), b)]
zs[((Cite, b), b)] -> [[((Cite, b), b)]] -> [[((Cite, b), b)]]
forall a. a -> [a] -> [a]
:) m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [((Cite, b), b)] -> m ()
toChunks' [((Cite, b), b)]
ys
      hasPrefix :: ((Cite, b), b) -> Bool
hasPrefix ((Cite
c,b
_),b
_) = Cite -> Formatted
citePrefix Cite
c Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
/= Formatted
forall a. Monoid a => a
mempty

formatBiblioLayout :: Formatting -> Delimiter -> [Output] -> [Output]
formatBiblioLayout :: Formatting -> Text -> [Output] -> [Output]
formatBiblioLayout  Formatting
f Text
d = Formatting -> [Output] -> [Output]
appendOutput Formatting
f ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Output] -> [Output]
addDelim Text
d

formatCitLayout :: Style -> CitationGroup -> Formatted
formatCitLayout :: Style -> CitationGroup -> Formatted
formatCitLayout Style
s (CG [(Cite, Output)]
co Formatting
f Text
d [(Cite, Output)]
cs)
    | [(Cite, Output)
a] <- [(Cite, Output)]
co = Formatted -> Formatted -> Formatted
combine ((Cite, Output) -> Formatted
formatAuth (Cite, Output)
a)
                  ([(Cite, Output)] -> Formatted
formatCits ([(Cite, Output)] -> Formatted) -> [(Cite, Output)] -> Formatted
forall a b. (a -> b) -> a -> b
$
                   ((Cite, Output) -> Cite
forall a b. (a, b) -> a
fst ((Cite, Output) -> Cite)
-> (Cite -> [(Cite, Output)] -> [(Cite, Output)])
-> (Cite, Output)
-> [(Cite, Output)]
-> [(Cite, Output)]
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Cite -> Text
citeId (Cite -> Text) -> (Cite -> Int) -> Cite -> (Text, Int)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Cite -> Int
citeHash (Cite -> (Text, Int))
-> ((Text, Int) -> [(Cite, Output)] -> [(Cite, Output)])
-> Cite
-> [(Cite, Output)]
-> [(Cite, Output)]
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Text, Int) -> [(Cite, Output)] -> [(Cite, Output)]
forall b. (Text, Int) -> [(Cite, b)] -> [(Cite, b)]
setAsSupAu ((Cite, Output) -> [(Cite, Output)] -> [(Cite, Output)])
-> (Cite, Output) -> [(Cite, Output)] -> [(Cite, Output)]
forall a b. (a -> b) -> a -> b
$ (Cite, Output)
a) [(Cite, Output)]
cs)
    | Bool
otherwise = [(Cite, Output)] -> Formatted
formatCits [(Cite, Output)]
cs
    where
      isNote :: Bool
isNote    = Style -> Text
styleClass Style
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"note"
      toNote :: Formatted -> Formatted
toNote (Formatted []) = Formatted
forall a. Monoid a => a
mempty
      toNote (Formatted [Inline]
xs) = [Inline] -> Formatted
Formatted [[Block] -> Inline
Note [[Inline] -> Block
Para [Inline]
xs]]
      combine :: Formatted -> Formatted -> Formatted
combine (Formatted []) Formatted
ys = Formatted
ys
      combine Formatted
xs Formatted
ys =
        case Formatted
ys of
             Formatted []           -> Formatted
xs
             Formatted (Note [Block]
_ : [Inline]
_) -> Formatted
xs Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> Formatted
ys
             Formatted (Str (Text -> String
T.unpack -> [Char
c]):[Inline]
_)  | Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (String
", ;:" :: String) -> Formatted
xs Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> Formatted
ys
             Formatted
_                      -> Formatted
xs Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> [Inline] -> Formatted
Formatted [Inline
Space] Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> Formatted
ys
      formatAuth :: (Cite, Output) -> Formatted
formatAuth   = Output -> Formatted
formatOutput (Output -> Formatted)
-> ((Cite, Output) -> Output) -> (Cite, Output) -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cite, Output) -> Output
localMod
      formatCits :: [(Cite, Output)] -> Formatted
formatCits   = (if Bool
isNote then Formatted -> Formatted
toNote else Formatted -> Formatted
forall a. a -> a
id) (Formatted -> Formatted)
-> ([(Cite, Output)] -> Formatted) -> [(Cite, Output)] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     [Output] -> Formatted
formatOutputList ([Output] -> Formatted)
-> ([(Cite, Output)] -> [Output]) -> [(Cite, Output)] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatting -> [Output] -> [Output]
appendOutput Formatting
formatting ([Output] -> [Output])
-> ([(Cite, Output)] -> [Output]) -> [(Cite, Output)] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatting -> [Output] -> [Output]
addAffixes Formatting
f ([Output] -> [Output])
-> ([(Cite, Output)] -> [Output]) -> [(Cite, Output)] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     Text -> [Output] -> [Output]
addDelim Text
d ([Output] -> [Output])
-> ([(Cite, Output)] -> [Output]) -> [(Cite, Output)] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                     ((Cite, Output) -> Output) -> [(Cite, Output)] -> [Output]
forall a b. (a -> b) -> [a] -> [b]
map ((Cite, Output) -> Cite
forall a b. (a, b) -> a
fst ((Cite, Output) -> Cite)
-> ((Cite, Output) -> Output) -> (Cite, Output) -> (Cite, Output)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& (Cite, Output) -> Output
localMod ((Cite, Output) -> (Cite, Output))
-> ((Cite, Output) -> Output) -> (Cite, Output) -> Output
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Cite -> Output -> Output) -> (Cite, Output) -> Output
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Cite -> Output -> Output
addCiteAffixes)
      formatting :: Formatting
formatting   = Formatting
f{ prefix :: Text
prefix = Text
"", suffix :: Text
suffix = Text
"",
                        verticalAlign :: Text
verticalAlign = if [(Cite, Output)] -> Bool
forall b. [(Cite, b)] -> Bool
isAuthorInText [(Cite, Output)]
cs
                                           then Text
""
                                           else Formatting -> Text
verticalAlign Formatting
f }
      isAuthorInText :: [(Cite, b)] -> Bool
isAuthorInText []        = Bool
False
      isAuthorInText ((Cite
c,b
_):[(Cite, b)]
_) = Cite -> Bool
authorInText Cite
c
      localMod :: (Cite, Output) -> Output
localMod     = (Cite -> Output -> Output) -> (Cite, Output) -> Output
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Cite -> Output -> Output) -> (Cite, Output) -> Output)
-> (Cite -> Output -> Output) -> (Cite, Output) -> Output
forall a b. (a -> b) -> a -> b
$ Style -> Bool -> Cite -> Output -> Output
localModifiers Style
s (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [(Cite, Output)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Cite, Output)]
co)
      setAsSupAu :: (Text, Int) -> [(Cite, b)] -> [(Cite, b)]
setAsSupAu (Text, Int)
h = ((Cite, b) -> (Cite, b)) -> [(Cite, b)] -> [(Cite, b)]
forall a b. (a -> b) -> [a] -> [b]
map (((Cite, b) -> (Cite, b)) -> [(Cite, b)] -> [(Cite, b)])
-> ((Cite, b) -> (Cite, b)) -> [(Cite, b)] -> [(Cite, b)]
forall a b. (a -> b) -> a -> b
$ \(Cite
c,b
o) -> if (Cite -> Text
citeId Cite
c, Cite -> Int
citeHash Cite
c) (Text, Int) -> (Text, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== (Text, Int)
h
                                     then (Cite
c { authorInText :: Bool
authorInText   = Bool
False
                                             , suppressAuthor :: Bool
suppressAuthor = Bool
True }, b
o)
                                     else (Cite
c, b
o)

addAffixes :: Formatting -> [Output] -> [Output]
addAffixes :: Formatting -> [Output] -> [Output]
addAffixes Formatting
f [Output]
os
    | []      <- [Output]
os            = []
    | [Output
ONull] <- [Output]
os            = []
    | [Output [Output
ONull] Formatting
_] <- [Output]
os = []
    | Bool
otherwise                = [Output]
pref [Output] -> [Output] -> [Output]
forall a. [a] -> [a] -> [a]
++ [Output]
suff
    where
      pref :: [Output]
pref = if Bool -> Bool
not (Text -> Bool
T.null (Formatting -> Text
prefix Formatting
f))
             then Text -> Formatting -> Output
OStr (Formatting -> Text
prefix Formatting
f) Formatting
emptyFormatting Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
os
             else [Output]
os
      suff :: [Output]
suff = case Text -> Maybe (Char, Text)
T.uncons (Text -> Maybe (Char, Text)) -> Text -> Maybe (Char, Text)
forall a b. (a -> b) -> a -> b
$ Formatting -> Text
suffix Formatting
f of
               Maybe (Char, Text)
Nothing     -> []
               Just (Char
c,Text
_)
                    | Char -> Bool
isLetter Char
c Bool -> Bool -> Bool
|| Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'(' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'[' ->
                         [Output
OSpace, Text -> Formatting -> Output
OStr (Formatting -> Text
suffix Formatting
f) Formatting
emptyFormatting]
                    | Bool
otherwise -> [Text -> Formatting -> Output
OStr (Formatting -> Text
suffix Formatting
f) Formatting
emptyFormatting]

-- | The 'Bool' is 'True' if we are formatting a textual citation (in
-- pandoc terminology).
localModifiers :: Style -> Bool -> Cite -> Output -> Output
localModifiers :: Style -> Bool -> Cite -> Output -> Output
localModifiers Style
s Bool
b Cite
c
    | Cite -> Bool
authorInText   Cite
c = [Output] -> Output
check ([Output] -> Output) -> (Output -> [Output]) -> Output -> Output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Output -> [Output]
forall (m :: * -> *) a. Monad m => a -> m a
return (Output -> [Output]) -> (Output -> Output) -> Output -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Style -> Output -> Output
contribOnly Style
s
    | Cite -> Bool
suppressAuthor Cite
c = [Output] -> Output
check ([Output] -> Output) -> (Output -> [Output]) -> Output -> Output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Output] -> [Output]
rmContrib ([Output] -> [Output])
-> (Output -> [Output]) -> Output -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Output -> [Output]
forall (m :: * -> *) a. Monad m => a -> m a
return
    | Bool
otherwise        = Output -> Output
forall a. a -> a
id
    where
      isPunct' :: Text -> Bool
isPunct' Text
"" = Bool
False
      isPunct' Text
xs = (Char -> Bool) -> Text -> Bool
T.all (Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (String
".,;:!? " :: String)) Text
xs
      check :: [Output] -> Output
check [Output]
o = case [Output] -> [Output]
cleanOutput [Output]
o of
                  [] -> Output
ONull
                  [Output]
x  -> case [Output] -> [Output]
trim' [Output]
x of
                          [] -> Output
ONull
                          [Output]
x' -> [Output] -> Formatting -> Output
Output [Output]
x' Formatting
emptyFormatting
      hasOutput :: Output -> [Bool]
hasOutput Output
o
          | Output [] Formatting
_ <- Output
o = [Bool
False]
          | ODel      Text
_ <- Output
o = [Bool
False]
          | Output
OSpace      <- Output
o = [Bool
False]
          | Output
ONull       <- Output
o = [Bool
False]
          | Bool
otherwise        = [Bool
True]
      trim' :: [Output] -> [Output]
trim' [] = []
      trim' (Output
o:[Output]
os)
          | Output [Output]
ot Formatting
f <- Output
o, Text
p <- Formatting -> Text
prefix Formatting
f,  Text
p Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
""
          , Text -> Bool
isPunct' Text
p        = [Output] -> [Output]
trim' ([Output] -> [Output]) -> [Output] -> [Output]
forall a b. (a -> b) -> a -> b
$ [Output] -> Formatting -> Output
Output [Output]
ot Formatting
f { prefix :: Text
prefix = Text
"" } Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
os
          | Output [Output]
ot Formatting
f <- Output
o  = if [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ((Output -> [Bool]) -> [Output] -> [Bool]
forall a b m. (Typeable a, Data b, Monoid m) => (a -> m) -> b -> m
query Output -> [Bool]
hasOutput [Output]
ot)
                                then [Output] -> Formatting -> Output
Output ([Output] -> [Output]
trim' [Output]
ot) Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
os
                                else [Output] -> Formatting -> Output
Output       [Output]
ot  Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output] -> [Output]
trim' [Output]
os
          | ODel Text
_      <- Output
o  = [Output] -> [Output]
trim' [Output]
os
          | Output
OSpace      <- Output
o  = [Output] -> [Output]
trim' [Output]
os
          | OStr    Text
x Formatting
f <- Output
o  = Text -> Formatting -> Output
OStr Text
x (if Text -> Bool
isPunct' (Formatting -> Text
prefix Formatting
f)
                                        then Formatting
f { prefix :: Text
prefix = Text
"" } else Formatting
f) Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
os
          | Bool
otherwise         = Output
oOutput -> [Output] -> [Output]
forall a. a -> [a] -> [a]
:[Output]
os
      rmCitNum :: Output -> Output
rmCitNum Output
o
          | OCitNum {} <- Output
o = Output
ONull
          | Bool
otherwise       = Output
o
      rmContrib :: [Output] -> [Output]
rmContrib [] = []
      rmContrib [Output]
o
          | Bool
b, [Output] -> Bool
isNumStyle [Output]
o = (Output -> Output) -> [Output] -> [Output]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc Output -> Output
rmCitNum [Output]
o
          | Bool
otherwise       = [Output] -> [Output]
rmContrib' [Output]
o
      rmContrib' :: [Output] -> [Output]
rmContrib' [] = []
      rmContrib' (Output
o:[Output]
os)
          | Output [Output]
ot Formatting
f <- Output
o = [Output] -> Formatting -> Output
Output ([Output] -> [Output]
rmContrib' [Output]
ot) Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output] -> [Output]
rmContrib' [Output]
os
          | ODel Text
_ <- Output
o
          , OContrib Text
_ Text
"author"
                     [Output]
_ [Output]
_ [[Output]]
_ : [Output]
xs <- [Output]
os = [Output] -> [Output]
rmContrib' [Output]
xs
          | ODel Text
_ <- Output
o
          , OContrib Text
_ Text
"authorsub"
                     [Output]
_ [Output]
_ [[Output]]
_ : [Output]
xs <- [Output]
os = [Output] -> [Output]
rmContrib' [Output]
xs
          | OContrib Text
_ Text
"author" [Output]
_ [Output]
_ [[Output]]
_ <- Output
o
          , ODel Text
_ : [Output]
xs <- [Output]
os =     [Output] -> [Output]
rmContrib' [Output]
xs
          | OContrib Text
_ Text
"authorsub" [Output]
_ [Output]
_ [[Output]]
_ <- Output
o
          , ODel Text
_ : [Output]
xs <- [Output]
os =     [Output] -> [Output]
rmContrib' [Output]
xs
          | OContrib Text
_ Text
"author"
                  [Output]
_ [Output]
_ [[Output]]
_ <- Output
o =     [Output] -> [Output]
rmContrib' [Output]
os
          | OContrib Text
_ Text
"authorsub"
                  [Output]
_ [Output]
_ [[Output]]
_ <- Output
o =     [Output] -> [Output]
rmContrib' [Output]
os
          | OStr Text
x Formatting
_ <- Output
o
          , Text
"ibid" <- (Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'.') (Text -> Text
T.toLower Text
x) = [Output] -> [Output]
rmContrib' [Output]
os

          | Bool
otherwise        = Output
o Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output] -> [Output]
rmContrib' [Output]
os

contribOnly :: Style -> Output -> Output
contribOnly :: Style -> Output -> Output
contribOnly Style
s Output
o
    | [Output] -> Bool
isNumStyle [Output
o]
    , OCitNum Int
n Formatting
f <- Output
o = [Output] -> Formatting -> Output
Output [ Int -> Formatting -> Output
OCitNum Int
n Formatting
f{
                                       verticalAlign :: Text
verticalAlign = Text
"",
                                       prefix :: Text
prefix = Text
"",
                                       suffix :: Text
suffix = Text
"" } ] Formatting
emptyFormatting
    | OContrib Text
_ Text
"author"
            [Output]
_ [Output]
_ [[Output]]
_ <- Output
o = Output
o
    | OContrib Text
_ Text
"authorsub"
            [Output]
_ [Output]
_ [[Output]]
_ <- Output
o = Output
o
    | Output [Output]
ot Formatting
f <- Output
o = [Output] -> Formatting -> Output
Output ([Output] -> [Output]
cleanOutput ([Output] -> [Output]) -> [Output] -> [Output]
forall a b. (a -> b) -> a -> b
$ (Output -> Output) -> [Output] -> [Output]
forall a b. (a -> b) -> [a] -> [b]
map (Style -> Output -> Output
contribOnly Style
s) [Output]
ot)
                         Formatting
f{ verticalAlign :: Text
verticalAlign = Text
"",
                            prefix :: Text
prefix = Text
"",
                            suffix :: Text
suffix = Text
"" }
    | OStr    Text
x Formatting
_ <- Output
o
    , Text
"ibid" <- (Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'.') (Text -> Text
T.toLower Text
x) = Output
o
    | Bool
otherwise        = Output
ONull