{-# LANGUAGE StrictData #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveTraversable #-}
module Citeproc.CslJson
( CslJson(..)
, cslJsonToJson
, renderCslJson
, parseCslJson
)
where
import Citeproc.Types
import Citeproc.CaseTransform
import Data.Ord ()
import qualified Data.Map as M
import Data.Char (isAlphaNum, isSpace, isPunctuation)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Foldable (fold)
import Data.Functor.Identity
import Data.Aeson (FromJSON(..), ToJSON(..), Value(..), object)
import Control.Monad.Trans.State
import Control.Monad (when)
import Data.Generics.Uniplate.Direct
data CslJson a =
CslText a
| CslEmpty
| CslConcat (CslJson a) (CslJson a)
| CslQuoted (CslJson a)
| CslItalic (CslJson a)
| CslNormal (CslJson a)
| CslBold (CslJson a)
| CslUnderline (CslJson a)
| CslNoDecoration (CslJson a)
| CslSmallCaps (CslJson a)
| CslBaseline (CslJson a)
| CslSup (CslJson a)
| CslSub (CslJson a)
| CslNoCase (CslJson a)
| CslDiv Text (CslJson a)
| CslLink Text (CslJson a)
deriving (Int -> CslJson a -> ShowS
[CslJson a] -> ShowS
CslJson a -> String
(Int -> CslJson a -> ShowS)
-> (CslJson a -> String)
-> ([CslJson a] -> ShowS)
-> Show (CslJson a)
forall a. Show a => Int -> CslJson a -> ShowS
forall a. Show a => [CslJson a] -> ShowS
forall a. Show a => CslJson a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> CslJson a -> ShowS
showsPrec :: Int -> CslJson a -> ShowS
$cshow :: forall a. Show a => CslJson a -> String
show :: CslJson a -> String
$cshowList :: forall a. Show a => [CslJson a] -> ShowS
showList :: [CslJson a] -> ShowS
Show, CslJson a -> CslJson a -> Bool
(CslJson a -> CslJson a -> Bool)
-> (CslJson a -> CslJson a -> Bool) -> Eq (CslJson a)
forall a. Eq a => CslJson a -> CslJson a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => CslJson a -> CslJson a -> Bool
== :: CslJson a -> CslJson a -> Bool
$c/= :: forall a. Eq a => CslJson a -> CslJson a -> Bool
/= :: CslJson a -> CslJson a -> Bool
Eq, Eq (CslJson a)
Eq (CslJson a) =>
(CslJson a -> CslJson a -> Ordering)
-> (CslJson a -> CslJson a -> Bool)
-> (CslJson a -> CslJson a -> Bool)
-> (CslJson a -> CslJson a -> Bool)
-> (CslJson a -> CslJson a -> Bool)
-> (CslJson a -> CslJson a -> CslJson a)
-> (CslJson a -> CslJson a -> CslJson a)
-> Ord (CslJson a)
CslJson a -> CslJson a -> Bool
CslJson a -> CslJson a -> Ordering
CslJson a -> CslJson a -> CslJson a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (CslJson a)
forall a. Ord a => CslJson a -> CslJson a -> Bool
forall a. Ord a => CslJson a -> CslJson a -> Ordering
forall a. Ord a => CslJson a -> CslJson a -> CslJson a
$ccompare :: forall a. Ord a => CslJson a -> CslJson a -> Ordering
compare :: CslJson a -> CslJson a -> Ordering
$c< :: forall a. Ord a => CslJson a -> CslJson a -> Bool
< :: CslJson a -> CslJson a -> Bool
$c<= :: forall a. Ord a => CslJson a -> CslJson a -> Bool
<= :: CslJson a -> CslJson a -> Bool
$c> :: forall a. Ord a => CslJson a -> CslJson a -> Bool
> :: CslJson a -> CslJson a -> Bool
$c>= :: forall a. Ord a => CslJson a -> CslJson a -> Bool
>= :: CslJson a -> CslJson a -> Bool
$cmax :: forall a. Ord a => CslJson a -> CslJson a -> CslJson a
max :: CslJson a -> CslJson a -> CslJson a
$cmin :: forall a. Ord a => CslJson a -> CslJson a -> CslJson a
min :: CslJson a -> CslJson a -> CslJson a
Ord, (forall a b. (a -> b) -> CslJson a -> CslJson b)
-> (forall a b. a -> CslJson b -> CslJson a) -> Functor CslJson
forall a b. a -> CslJson b -> CslJson a
forall a b. (a -> b) -> CslJson a -> CslJson b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> CslJson a -> CslJson b
fmap :: forall a b. (a -> b) -> CslJson a -> CslJson b
$c<$ :: forall a b. a -> CslJson b -> CslJson a
<$ :: forall a b. a -> CslJson b -> CslJson a
Functor, (forall m. Monoid m => CslJson m -> m)
-> (forall m a. Monoid m => (a -> m) -> CslJson a -> m)
-> (forall m a. Monoid m => (a -> m) -> CslJson a -> m)
-> (forall a b. (a -> b -> b) -> b -> CslJson a -> b)
-> (forall a b. (a -> b -> b) -> b -> CslJson a -> b)
-> (forall b a. (b -> a -> b) -> b -> CslJson a -> b)
-> (forall b a. (b -> a -> b) -> b -> CslJson a -> b)
-> (forall a. (a -> a -> a) -> CslJson a -> a)
-> (forall a. (a -> a -> a) -> CslJson a -> a)
-> (forall a. CslJson a -> [a])
-> (forall a. CslJson a -> Bool)
-> (forall a. CslJson a -> Int)
-> (forall a. Eq a => a -> CslJson a -> Bool)
-> (forall a. Ord a => CslJson a -> a)
-> (forall a. Ord a => CslJson a -> a)
-> (forall a. Num a => CslJson a -> a)
-> (forall a. Num a => CslJson a -> a)
-> Foldable CslJson
forall a. Eq a => a -> CslJson a -> Bool
forall a. Num a => CslJson a -> a
forall a. Ord a => CslJson a -> a
forall m. Monoid m => CslJson m -> m
forall a. CslJson a -> Bool
forall a. CslJson a -> Int
forall a. CslJson a -> [a]
forall a. (a -> a -> a) -> CslJson a -> a
forall m a. Monoid m => (a -> m) -> CslJson a -> m
forall b a. (b -> a -> b) -> b -> CslJson a -> b
forall a b. (a -> b -> b) -> b -> CslJson a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => CslJson m -> m
fold :: forall m. Monoid m => CslJson m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> CslJson a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> CslJson a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> CslJson a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> CslJson a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> CslJson a -> b
foldr :: forall a b. (a -> b -> b) -> b -> CslJson a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> CslJson a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> CslJson a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> CslJson a -> b
foldl :: forall b a. (b -> a -> b) -> b -> CslJson a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> CslJson a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> CslJson a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> CslJson a -> a
foldr1 :: forall a. (a -> a -> a) -> CslJson a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> CslJson a -> a
foldl1 :: forall a. (a -> a -> a) -> CslJson a -> a
$ctoList :: forall a. CslJson a -> [a]
toList :: forall a. CslJson a -> [a]
$cnull :: forall a. CslJson a -> Bool
null :: forall a. CslJson a -> Bool
$clength :: forall a. CslJson a -> Int
length :: forall a. CslJson a -> Int
$celem :: forall a. Eq a => a -> CslJson a -> Bool
elem :: forall a. Eq a => a -> CslJson a -> Bool
$cmaximum :: forall a. Ord a => CslJson a -> a
maximum :: forall a. Ord a => CslJson a -> a
$cminimum :: forall a. Ord a => CslJson a -> a
minimum :: forall a. Ord a => CslJson a -> a
$csum :: forall a. Num a => CslJson a -> a
sum :: forall a. Num a => CslJson a -> a
$cproduct :: forall a. Num a => CslJson a -> a
product :: forall a. Num a => CslJson a -> a
Foldable, Functor CslJson
Foldable CslJson
(Functor CslJson, Foldable CslJson) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b))
-> (forall (f :: * -> *) a.
Applicative f =>
CslJson (f a) -> f (CslJson a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CslJson a -> m (CslJson b))
-> (forall (m :: * -> *) a.
Monad m =>
CslJson (m a) -> m (CslJson a))
-> Traversable CslJson
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => CslJson (m a) -> m (CslJson a)
forall (f :: * -> *) a.
Applicative f =>
CslJson (f a) -> f (CslJson a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CslJson a -> m (CslJson b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
CslJson (f a) -> f (CslJson a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
CslJson (f a) -> f (CslJson a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CslJson a -> m (CslJson b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CslJson a -> m (CslJson b)
$csequence :: forall (m :: * -> *) a. Monad m => CslJson (m a) -> m (CslJson a)
sequence :: forall (m :: * -> *) a. Monad m => CslJson (m a) -> m (CslJson a)
Traversable)
instance Semigroup (CslJson a) where
(CslConcat CslJson a
x CslJson a
y) <> :: CslJson a -> CslJson a -> CslJson a
<> CslJson a
z = CslJson a
x CslJson a -> CslJson a -> CslJson a
forall a. Semigroup a => a -> a -> a
<> (CslJson a
y CslJson a -> CslJson a -> CslJson a
forall a. Semigroup a => a -> a -> a
<> CslJson a
z)
CslJson a
CslEmpty <> CslJson a
x = CslJson a
x
CslJson a
x <> CslJson a
CslEmpty = CslJson a
x
CslJson a
x <> CslJson a
y = CslJson a -> CslJson a -> CslJson a
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson a
x CslJson a
y
instance Monoid (CslJson a) where
mempty :: CslJson a
mempty = CslJson a
forall a. CslJson a
CslEmpty
mappend :: CslJson a -> CslJson a -> CslJson a
mappend = CslJson a -> CslJson a -> CslJson a
forall a. Semigroup a => a -> a -> a
(<>)
instance FromJSON (CslJson Text) where
parseJSON :: Value -> Parser (CslJson Text)
parseJSON = (Text -> CslJson Text) -> Parser Text -> Parser (CslJson Text)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Locale -> Text -> CslJson Text
forall a. CiteprocOutput a => Locale -> Text -> a
parseCslJson Locale
forall a. Monoid a => a
mempty) (Parser Text -> Parser (CslJson Text))
-> (Value -> Parser Text) -> Value -> Parser (CslJson Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON
instance ToJSON (CslJson Text) where
toJSON :: CslJson Text -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> (CslJson Text -> Text) -> CslJson Text -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Locale -> CslJson Text -> Text
renderCslJson Bool
False Locale
forall a. Monoid a => a
mempty
instance Uniplate (CslJson a) where
uniplate :: CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
uniplate (CslText a
x) = (a -> CslJson a) -> Type (a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate a -> CslJson a
forall a. a -> CslJson a
CslText Type (a -> CslJson a) (CslJson a)
-> a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- a
x
uniplate (CslJson a
CslEmpty) = CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall from to. from -> Type from to
plate CslJson a
forall a. CslJson a
CslEmpty
uniplate (CslConcat CslJson a
x CslJson a
y) = (CslJson a -> CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a -> CslJson a
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat Type (CslJson a -> CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> Type (CslJson a -> CslJson a) (CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
y
uniplate (CslQuoted CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslQuoted Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslItalic CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslItalic Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslNormal CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslNormal Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslBold CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslBold Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslUnderline CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslUnderline Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslNoDecoration CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslNoDecoration Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslSmallCaps CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslSmallCaps Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslBaseline CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslBaseline Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslSup CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslSup Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslSub CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslSub Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslNoCase CslJson a
x) = (CslJson a -> CslJson a)
-> Type (CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate CslJson a -> CslJson a
forall a. CslJson a -> CslJson a
CslNoCase Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslDiv Text
t CslJson a
x) = (Text -> CslJson a -> CslJson a)
-> Type (Text -> CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate Text -> CslJson a -> CslJson a
forall a. Text -> CslJson a -> CslJson a
CslDiv Type (Text -> CslJson a -> CslJson a) (CslJson a)
-> Text -> Type (CslJson a -> CslJson a) (CslJson a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- Text
t Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
uniplate (CslLink Text
t CslJson a
x) = (Text -> CslJson a -> CslJson a)
-> Type (Text -> CslJson a -> CslJson a) (CslJson a)
forall from to. from -> Type from to
plate Text -> CslJson a -> CslJson a
forall a. Text -> CslJson a -> CslJson a
CslLink Type (Text -> CslJson a -> CslJson a) (CslJson a)
-> Text -> Type (CslJson a -> CslJson a) (CslJson a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- Text
t Type (CslJson a -> CslJson a) (CslJson a)
-> CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to from. Type (to -> from) to -> to -> Type from to
|* CslJson a
x
instance Biplate (CslJson a) (CslJson a) where
biplate :: CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
biplate = CslJson a -> (Str (CslJson a), Str (CslJson a) -> CslJson a)
forall to. to -> Type to to
plateSelf
instance CiteprocOutput (CslJson Text) where
toText :: CslJson Text -> Text
toText = CslJson Text -> Text
forall m. Monoid m => CslJson m -> m
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
fromText :: Text -> CslJson Text
fromText = \Text
t -> if Text -> Bool
T.null Text
t
then CslJson Text
forall a. CslJson a
CslEmpty
else Text -> CslJson Text
forall a. a -> CslJson a
CslText Text
t
dropTextWhile :: (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhile = (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhile'
dropTextWhileEnd :: (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd = (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd'
addFontVariant :: FontVariant -> CslJson Text -> CslJson Text
addFontVariant FontVariant
x =
case FontVariant
x of
FontVariant
NormalVariant -> CslJson Text -> CslJson Text
forall a. a -> a
id
FontVariant
SmallCapsVariant -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps
addFontStyle :: FontStyle -> CslJson Text -> CslJson Text
addFontStyle FontStyle
x =
case FontStyle
x of
FontStyle
NormalFont -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal
FontStyle
ItalicFont -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic
FontStyle
ObliqueFont -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic
addFontWeight :: FontWeight -> CslJson Text -> CslJson Text
addFontWeight FontWeight
x =
case FontWeight
x of
FontWeight
NormalWeight -> CslJson Text -> CslJson Text
forall a. a -> a
id
FontWeight
LightWeight -> CslJson Text -> CslJson Text
forall a. a -> a
id
FontWeight
BoldWeight -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold
addTextDecoration :: TextDecoration -> CslJson Text -> CslJson Text
addTextDecoration TextDecoration
x =
case TextDecoration
x of
TextDecoration
NoDecoration -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration
TextDecoration
UnderlineDecoration -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline
addVerticalAlign :: VerticalAlign -> CslJson Text -> CslJson Text
addVerticalAlign VerticalAlign
x =
case VerticalAlign
x of
VerticalAlign
BaselineAlign -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline
VerticalAlign
SubAlign -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub
VerticalAlign
SupAlign -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup
addTextCase :: Maybe Lang -> TextCase -> CslJson Text -> CslJson Text
addTextCase Maybe Lang
mblang TextCase
x =
case TextCase
x of
TextCase
Lowercase -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withLowercaseAll
TextCase
Uppercase -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withUppercaseAll
TextCase
CapitalizeFirst -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withCapitalizeFirst
TextCase
CapitalizeAll -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withCapitalizeWords
TextCase
SentenceCase -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withSentenceCase
TextCase
TitleCase -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withTitleCase
TextCase
PreserveCase -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoCase
addDisplay :: DisplayStyle -> CslJson Text -> CslJson Text
addDisplay DisplayStyle
x =
case DisplayStyle
x of
DisplayStyle
DisplayBlock -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
"block"
DisplayStyle
DisplayLeftMargin -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
"left-margin"
DisplayStyle
DisplayRightInline -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
"right-inline"
DisplayStyle
DisplayIndent -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
"indent"
addQuotes :: CslJson Text -> CslJson Text
addQuotes = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted
inNote :: CslJson Text -> CslJson Text
inNote = CslJson Text -> CslJson Text
forall a. a -> a
id
movePunctuationInsideQuotes :: CslJson Text -> CslJson Text
movePunctuationInsideQuotes
= CslJson Text -> CslJson Text
punctuationInsideQuotes
mapText :: (Text -> Text) -> CslJson Text -> CslJson Text
mapText Text -> Text
f = Identity (CslJson Text) -> CslJson Text
forall a. Identity a -> a
runIdentity (Identity (CslJson Text) -> CslJson Text)
-> (CslJson Text -> Identity (CslJson Text))
-> CslJson Text
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Identity Text) -> CslJson Text -> Identity (CslJson Text)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b)
traverse (Text -> Identity Text
forall a. a -> Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Identity Text) -> (Text -> Text) -> Text -> Identity Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
f)
addHyperlink :: Text -> CslJson Text -> CslJson Text
addHyperlink Text
url CslJson Text
x = Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslLink Text
url CslJson Text
x
localizeQuotes :: Locale -> CslJson Text -> CslJson Text
localizeQuotes = Locale -> CslJson Text -> CslJson Text
convertQuotes
dropTextWhile' :: (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhile' :: (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhile' Char -> Bool
f CslJson Text
x = State Bool (CslJson Text) -> Bool -> CslJson Text
forall s a. State s a -> s -> a
evalState ((Text -> StateT Bool Identity Text)
-> CslJson Text -> State Bool (CslJson Text)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b)
traverse Text -> StateT Bool Identity Text
forall {m :: * -> *}. Monad m => Text -> StateT Bool m Text
g CslJson Text
x) Bool
False
where
g :: Text -> StateT Bool m Text
g Text
t = do
Bool
pastFirst <- StateT Bool m Bool
forall (m :: * -> *) s. Monad m => StateT s m s
get
if Bool
pastFirst
then Text -> StateT Bool m Text
forall a. a -> StateT Bool m a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
t
else do
Bool -> StateT Bool m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put Bool
True
Text -> StateT Bool m Text
forall a. a -> StateT Bool m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
f Text
t)
dropTextWhileEnd' :: (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' :: (Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
el =
case CslJson Text
el of
CslJson Text
CslEmpty -> CslJson Text
forall a. CslJson a
CslEmpty
CslText Text
t -> Text -> CslJson Text
forall a. a -> CslJson a
CslText ((Char -> Bool) -> Text -> Text
T.dropWhileEnd Char -> Bool
f Text
t)
CslConcat CslJson Text
x CslJson Text
y -> CslJson Text -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson Text
x ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
y)
CslQuoted CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslItalic CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslNormal CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslBold CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslUnderline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslNoDecoration CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslSmallCaps CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslBaseline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslSub CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslSup CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslNoCase CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoCase ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslDiv Text
t CslJson Text
x -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
t ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
CslLink Text
t CslJson Text
x -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslLink Text
t ((Char -> Bool) -> CslJson Text -> CslJson Text
dropTextWhileEnd' Char -> Bool
f CslJson Text
x)
data RenderContext =
RenderContext
{ RenderContext -> Bool
useOuterQuotes :: Bool
, RenderContext -> Bool
useItalics :: Bool
, RenderContext -> Bool
useBold :: Bool
, RenderContext -> Bool
useSmallCaps :: Bool
} deriving (Int -> RenderContext -> ShowS
[RenderContext] -> ShowS
RenderContext -> String
(Int -> RenderContext -> ShowS)
-> (RenderContext -> String)
-> ([RenderContext] -> ShowS)
-> Show RenderContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RenderContext -> ShowS
showsPrec :: Int -> RenderContext -> ShowS
$cshow :: RenderContext -> String
show :: RenderContext -> String
$cshowList :: [RenderContext] -> ShowS
showList :: [RenderContext] -> ShowS
Show, RenderContext -> RenderContext -> Bool
(RenderContext -> RenderContext -> Bool)
-> (RenderContext -> RenderContext -> Bool) -> Eq RenderContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RenderContext -> RenderContext -> Bool
== :: RenderContext -> RenderContext -> Bool
$c/= :: RenderContext -> RenderContext -> Bool
/= :: RenderContext -> RenderContext -> Bool
Eq)
renderCslJson :: Bool
-> Locale
-> CslJson Text
-> Text
renderCslJson :: Bool -> Locale -> CslJson Text -> Text
renderCslJson Bool
useEntities Locale
locale =
RenderContext -> CslJson Text -> Text
go (Bool -> Bool -> Bool -> Bool -> RenderContext
RenderContext Bool
True Bool
True Bool
True Bool
True)
where
((Text, Text)
outerQuotes, (Text, Text)
innerQuotes) = Locale -> ((Text, Text), (Text, Text))
lookupQuotes Locale
locale
go :: RenderContext -> CslJson Text -> Text
go :: RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
el =
case CslJson Text
el of
CslText Text
t
| Just (Char
c, Text
"") <- Text -> Maybe (Char, Text)
T.uncons Text
t
, Just Text
t' <- Char -> Map Char Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Char
c Map Char Text
superscriptChars
-> Text
"<sup>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</sup>"
| Bool
otherwise -> Text -> Text
escape Text
t
CslJson Text
CslEmpty -> Text
forall a. Monoid a => a
mempty
CslConcat CslJson Text
x CslJson Text
y -> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
y
CslQuoted CslJson Text
x
| RenderContext -> Bool
useOuterQuotes RenderContext
ctx
-> (Text, Text) -> Text
forall a b. (a, b) -> a
fst (Text, Text)
outerQuotes Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useOuterQuotes = False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(Text, Text) -> Text
forall a b. (a, b) -> b
snd (Text, Text)
outerQuotes
| Bool
otherwise
-> (Text, Text) -> Text
forall a b. (a, b) -> a
fst (Text, Text)
innerQuotes Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useOuterQuotes = True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(Text, Text) -> Text
forall a b. (a, b) -> b
snd (Text, Text)
innerQuotes
CslNormal CslJson Text
x
| RenderContext -> Bool
useItalics RenderContext
ctx -> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x
| Bool
otherwise -> Text
"<span style=\"font-style:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
CslItalic CslJson Text
x
| RenderContext -> Bool
useItalics RenderContext
ctx -> Text
"<i>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useItalics = False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</i>"
| Bool
otherwise -> Text
"<span style=\"font-style:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useItalics = True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
CslBold CslJson Text
x
| RenderContext -> Bool
useBold RenderContext
ctx -> Text
"<b>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useBold = False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</b>"
| Bool
otherwise -> Text
"<span style=\"font-weight:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useBold = True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
CslUnderline CslJson Text
x -> Text
"<u>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</u>"
CslNoDecoration CslJson Text
x -> Text
"<span style=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(if RenderContext -> Bool
useSmallCaps RenderContext
ctx
then Text
""
else Text
"font-variant:normal;") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(if RenderContext -> Bool
useBold RenderContext
ctx
then Text
""
else Text
"font-weight:normal;") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(if RenderContext -> Bool
useItalics RenderContext
ctx
then Text
""
else Text
"font-style:normal;") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
"\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
CslSmallCaps CslJson Text
x
| RenderContext -> Bool
useSmallCaps RenderContext
ctx -> Text
"<span style=\"font-variant:small-caps;\">"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useSmallCaps = False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
"</span>"
| Bool
otherwise -> Text
"<span style=\"font-variant:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useSmallCaps = True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
CslSup CslJson Text
x -> Text
"<sup>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</sup>"
CslSub CslJson Text
x -> Text
"<sub>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</sub>"
CslBaseline CslJson Text
x -> Text
"<span style=\"baseline\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
CslDiv Text
t CslJson Text
x -> Text
"<div class=\"csl-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</div>"
CslLink Text
t CslJson Text
x -> Text
"<a href=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</a>"
CslNoCase CslJson Text
x -> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x
escape :: Text -> Text
escape Text
t
| Bool
useEntities
= case (Char -> Bool) -> Text -> Maybe Int
T.findIndex (\Char
c -> 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
'>' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'&') Text
t of
Just Int
_ -> HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"<" Text
"<" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
">" Text
">" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
T.replace Text
"&" Text
"&" (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
t
Maybe Int
Nothing -> Text
t
| Bool
otherwise = Text
t
convertQuotes :: Locale -> CslJson Text -> CslJson Text
convertQuotes :: Locale -> CslJson Text -> CslJson Text
convertQuotes Locale
locale = Bool -> CslJson Text -> CslJson Text
go Bool
True
where
((Text, Text)
outerQuotes, (Text, Text)
innerQuotes) = Locale -> ((Text, Text), (Text, Text))
lookupQuotes Locale
locale
go :: Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
el =
case CslJson Text
el of
CslConcat CslJson Text
x CslJson Text
y -> Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
y
CslQuoted CslJson Text
x
| Bool
useOuter
-> Text -> CslJson Text
forall a. a -> CslJson a
CslText ((Text, Text) -> Text
forall a b. (a, b) -> a
fst (Text, Text)
outerQuotes) CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<>
Bool -> CslJson Text -> CslJson Text
go (Bool -> Bool
not Bool
useOuter) CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<>
Text -> CslJson Text
forall a. a -> CslJson a
CslText ((Text, Text) -> Text
forall a b. (a, b) -> b
snd (Text, Text)
outerQuotes)
| Bool
otherwise
-> Text -> CslJson Text
forall a. a -> CslJson a
CslText ((Text, Text) -> Text
forall a b. (a, b) -> a
fst (Text, Text)
innerQuotes) CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<>
Bool -> CslJson Text -> CslJson Text
go (Bool -> Bool
not Bool
useOuter) CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<>
Text -> CslJson Text
forall a. a -> CslJson a
CslText ((Text, Text) -> Text
forall a b. (a, b) -> b
snd (Text, Text)
innerQuotes)
CslNormal CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslItalic CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslBold CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslUnderline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslNoDecoration CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslSmallCaps CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslSup CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslSub CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslBaseline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslDiv Text
t CslJson Text
x -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
t (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslNoCase CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoCase (CslJson Text -> CslJson Text) -> CslJson Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Bool -> CslJson Text -> CslJson Text
go Bool
useOuter CslJson Text
x
CslJson Text
x -> CslJson Text
x
cslJsonToJson :: CslJson Text -> [Value]
cslJsonToJson :: CslJson Text -> [Value]
cslJsonToJson = RenderContext -> CslJson Text -> [Value]
go (Bool -> Bool -> Bool -> Bool -> RenderContext
RenderContext Bool
True Bool
True Bool
True Bool
True)
where
isString :: Value -> Bool
isString (String Text
_) = Bool
True
isString Value
_ = Bool
False
consolidateStrings :: [Value] -> [Value]
consolidateStrings :: [Value] -> [Value]
consolidateStrings [] = []
consolidateStrings (String Text
t : [Value]
rest) =
let ([Value]
xs,[Value]
ys) = (Value -> Bool) -> [Value] -> ([Value], [Value])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span Value -> Bool
isString [Value]
rest
in Text -> Value
String (Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat [Text
t' | String Text
t' <- [Value]
xs]) Value -> [Value] -> [Value]
forall a. a -> [a] -> [a]
:
[Value] -> [Value]
consolidateStrings [Value]
ys
consolidateStrings (Value
x : [Value]
rest) =
Value
x Value -> [Value] -> [Value]
forall a. a -> [a] -> [a]
: [Value] -> [Value]
consolidateStrings [Value]
rest
go :: RenderContext -> CslJson Text -> [Value]
go :: RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
el = [Value] -> [Value]
consolidateStrings ([Value] -> [Value]) -> [Value] -> [Value]
forall a b. (a -> b) -> a -> b
$
case CslJson Text
el of
CslText Text
t -> [Text -> Value
String Text
t]
CslJson Text
CslEmpty -> []
CslConcat CslJson Text
x CslJson Text
CslEmpty -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x
CslConcat (CslConcat CslJson Text
x CslJson Text
y) CslJson Text
z -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx (CslJson Text -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson Text
x (CslJson Text -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson Text
y CslJson Text
z))
CslConcat CslJson Text
x CslJson Text
y -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x [Value] -> [Value] -> [Value]
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
y
CslQuoted CslJson Text
x -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x
CslNormal CslJson Text
x
| RenderContext -> Bool
useItalics RenderContext
ctx -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x
| Bool
otherwise -> [ [Pair] -> Value
object
[ (Key
"format", Value
"no-italics")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslItalic CslJson Text
x
| RenderContext -> Bool
useItalics RenderContext
ctx -> [ [Pair] -> Value
object
[ (Key
"format", Value
"italics")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$
RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx{ useItalics = False } CslJson Text
x)
]
]
| Bool
otherwise -> [ [Pair] -> Value
object
[ (Key
"format", Value
"no-italics")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$
RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx{ useItalics = False } CslJson Text
x)
]
]
CslBold CslJson Text
x
| RenderContext -> Bool
useItalics RenderContext
ctx -> [ [Pair] -> Value
object
[ (Key
"format", Value
"bold")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$
RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx{ useBold = False } CslJson Text
x)
]
]
| Bool
otherwise -> [ [Pair] -> Value
object
[ (Key
"format", Value
"no-bold")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$
RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx{ useBold = False } CslJson Text
x)
]
]
CslUnderline CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"underline")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslNoDecoration CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"no-decoration")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslSmallCaps CslJson Text
x
| RenderContext -> Bool
useSmallCaps RenderContext
ctx -> [ [Pair] -> Value
object
[ (Key
"format", Value
"small-caps")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$
RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx{ useSmallCaps = False } CslJson Text
x)
]
]
| Bool
otherwise -> [ [Pair] -> Value
object
[ (Key
"format", Value
"no-small-caps")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$
RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx{ useSmallCaps = False } CslJson Text
x)
]
]
CslSup CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"superscript")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslSub CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"subscript")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslBaseline CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"baseline")
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslDiv Text
t CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"div")
, (Key
"class", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Text
"csl-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t)
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslLink Text
t CslJson Text
x -> [ [Pair] -> Value
object
[ (Key
"format", Value
"link")
, (Key
"target", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Text
t)
, (Key
"contents", [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x)
]
]
CslNoCase CslJson Text
x -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x
caseTransform' :: (CaseTransformState -> Text -> Text)
-> Int
-> CslJson Text
-> State CaseTransformState (CslJson Text)
caseTransform' :: (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f Int
lev CslJson Text
el =
case CslJson Text
el of
CslText Text
x -> Text -> CslJson Text
forall a. a -> CslJson a
CslText (Text -> CslJson Text)
-> ([Text] -> Text) -> [Text] -> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> CslJson Text)
-> StateT CaseTransformState Identity [Text]
-> State CaseTransformState (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> StateT CaseTransformState Identity Text)
-> [Text] -> StateT CaseTransformState Identity [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Text -> StateT CaseTransformState Identity Text
g (Text -> [Text]
splitUp Text
x)
CslConcat CslJson Text
x CslJson Text
y -> do
CslJson Text
x' <- (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f Int
lev CslJson Text
x
let lastWord :: Bool
lastWord = Int
lev Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& Bool -> Bool
not (CslJson Text -> Bool
hasWordBreak CslJson Text
y)
CaseTransformState
st <- StateT CaseTransformState Identity CaseTransformState
forall (m :: * -> *) s. Monad m => StateT s m s
get
Bool
-> StateT CaseTransformState Identity ()
-> StateT CaseTransformState Identity ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
lastWord Bool -> Bool -> Bool
&&
(CaseTransformState
st CaseTransformState -> CaseTransformState -> Bool
forall a. Eq a => a -> a -> Bool
== CaseTransformState
AfterWordEnd Bool -> Bool -> Bool
|| CaseTransformState
st CaseTransformState -> CaseTransformState -> Bool
forall a. Eq a => a -> a -> Bool
== CaseTransformState
StartSentence Bool -> Bool -> Bool
|| CaseTransformState
st CaseTransformState -> CaseTransformState -> Bool
forall a. Eq a => a -> a -> Bool
== CaseTransformState
Start)) (StateT CaseTransformState Identity ()
-> StateT CaseTransformState Identity ())
-> StateT CaseTransformState Identity ()
-> StateT CaseTransformState Identity ()
forall a b. (a -> b) -> a -> b
$
CaseTransformState -> StateT CaseTransformState Identity ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put CaseTransformState
BeforeLastWord
CslJson Text
y' <- (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f Int
lev CslJson Text
y
CslJson Text -> State CaseTransformState (CslJson Text)
forall a. a -> StateT CaseTransformState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (CslJson Text -> State CaseTransformState (CslJson Text))
-> CslJson Text -> State CaseTransformState (CslJson Text)
forall a b. (a -> b) -> a -> b
$ CslJson Text -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson Text
x' CslJson Text
y'
CslQuoted CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted (CslJson Text -> CslJson Text)
-> State CaseTransformState (CslJson Text)
-> State CaseTransformState (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f (Int
lev Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) CslJson Text
x
CslItalic CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic (CslJson Text -> CslJson Text)
-> State CaseTransformState (CslJson Text)
-> State CaseTransformState (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f (Int
lev Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) CslJson Text
x
CslNormal CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal (CslJson Text -> CslJson Text)
-> State CaseTransformState (CslJson Text)
-> State CaseTransformState (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f (Int
lev Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) CslJson Text
x
CslBold CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold (CslJson Text -> CslJson Text)
-> State CaseTransformState (CslJson Text)
-> State CaseTransformState (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f (Int
lev Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) CslJson Text
x
CslUnderline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline (CslJson Text -> CslJson Text)
-> State CaseTransformState (CslJson Text)
-> State CaseTransformState (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' CaseTransformState -> Text -> Text
f (Int
lev Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) CslJson Text
x
CslNoDecoration CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslSmallCaps CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslBaseline CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslSub CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslSup CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslNoCase CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslDiv Text
_ CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslLink Text
_ CslJson Text
_ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
CslJson Text
CslEmpty -> CslJson Text -> State CaseTransformState (CslJson Text)
forall {a}.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
where
return' :: a -> StateT CaseTransformState Identity a
return' a
x = a
x a
-> StateT CaseTransformState Identity Text
-> StateT CaseTransformState Identity a
forall a b.
a
-> StateT CaseTransformState Identity b
-> StateT CaseTransformState Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> StateT CaseTransformState Identity Text
g (a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x)
g :: Text -> State CaseTransformState Text
g :: Text -> StateT CaseTransformState Identity Text
g Text
t = do
CaseTransformState
st <- StateT CaseTransformState Identity CaseTransformState
forall (m :: * -> *) s. Monad m => StateT s m s
get
CaseTransformState -> StateT CaseTransformState Identity ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (CaseTransformState -> StateT CaseTransformState Identity ())
-> CaseTransformState -> StateT CaseTransformState Identity ()
forall a b. (a -> b) -> a -> b
$ case Text -> Maybe (Text, Char)
T.unsnoc Text
t of
Maybe (Text, Char)
Nothing -> CaseTransformState
st
Just (Text
_,Char
c)
| 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
'?' 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
':' ->
CaseTransformState
AfterSentenceEndingPunctuation
| Char -> Bool
isAlphaNum Char
c -> CaseTransformState
AfterWordChar
| Char -> Bool
isSpace Char
c
, CaseTransformState
st CaseTransformState -> CaseTransformState -> Bool
forall a. Eq a => a -> a -> Bool
== CaseTransformState
AfterSentenceEndingPunctuation -> CaseTransformState
StartSentence
| Char -> Bool
isWordBreak Char
c -> CaseTransformState
AfterWordEnd
| Bool
otherwise -> CaseTransformState
st
Text -> StateT CaseTransformState Identity Text
forall a. a -> StateT CaseTransformState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> StateT CaseTransformState Identity Text)
-> Text -> StateT CaseTransformState Identity Text
forall a b. (a -> b) -> a -> b
$
if (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isAlphaNum Text
t
then CaseTransformState -> Text -> Text
f CaseTransformState
st Text
t
else Text
t
isWordBreak :: Char -> Bool
isWordBreak Char
'-' = Bool
True
isWordBreak Char
'/' = Bool
True
isWordBreak Char
'\x2013' = Bool
True
isWordBreak Char
'\x2014' = Bool
True
isWordBreak Char
c = Char -> Bool
isSpace Char
c
hasWordBreak :: CslJson Text -> Bool
hasWordBreak = (Text -> Bool) -> CslJson Text -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ((Char -> Bool) -> Text -> Bool
T.any Char -> Bool
isWordBreak)
splitUp :: Text -> [Text]
splitUp = (Char -> Char -> Bool) -> Text -> [Text]
T.groupBy Char -> Char -> Bool
sameType
sameType :: Char -> Char -> Bool
sameType Char
c Char
d =
(Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
&& Char -> Bool
isAlphaNum Char
d) Bool -> Bool -> Bool
|| (Char -> Bool
isSpace Char
c Bool -> Bool -> Bool
&& Char -> Bool
isSpace Char
d) Bool -> Bool -> Bool
||
(Char -> Bool
isPunctuation Char
c Bool -> Bool -> Bool
&& Char -> Bool
isPunctuation Char
d)
caseTransform :: Maybe Lang
-> CaseTransformer
-> CslJson Text
-> CslJson Text
caseTransform :: Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
f CslJson Text
x =
State CaseTransformState (CslJson Text)
-> CaseTransformState -> CslJson Text
forall s a. State s a -> s -> a
evalState ((CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' (CaseTransformer -> Maybe Lang -> CaseTransformState -> Text -> Text
unCaseTransformer CaseTransformer
f Maybe Lang
mblang) Int
0 CslJson Text
x) CaseTransformState
Start
punctuationInsideQuotes :: CslJson Text -> CslJson Text
punctuationInsideQuotes :: CslJson Text -> CslJson Text
punctuationInsideQuotes = CslJson Text -> CslJson Text
go
where
startsWithMovable :: Text -> Bool
startsWithMovable Text
t =
case Text -> Maybe (Char, Text)
T.uncons Text
t of
Just (Char
c,Text
_) -> 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
','
Maybe (Char, Text)
Nothing -> Bool
False
go :: CslJson Text -> CslJson Text
go CslJson Text
el =
case CslJson Text
el of
CslConcat CslJson Text
CslEmpty CslJson Text
x -> CslJson Text -> CslJson Text
go CslJson Text
x
CslConcat CslJson Text
x CslJson Text
CslEmpty -> CslJson Text -> CslJson Text
go CslJson Text
x
CslConcat (CslQuoted CslJson Text
x) CslJson Text
y ->
case CslJson Text -> CslJson Text
go CslJson Text
y of
(CslText Text
t) | Text -> Bool
startsWithMovable Text
t
-> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted (CslJson Text -> CslJson Text
go (CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> Text -> CslJson Text
forall a. a -> CslJson a
CslText (Int -> Text -> Text
T.take Int
1 Text
t)))
CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> Text -> CslJson Text
forall a. a -> CslJson a
CslText (Int -> Text -> Text
T.drop Int
1 Text
t)
(CslConcat (CslText Text
t) CslJson Text
z) | Text -> Bool
startsWithMovable Text
t
-> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted (CslJson Text -> CslJson Text
go (CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> Text -> CslJson Text
forall a. a -> CslJson a
CslText (Int -> Text -> Text
T.take Int
1 Text
t))) CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<>
Text -> CslJson Text
forall a. a -> CslJson a
CslText (Int -> Text -> Text
T.drop Int
1 Text
t) CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> CslJson Text
z
CslJson Text
z -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> CslJson Text
z
CslConcat (CslConcat CslJson Text
x CslJson Text
y) CslJson Text
z -> CslJson Text -> CslJson Text
go (CslJson Text -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson Text
x (CslJson Text -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a -> CslJson a
CslConcat CslJson Text
y CslJson Text
z))
CslConcat CslJson Text
x CslJson Text
y -> CslJson Text -> CslJson Text
go CslJson Text
x CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> CslJson Text -> CslJson Text
go CslJson Text
y
CslQuoted CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted (CslJson Text -> CslJson Text
go CslJson Text
x)
CslItalic CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic (CslJson Text -> CslJson Text
go CslJson Text
x)
CslNormal CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal (CslJson Text -> CslJson Text
go CslJson Text
x)
CslBold CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold (CslJson Text -> CslJson Text
go CslJson Text
x)
CslUnderline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline (CslJson Text -> CslJson Text
go CslJson Text
x)
CslNoDecoration CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration (CslJson Text -> CslJson Text
go CslJson Text
x)
CslSmallCaps CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps (CslJson Text -> CslJson Text
go CslJson Text
x)
CslSup CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (CslJson Text -> CslJson Text
go CslJson Text
x)
CslSub CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub (CslJson Text -> CslJson Text
go CslJson Text
x)
CslBaseline CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline (CslJson Text -> CslJson Text
go CslJson Text
x)
CslNoCase CslJson Text
x -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoCase (CslJson Text -> CslJson Text
go CslJson Text
x)
CslDiv Text
t CslJson Text
x -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv Text
t (CslJson Text -> CslJson Text
go CslJson Text
x)
CslLink Text
t CslJson Text
x -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslLink Text
t (CslJson Text -> CslJson Text
go CslJson Text
x)
CslText Text
t -> Text -> CslJson Text
forall a. a -> CslJson a
CslText Text
t
CslJson Text
CslEmpty -> CslJson Text
forall a. CslJson a
CslEmpty