{-# LANGUAGE StrictData #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveTraversable #-}
-- | CSL JSON is the structured text format defined in
-- <https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html>.
-- It is used to represent formatted text inside CSL JSON bibliographies.
-- For the most part it is a subset of HTML, with some special
-- features like smart quote parsing.  This module defines a parser
-- and a renderer for this format, as well as 'CiteprocOutput' and
-- other typeclass instances.
module Citeproc.CslJson
  ( CslJson(..)
  , cslJsonToJson
  , renderCslJson
  , parseCslJson
  )
where

--  represent and parse CSL JSON pseudo-html
--  https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html
--  Supported:
--  <i>italics</i>  -- will flip-flop
--  <b>bold</b>     -- will flip-flop
--  <span style="font-variant:small-caps;">...</span> -- ill flip-flop
--  <sup>..</sup>
--  <sub>..</sub>
--  <span class="nocase">..</span>  -- suppress case transformations


import Citeproc.Types
import Citeproc.Locale (lookupQuotes)
import Citeproc.CaseTransform
import Data.Ord ()
import Data.Char (isAlphaNum, isSpace, isAscii)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Foldable (fold)
import Data.Functor.Identity
import Data.Attoparsec.Text as P
import Data.Aeson (FromJSON(..), ToJSON(..), Value(..), object)
import Control.Monad.Trans.State
import Control.Monad (guard, when)
import Control.Applicative ((<|>))
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
showList :: [CslJson a] -> ShowS
$cshowList :: forall a. Show a => [CslJson a] -> ShowS
show :: CslJson a -> String
$cshow :: forall a. Show a => CslJson a -> String
showsPrec :: Int -> CslJson a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> 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
/= :: CslJson a -> CslJson a -> Bool
$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
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
min :: CslJson a -> CslJson a -> CslJson a
$cmin :: forall a. Ord a => CslJson a -> CslJson a -> CslJson a
max :: CslJson a -> CslJson a -> CslJson a
$cmax :: forall a. Ord a => CslJson a -> CslJson a -> CslJson a
>= :: 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
$c< :: forall a. Ord a => CslJson a -> CslJson a -> Bool
compare :: CslJson a -> CslJson a -> Ordering
$ccompare :: forall a. Ord a => CslJson a -> CslJson a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (CslJson a)
Ord, a -> CslJson b -> CslJson a
(a -> b) -> CslJson a -> CslJson b
(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
<$ :: a -> CslJson b -> CslJson a
$c<$ :: forall a b. a -> CslJson b -> CslJson a
fmap :: (a -> b) -> CslJson a -> CslJson b
$cfmap :: forall a b. (a -> b) -> CslJson a -> CslJson b
Functor, CslJson a -> Bool
(a -> m) -> CslJson a -> m
(a -> b -> b) -> b -> CslJson a -> b
(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
product :: CslJson a -> a
$cproduct :: forall a. Num a => CslJson a -> a
sum :: CslJson a -> a
$csum :: forall a. Num a => CslJson a -> a
minimum :: CslJson a -> a
$cminimum :: forall a. Ord a => CslJson a -> a
maximum :: CslJson a -> a
$cmaximum :: forall a. Ord a => CslJson a -> a
elem :: a -> CslJson a -> Bool
$celem :: forall a. Eq a => a -> CslJson a -> Bool
length :: CslJson a -> Int
$clength :: forall a. CslJson a -> Int
null :: CslJson a -> Bool
$cnull :: forall a. CslJson a -> Bool
toList :: CslJson a -> [a]
$ctoList :: forall a. CslJson a -> [a]
foldl1 :: (a -> a -> a) -> CslJson a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> CslJson a -> a
foldr1 :: (a -> a -> a) -> CslJson a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> CslJson a -> a
foldl' :: (b -> a -> b) -> b -> CslJson a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> CslJson a -> b
foldl :: (b -> a -> b) -> b -> CslJson a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> CslJson a -> b
foldr' :: (a -> b -> b) -> b -> CslJson a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> CslJson a -> b
foldr :: (a -> b -> b) -> b -> CslJson a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> CslJson a -> b
foldMap' :: (a -> m) -> CslJson a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> CslJson a -> m
foldMap :: (a -> m) -> CslJson a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> CslJson a -> m
fold :: CslJson m -> m
$cfold :: forall m. Monoid m => CslJson m -> m
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
(a -> f b) -> CslJson a -> f (CslJson b)
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)
sequence :: CslJson (m a) -> m (CslJson a)
$csequence :: forall (m :: * -> *) a. Monad m => CslJson (m a) -> m (CslJson a)
mapM :: (a -> m b) -> CslJson a -> m (CslJson b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> CslJson a -> m (CslJson b)
sequenceA :: CslJson (f a) -> f (CslJson a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
CslJson (f a) -> f (CslJson a)
traverse :: (a -> f b) -> CslJson a -> f (CslJson b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> CslJson a -> f (CslJson b)
$cp2Traversable :: Foldable CslJson
$cp1Traversable :: Functor CslJson
Traversable)

instance Semigroup (CslJson a) where
  (CslConcat x :: CslJson a
x y :: CslJson a
y) <> :: CslJson a -> CslJson a -> CslJson a
<> z :: 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)
  CslEmpty <> x :: CslJson a
x = CslJson a
x
  x :: CslJson a
x <> CslEmpty = CslJson a
x
  x :: CslJson a
x <> y :: 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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Locale -> Text -> CslJson Text
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 x :: 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 x :: CslJson a
x y :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 t :: Text
t x :: 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 t :: Text
t x :: 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 (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
  fromText :: Text -> CslJson Text
fromText              = Locale -> Text -> CslJson Text
parseCslJson Locale
forall a. Monoid a => a
mempty
  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 x :: FontVariant
x      =
    case FontVariant
x of
      NormalVariant    -> CslJson Text -> CslJson Text
forall a. a -> a
id
      SmallCapsVariant -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps
  addFontStyle :: FontStyle -> CslJson Text -> CslJson Text
addFontStyle x :: FontStyle
x        =
    case FontStyle
x of
      NormalFont       -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal
      ItalicFont       -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic
      ObliqueFont      -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic
  addFontWeight :: FontWeight -> CslJson Text -> CslJson Text
addFontWeight x :: FontWeight
x       =
    case FontWeight
x of
      NormalWeight     -> CslJson Text -> CslJson Text
forall a. a -> a
id
      LightWeight      -> CslJson Text -> CslJson Text
forall a. a -> a
id
      BoldWeight       -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold
  addTextDecoration :: TextDecoration -> CslJson Text -> CslJson Text
addTextDecoration x :: TextDecoration
x   =
    case TextDecoration
x of
      NoDecoration        -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration
      UnderlineDecoration -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline
  addVerticalAlign :: VerticalAlign -> CslJson Text -> CslJson Text
addVerticalAlign x :: VerticalAlign
x    =
    case VerticalAlign
x of
      BaselineAlign    -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline
      SubAlign         -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub
      SupAlign         -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup
  addTextCase :: Maybe Lang -> TextCase -> CslJson Text -> CslJson Text
addTextCase mblang :: Maybe Lang
mblang x :: TextCase
x =
    case TextCase
x of
      Lowercase        -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withLowercaseAll
      Uppercase        -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withUppercaseAll
      CapitalizeFirst  -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withCapitalizeFirst
      CapitalizeAll    -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withCapitalizeWords
      SentenceCase     -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withSentenceCase
      TitleCase        -> Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform Maybe Lang
mblang CaseTransformer
withTitleCase
  addDisplay :: DisplayStyle -> CslJson Text -> CslJson Text
addDisplay x :: DisplayStyle
x          =
    case DisplayStyle
x of
      DisplayBlock       -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv "block"
      DisplayLeftMargin  -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv "left-margin"
      DisplayRightInline -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv "right-inline"
      DisplayIndent      -> Text -> CslJson Text -> CslJson Text
forall a. Text -> CslJson a -> CslJson a
CslDiv "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 -- no-op
  movePunctuationInsideQuotes :: CslJson Text -> CslJson Text
movePunctuationInsideQuotes
                        = CslJson Text -> CslJson Text
punctuationInsideQuotes
  mapText :: (Text -> Text) -> CslJson Text -> CslJson Text
mapText f :: 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)
traverse (Text -> Identity Text
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 url :: Text
url x :: 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' f :: Char -> Bool
f x :: 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)
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 t :: 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 (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 (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' f :: Char -> Bool
f el :: CslJson Text
el =
  case CslJson Text
el of
     CslEmpty -> CslJson Text
forall a. CslJson a
CslEmpty
     CslText t :: Text
t -> Text -> CslJson Text
forall a. a -> CslJson a
CslText ((Char -> Bool) -> Text -> Text
T.dropWhileEnd Char -> Bool
f Text
t)
     CslConcat x :: CslJson Text
x y :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 t :: Text
t x :: 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 t :: Text
t x :: 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)

parseCslJson :: Locale -> Text -> CslJson Text
parseCslJson :: Locale -> Text -> CslJson Text
parseCslJson locale :: Locale
locale t :: Text
t =
  case Parser [CslJson Text] -> Text -> Either String [CslJson Text]
forall a. Parser a -> Text -> Either String a
P.parseOnly
         (Parser Text (CslJson Text) -> Parser [CslJson Text]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many' (Locale -> Parser Text (CslJson Text)
pCslJson Locale
locale) Parser [CslJson Text] -> Parser Text () -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text ()
forall t. Chunk t => Parser t ()
P.endOfInput) Text
t of
    Left _   -> Text -> CslJson Text
forall a. a -> CslJson a
CslText Text
t
    Right xs :: [CslJson Text]
xs -> [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat [CslJson Text]
xs

pCslJson :: Locale -> P.Parser (CslJson Text)
pCslJson :: Locale -> Parser Text (CslJson Text)
pCslJson locale :: Locale
locale = [Parser Text (CslJson Text)] -> Parser Text (CslJson Text)
forall (f :: * -> *) a. Alternative f => [f a] -> f a
P.choice
  [ Parser Text (CslJson Text)
pCslText
  , Parser Text (CslJson Text)
pCslQuoted
  , Parser Text (CslJson Text)
pCslItalic
  , Parser Text (CslJson Text)
pCslBold
  , Parser Text (CslJson Text)
pCslUnderline
  , Parser Text (CslJson Text)
pCslNoDecoration
  , Parser Text (CslJson Text)
pCslSmallCaps
  , Parser Text (CslJson Text)
pCslSup
  , Parser Text (CslJson Text)
pCslSub
  , Parser Text (CslJson Text)
pCslBaseline
  , Parser Text (CslJson Text)
pCslNoCase
  , Parser Text (CslJson Text)
pCslSymbol
  ]
 where
  ((outerOpenQuote :: Text
outerOpenQuote, outerCloseQuote :: Text
outerCloseQuote), (innerOpenQuote :: Text
innerOpenQuote, innerCloseQuote :: Text
innerCloseQuote)) =
     Locale -> ((Text, Text), (Text, Text))
lookupQuotes Locale
locale
  isSpecialChar :: Char -> Bool
isSpecialChar c :: Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '<' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '>' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\'' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '"' Bool -> Bool -> Bool
||
       Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '’' Bool -> Bool -> Bool
|| (Bool -> Bool
not (Char -> Bool
isAscii Char
c) Bool -> Bool -> Bool
&& (Char -> Bool
isSuperscriptChar Char
c Bool -> Bool -> Bool
|| Char -> Bool
isQuoteChar Char
c))
  isQuoteChar :: Char -> Bool
isQuoteChar = String -> Char -> Bool
P.inClass
       (Text -> String
T.unpack (Text
outerOpenQuote Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
outerCloseQuote Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                 Text
innerOpenQuote Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
innerCloseQuote))
  isSuperscriptChar :: Char -> Bool
isSuperscriptChar = String -> Char -> Bool
P.inClass String
superscriptChars
  isApostrophe :: Char -> Bool
isApostrophe '\'' = Bool
True
  isApostrophe '’'  = Bool
True
  isApostrophe _    = Bool
False
  pCsl :: Parser Text (CslJson Text)
pCsl = Locale -> Parser Text (CslJson Text)
pCslJson Locale
locale
  notFollowedBySpace :: Parser Text ()
notFollowedBySpace =
    Parser Char
P.peekChar' Parser Char -> (Char -> Parser Text ()) -> Parser Text ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Parser Text ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Parser Text ())
-> (Char -> Bool) -> Char -> Parser Text ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpaceChar
  isSpaceChar :: Char -> Bool
isSpaceChar = String -> Char -> Bool
P.inClass [' ','\t','\n','\r']
  pOpenQuote :: Parser Text Text
pOpenQuote = (("\"" Text -> Parser Char -> Parser Text Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser Char
P.char '"')
                Parser Text Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ("'" Text -> Parser Char -> Parser Text Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser Char
P.char '\'')
                Parser Text Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text
outerCloseQuote Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser Text Text
P.string Text
outerOpenQuote)
                Parser Text Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text
innerCloseQuote Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser Text Text
P.string Text
innerOpenQuote))
                 Parser Text Text -> Parser Text () -> Parser Text Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Text ()
notFollowedBySpace
  pSpace :: Parser Text ()
pSpace = (Char -> Bool) -> Parser Text ()
P.skipWhile Char -> Bool
isSpaceChar
  pCslText :: Parser Text (CslJson Text)
pCslText = 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
addNarrowSpace (Text -> CslJson Text)
-> Parser Text Text -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (  do Text
t <- (Char -> Bool) -> Parser Text Text
P.takeWhile1 (\c :: Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
&& Bool -> Bool
not (Char -> Bool
isSpecialChar Char
c))
          -- apostrophe
          Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a. Alternative f => a -> f a -> f a
P.option Text
t (Parser Text Text -> Parser Text Text)
-> Parser Text Text -> Parser Text Text
forall a b. (a -> b) -> a -> b
$ do Char
_ <- (Char -> Bool) -> Parser Char
P.satisfy Char -> Bool
isApostrophe
                          Text
t' <- (Char -> Bool) -> Parser Text Text
P.takeWhile1 Char -> Bool
isAlphaNum
                          Text -> Parser Text Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "’" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t')
    Parser Text Text -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
      ((Char -> Bool) -> Parser Text Text
P.takeWhile1 (\c :: Char
c -> Bool -> Bool
not (Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char -> Bool
isSpecialChar Char
c))) )
  pCslQuoted :: Parser Text (CslJson Text)
pCslQuoted = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted (CslJson Text -> CslJson Text)
-> Parser Text (CslJson Text) -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    do Text
cl <- Parser Text Text
pOpenQuote
       Maybe Char
mbc <- Parser (Maybe Char)
peekChar
       case Maybe Char
mbc of
         Just c :: Char
c  | Char -> Text
T.singleton Char
c Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
cl -> String -> Parser Text ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail "unexpected close quote"
         _ -> () -> Parser Text ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
       [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string Text
cl)
  pCslSymbol :: Parser Text (CslJson Text)
pCslSymbol = do
    Char
c <- (Char -> Bool) -> Parser Char
P.satisfy Char -> Bool
isSpecialChar
    CslJson Text -> Parser Text (CslJson Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (CslJson Text -> Parser Text (CslJson Text))
-> CslJson Text -> Parser Text (CslJson Text)
forall a b. (a -> b) -> a -> b
$
       if Char -> Bool
isApostrophe Char
c
          then Text -> CslJson Text
forall a. a -> CslJson a
CslText "’"
          else Char -> CslJson Text
charToSup Char
c
  pCslItalic :: Parser Text (CslJson Text)
pCslItalic = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<i>" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</i>"))
  pCslBold :: Parser Text (CslJson Text)
pCslBold = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<b>" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</b>"))
  pCslUnderline :: Parser Text (CslJson Text)
pCslUnderline = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<u>" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</u>"))
  pCslNoDecoration :: Parser Text (CslJson Text)
pCslNoDecoration = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<span" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
     Text -> Parser Text Text
P.string "class=\"nodecor\"" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Char -> Parser Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> Parser Char
P.char '>' Parser Char -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
     Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</span>"))
  pCslSup :: Parser Text (CslJson Text)
pCslSup = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<sup>" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</sup>"))
  pCslSub :: Parser Text (CslJson Text)
pCslSub = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<sub>" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</sub>"))
  pCslBaseline :: Parser Text (CslJson Text)
pCslBaseline = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<span" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> Parser Text Text
P.string "style=\"baseline\">" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
      Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</span>"))
  pCslSmallCaps :: Parser Text (CslJson Text)
pCslSmallCaps = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    ((Text -> Parser Text Text
P.string "<span" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
      Text -> Parser Text Text
P.string "style=\"font-variant:" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
      Text -> Parser Text Text
P.string "small-caps;" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Char -> Parser Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> Parser Char
P.char '"' Parser Char -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
      Parser Text ()
pSpace Parser Text () -> Parser Char -> Parser Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> Parser Char
P.char '>' Parser Char -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</span>"))
    Parser [CslJson Text]
-> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
     (Text -> Parser Text Text
P.string "<sc>" Parser Text Text -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</sc>")))
  pCslNoCase :: Parser Text (CslJson Text)
pCslNoCase = CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoCase (CslJson Text -> CslJson Text)
-> ([CslJson Text] -> CslJson Text)
-> [CslJson Text]
-> CslJson Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [CslJson Text] -> CslJson Text
forall a. Monoid a => [a] -> a
mconcat ([CslJson Text] -> CslJson Text)
-> Parser [CslJson Text] -> Parser Text (CslJson Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Parser Text Text
P.string "<span" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Text Text -> Parser Text Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
     Text -> Parser Text Text
P.string "class=\"nocase\"" Parser Text Text -> Parser Text () -> Parser Text ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text ()
pSpace Parser Text () -> Parser Char -> Parser Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> Parser Char
P.char '>' Parser Char -> Parser [CslJson Text] -> Parser [CslJson Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
     Parser Text (CslJson Text)
-> Parser Text Text -> Parser [CslJson Text]
forall (m :: * -> *) a b. MonadPlus m => m a -> m b -> m [a]
P.manyTill' Parser Text (CslJson Text)
pCsl (Text -> Parser Text Text
P.string "</span>"))
  addNarrowSpace :: Text -> Text
addNarrowSpace =
    Text -> Text -> Text -> Text
T.replace " ;" "\x202F;" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Text -> Text -> Text -> Text
T.replace " ?" "\x202F?" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Text -> Text -> Text -> Text
T.replace " !" "\x202F!" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Text -> Text -> Text -> Text
T.replace " »" "\x202F»" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Text -> Text -> Text -> Text
T.replace "« " "«\x202F"

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
showList :: [RenderContext] -> ShowS
$cshowList :: [RenderContext] -> ShowS
show :: RenderContext -> String
$cshow :: RenderContext -> String
showsPrec :: Int -> RenderContext -> ShowS
$cshowsPrec :: Int -> RenderContext -> ShowS
Show, RenderContext -> RenderContext -> Bool
(RenderContext -> RenderContext -> Bool)
-> (RenderContext -> RenderContext -> Bool) -> Eq RenderContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RenderContext -> RenderContext -> Bool
$c/= :: RenderContext -> RenderContext -> Bool
== :: RenderContext -> RenderContext -> Bool
$c== :: RenderContext -> RenderContext -> Bool
Eq)

-- | Render 'CslJson' as 'Text'.  Set the first parameter to True
-- when rendering HTML output (so that entities are escaped).
-- Set it to False when rendering for CSL JSON bibliographies.
renderCslJson :: Bool          -- ^ Escape < > & using entities
              -> Locale        -- ^ Locale (used for quote styles)
              -> CslJson Text  -- ^ CslJson to render
              -> Text
renderCslJson :: Bool -> Locale -> CslJson Text -> Text
renderCslJson useEntities :: Bool
useEntities locale :: Locale
locale =
  RenderContext -> CslJson Text -> Text
go (Bool -> Bool -> Bool -> Bool -> RenderContext
RenderContext Bool
True Bool
True Bool
True Bool
True)
 where
  (outerQuotes :: (Text, Text)
outerQuotes, innerQuotes :: (Text, Text)
innerQuotes) = Locale -> ((Text, Text), (Text, Text))
lookupQuotes Locale
locale
  go :: RenderContext -> CslJson Text -> Text
  go :: RenderContext -> CslJson Text -> Text
go ctx :: RenderContext
ctx el :: CslJson Text
el =
    case CslJson Text
el of
      CslText t :: Text
t -> Text -> Text
escape Text
t
      CslEmpty -> Text
forall a. Monoid a => a
mempty
      CslConcat x :: CslJson Text
x y :: 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 x :: 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 :: Bool
useOuterQuotes = Bool
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 :: Bool
useOuterQuotes = Bool
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 x :: CslJson Text
x
        | RenderContext -> Bool
useItalics RenderContext
ctx -> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x
        | Bool
otherwise      -> "<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
<> "</span>"
      CslItalic x :: CslJson Text
x
        | RenderContext -> Bool
useItalics RenderContext
ctx -> "<i>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useItalics :: Bool
useItalics = Bool
False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "</i>"
        | Bool
otherwise -> "<span style=\"font-style:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                          RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useItalics :: Bool
useItalics = Bool
True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "</span>"
      CslBold x :: CslJson Text
x
        | RenderContext -> Bool
useBold RenderContext
ctx -> "<b>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useBold :: Bool
useBold = Bool
False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "</b>"
        | Bool
otherwise -> "<span style=\"font-weight:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                          RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useBold :: Bool
useBold = Bool
True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "</span>"
      CslUnderline x :: CslJson Text
x -> "<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
<> "</u>"
      CslNoDecoration x :: CslJson Text
x -> "<span style=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                           (if RenderContext -> Bool
useSmallCaps RenderContext
ctx
                               then ""
                               else "font-variant:normal;") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                           (if RenderContext -> Bool
useBold RenderContext
ctx
                               then ""
                               else "font-weight:normal;") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                           (if RenderContext -> Bool
useItalics RenderContext
ctx
                               then ""
                               else "font-style:normal;") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                           "\">" 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
<> "</span>"
      CslSmallCaps x :: CslJson Text
x
        | RenderContext -> Bool
useSmallCaps RenderContext
ctx -> "<span style=\"font-variant:small-caps;\">"
                                Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useSmallCaps :: Bool
useSmallCaps = Bool
False } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                                "</span>"
        | Bool
otherwise -> "<span style=\"font-variant:normal;\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                          RenderContext -> CslJson Text -> Text
go RenderContext
ctx{ useSmallCaps :: Bool
useSmallCaps = Bool
True } CslJson Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "</span>"
      CslSup x :: CslJson Text
x -> "<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
<> "</sup>"
      CslSub x :: CslJson Text
x -> "<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
<> "</sub>"
      CslBaseline x :: CslJson Text
x -> "<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
<> "</span>"
      CslDiv t :: Text
t x :: CslJson Text
x -> "<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
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
<> "</div>"
      CslLink t :: Text
t x :: CslJson Text
x -> "<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
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
<> "</a>"
      CslNoCase x :: CslJson Text
x -> RenderContext -> CslJson Text -> Text
go RenderContext
ctx CslJson Text
x -- nocase is just for internal purposes
  escape :: Text -> Text
escape t :: Text
t
    | Bool
useEntities
      = case (Char -> Bool) -> Text -> Maybe Int
T.findIndex (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '<' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '>' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '&') Text
t of
               Just _ -> Text -> Text -> Text -> Text
T.replace "<" "&#60;" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                         Text -> Text -> Text -> Text
T.replace ">" "&#62;" (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                         Text -> Text -> Text -> Text
T.replace "&" "&#38;" (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
t
               Nothing -> Text
t
    | Bool
otherwise = Text
t

-- localized quotes
convertQuotes :: Locale -> CslJson Text -> CslJson Text
convertQuotes :: Locale -> CslJson Text -> CslJson Text
convertQuotes locale :: Locale
locale = Bool -> CslJson Text -> CslJson Text
go Bool
True
 where
  (outerQuotes :: (Text, Text)
outerQuotes, innerQuotes :: (Text, Text)
innerQuotes) = Locale -> ((Text, Text), (Text, Text))
lookupQuotes Locale
locale

  go :: Bool -> CslJson Text -> CslJson Text
go useOuter :: Bool
useOuter el :: CslJson Text
el =
    case CslJson Text
el of
      CslConcat x :: CslJson Text
x y :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 x :: 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 t :: Text
t x :: 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 x :: 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
      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 _) = Bool
True
  isString _ = Bool
False
  consolidateStrings :: [Value] -> [Value]
  consolidateStrings :: [Value] -> [Value]
consolidateStrings [] = []
  consolidateStrings (String t :: Text
t : rest :: [Value]
rest) =
    let (xs :: [Value]
xs,ys :: [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 t' :: Text
t' <- [Value]
xs]) Value -> [Value] -> [Value]
forall a. a -> [a] -> [a]
:
        [Value] -> [Value]
consolidateStrings [Value]
ys
  consolidateStrings (x :: Value
x : rest :: [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 ctx :: RenderContext
ctx el :: CslJson Text
el = [Value] -> [Value]
consolidateStrings ([Value] -> [Value]) -> [Value] -> [Value]
forall a b. (a -> b) -> a -> b
$
    case CslJson Text
el of
      CslText t :: Text
t -> [Text -> Value
String Text
t]
      CslEmpty -> []
      CslConcat x :: CslJson Text
x CslEmpty -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x
      CslConcat (CslConcat x :: CslJson Text
x y :: CslJson Text
y) z :: 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 x :: CslJson Text
x y :: 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 x :: CslJson Text
x -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x  -- should be localized already
      CslNormal x :: CslJson Text
x
        | RenderContext -> Bool
useItalics RenderContext
ctx -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x
        | Bool
otherwise      -> [ [Pair] -> Value
object
                               [ ("format", "no-italics")
                               , ("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 x :: CslJson Text
x
        | RenderContext -> Bool
useItalics RenderContext
ctx -> [ [Pair] -> Value
object
                               [ ("format", "italics")
                               , ("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 :: Bool
useItalics = Bool
False } CslJson Text
x)
                               ]
                            ]
        | Bool
otherwise      -> [ [Pair] -> Value
object
                               [ ("format", "no-italics")
                               , ("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 :: Bool
useItalics = Bool
False } CslJson Text
x)
                               ]
                            ]
      CslBold x :: CslJson Text
x
        | RenderContext -> Bool
useItalics RenderContext
ctx -> [ [Pair] -> Value
object
                               [ ("format", "bold")
                               , ("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 :: Bool
useBold = Bool
False } CslJson Text
x)
                               ]
                            ]
        | Bool
otherwise      -> [ [Pair] -> Value
object
                               [ ("format", "no-bold")
                               , ("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 :: Bool
useBold = Bool
False } CslJson Text
x)
                               ]
                            ]
      CslUnderline x :: CslJson Text
x     -> [ [Pair] -> Value
object
                               [ ("format", "underline")
                               , ("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 x :: CslJson Text
x -> [ [Pair] -> Value
object
                               [ ("format", "no-decoration")
                               , ("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 x :: CslJson Text
x
        | RenderContext -> Bool
useSmallCaps RenderContext
ctx -> [ [Pair] -> Value
object
                               [ ("format", "small-caps")
                               , ("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 :: Bool
useSmallCaps = Bool
False } CslJson Text
x)
                               ]
                            ]
        | Bool
otherwise      -> [ [Pair] -> Value
object
                               [ ("format", "no-small-caps")
                               , ("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 :: Bool
useSmallCaps = Bool
False } CslJson Text
x)
                               ]
                            ]
      CslSup x :: CslJson Text
x           -> [ [Pair] -> Value
object
                               [ ("format", "superscript")
                               , ("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 x :: CslJson Text
x           -> [ [Pair] -> Value
object
                               [ ("format", "subscript")
                               , ("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 x :: CslJson Text
x      -> [ [Pair] -> Value
object
                               [ ("format", "baseline")
                               , ("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 t :: Text
t x :: CslJson Text
x         -> [ [Pair] -> Value
object
                               [ ("format", "div")
                               , ("class", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ "csl-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t)
                               , ("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 t :: Text
t x :: CslJson Text
x        -> [ [Pair] -> Value
object
                               [ ("format", "link")
                               , ("target", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Text
t)
                               , ("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 x :: CslJson Text
x -> RenderContext -> CslJson Text -> [Value]
go RenderContext
ctx CslJson Text
x -- nocase is just for internal purposes


-- custom traversal which does not descend into
-- CslSmallCaps, Baseline, SUp, Sub, or NoCase (implicit nocase)
caseTransform' :: (CaseTransformState -> Text -> Text)
               -> Int -- level in hierarchy
               -> CslJson Text
               -> State CaseTransformState (CslJson Text)
caseTransform' :: (CaseTransformState -> Text -> Text)
-> Int -> CslJson Text -> State CaseTransformState (CslJson Text)
caseTransform' f :: CaseTransformState -> Text -> Text
f lev :: Int
lev el :: CslJson Text
el =
  case CslJson Text
el of
     CslText x :: 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)
mapM Text -> StateT CaseTransformState Identity Text
g (Text -> [Text]
splitUp Text
x)
     CslConcat x :: CslJson Text
x y :: 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
== 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 (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 x :: 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
+ 1) CslJson Text
x
     CslItalic x :: 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
+ 1) CslJson Text
x
     CslNormal x :: 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
+ 1) CslJson Text
x
     CslBold   x :: 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
+ 1) CslJson Text
x
     CslUnderline x :: 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
+ 1) CslJson Text
x
     CslNoDecoration _ -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslSmallCaps _    -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslBaseline _     -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslSub _          -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslSup _          -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslNoCase _       -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslDiv _ _        -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslLink _ _       -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
     CslEmpty          -> CslJson Text -> State CaseTransformState (CslJson Text)
forall a.
CiteprocOutput a =>
a -> StateT CaseTransformState Identity a
return' CslJson Text
el
 where
  -- we need to apply g to update the state:
  return' :: a -> StateT CaseTransformState Identity a
return' x :: a
x = a
x a
-> StateT CaseTransformState Identity Text
-> 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 t :: 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
            Nothing -> CaseTransformState
st
            Just (_,c :: Char
c)
              | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '.' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '?' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '!' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ':' ->
                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 (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 '-' = Bool
True
  isWordBreak '/' = Bool
True
  isWordBreak '\x2013' = Bool
True
  isWordBreak '\x2014' = Bool
True
  isWordBreak c :: 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 c :: Char
c d :: 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)

caseTransform :: Maybe Lang
              -> CaseTransformer
              -> CslJson Text
              -> CslJson Text
caseTransform :: Maybe Lang -> CaseTransformer -> CslJson Text -> CslJson Text
caseTransform mblang :: Maybe Lang
mblang f :: CaseTransformer
f x :: 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) 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 t :: Text
t =
    case Text -> Maybe (Char, Text)
T.uncons Text
t of
      Just (c :: Char
c,_) -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '.' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ','
      Nothing    -> Bool
False
  go :: CslJson Text -> CslJson Text
go el :: CslJson Text
el =
    case CslJson Text
el of
      CslConcat CslEmpty x :: CslJson Text
x -> CslJson Text -> CslJson Text
go CslJson Text
x
      CslConcat x :: CslJson Text
x CslEmpty -> CslJson Text -> CslJson Text
go CslJson Text
x
      CslConcat (CslQuoted x :: CslJson Text
x) y :: CslJson Text
y ->
         case CslJson Text -> CslJson Text
go CslJson Text
y of
           (CslText t :: 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 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 1 Text
t)
           (CslConcat (CslText t :: Text
t) z :: 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 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 1 Text
t) CslJson Text -> CslJson Text -> CslJson Text
forall a. Semigroup a => a -> a -> a
<> CslJson Text
z
           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 x :: CslJson Text
x y :: CslJson Text
y) z :: 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 x :: CslJson Text
x y :: 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 x :: CslJson Text
x                 -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslQuoted (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslItalic x :: CslJson Text
x                 -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslItalic (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslNormal x :: CslJson Text
x                 -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNormal (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslBold x :: CslJson Text
x                   -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBold (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslUnderline x :: CslJson Text
x              -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslUnderline (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslNoDecoration x :: CslJson Text
x           -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoDecoration (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslSmallCaps x :: CslJson Text
x              -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSmallCaps (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslSup x :: CslJson Text
x                    -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslSub x :: CslJson Text
x                    -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSub (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslBaseline x :: CslJson Text
x               -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslBaseline (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslNoCase x :: CslJson Text
x                 -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslNoCase (CslJson Text -> CslJson Text
go CslJson Text
x)
      CslDiv t :: Text
t x :: 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 t :: Text
t x :: 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 t :: Text
t                   -> Text -> CslJson Text
forall a. a -> CslJson a
CslText Text
t
      CslEmpty                    -> CslJson Text
forall a. CslJson a
CslEmpty

superscriptChars :: [Char]
superscriptChars :: String
superscriptChars =
  [ '\x00AA'
  , '\x00B2'
  , '\x00B3'
  , '\x00B9'
  , '\x00BA'
  , '\x02B0'
  , '\x02B1'
  , '\x02B2'
  , '\x02B3'
  , '\x02B4'
  , '\x02B5'
  , '\x02B6'
  , '\x02B7'
  , '\x02B8'
  , '\x02E0'
  , '\x02E1'
  , '\x02E2'
  , '\x02E3'
  , '\x02E4'
  , '\x1D2C'
  , '\x1D2D'
  , '\x1D2E'
  , '\x1D30'
  , '\x1D31'
  , '\x1D32'
  , '\x1D33'
  , '\x1D34'
  , '\x1D35'
  , '\x1D36'
  , '\x1D37'
  , '\x1D38'
  , '\x1D39'
  , '\x1D3A'
  , '\x1D3C'
  , '\x1D3D'
  , '\x1D3E'
  , '\x1D3F'
  , '\x1D40'
  , '\x1D41'
  , '\x1D42'
  , '\x1D43'
  , '\x1D44'
  , '\x1D45'
  , '\x1D46'
  , '\x1D47'
  , '\x1D48'
  , '\x1D49'
  , '\x1D4A'
  , '\x1D4B'
  , '\x1D4C'
  , '\x1D4D'
  , '\x1D4F'
  , '\x1D50'
  , '\x1D51'
  , '\x1D52'
  , '\x1D53'
  , '\x1D54'
  , '\x1D55'
  , '\x1D56'
  , '\x1D57'
  , '\x1D58'
  , '\x1D59'
  , '\x1D5A'
  , '\x1D5B'
  , '\x1D5C'
  , '\x1D5D'
  , '\x1D5E'
  , '\x1D5F'
  , '\x1D60'
  , '\x1D61'
  , '\x2070'
  , '\x2071'
  , '\x2074'
  , '\x2075'
  , '\x2076'
  , '\x2077'
  , '\x2078'
  , '\x2079'
  , '\x207A'
  , '\x207B'
  , '\x207C'
  , '\x207D'
  , '\x207E'
  , '\x207F'
  , '\x2120'
  , '\x2122'
  , '\x3192'
  , '\x3193'
  , '\x3194'
  , '\x3195'
  , '\x3196'
  , '\x3197'
  , '\x3198'
  , '\x3199'
  , '\x319A'
  , '\x319B'
  , '\x319C'
  , '\x319D'
  , '\x319E'
  , '\x319F'
  , '\x02C0'
  , '\x02C1'
  , '\x06E5'
  , '\x06E6'
  ]

charToSup :: Char -> CslJson Text
charToSup :: Char -> CslJson Text
charToSup c :: Char
c =
  case Char
c of
    '\x00AA' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0061")
    '\x00B2' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0032")
    '\x00B3' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0033")
    '\x00B9' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0031")
    '\x00BA' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006F")
    '\x02B0' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0068")
    '\x02B1' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0266")
    '\x02B2' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006A")
    '\x02B3' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0072")
    '\x02B4' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0279")
    '\x02B5' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x027B")
    '\x02B6' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0281")
    '\x02B7' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0077")
    '\x02B8' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0079")
    '\x02E0' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0263")
    '\x02E1' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006C")
    '\x02E2' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0073")
    '\x02E3' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0078")
    '\x02E4' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0295")
    '\x1D2C' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0041")
    '\x1D2D' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x00C6")
    '\x1D2E' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0042")
    '\x1D30' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0044")
    '\x1D31' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0045")
    '\x1D32' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x018E")
    '\x1D33' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0047")
    '\x1D34' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0048")
    '\x1D35' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0049")
    '\x1D36' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x004A")
    '\x1D37' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x004B")
    '\x1D38' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x004C")
    '\x1D39' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x004D")
    '\x1D3A' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x004E")
    '\x1D3C' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x004F")
    '\x1D3D' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0222")
    '\x1D3E' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0050")
    '\x1D3F' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0052")
    '\x1D40' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0054")
    '\x1D41' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0055")
    '\x1D42' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0057")
    '\x1D43' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0061")
    '\x1D44' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0250")
    '\x1D45' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0251")
    '\x1D46' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x1D02")
    '\x1D47' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0062")
    '\x1D48' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0064")
    '\x1D49' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0065")
    '\x1D4A' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0259")
    '\x1D4B' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x025B")
    '\x1D4C' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x025C")
    '\x1D4D' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0067")
    '\x1D4F' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006B")
    '\x1D50' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006D")
    '\x1D51' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x014B")
    '\x1D52' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006F")
    '\x1D53' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0254")
    '\x1D54' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x1D16")
    '\x1D55' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x1D17")
    '\x1D56' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0070")
    '\x1D57' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0074")
    '\x1D58' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0075")
    '\x1D59' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x1D1D")
    '\x1D5A' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x026F")
    '\x1D5B' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0076")
    '\x1D5C' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x1D25")
    '\x1D5D' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x03B2")
    '\x1D5E' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x03B3")
    '\x1D5F' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x03B4")
    '\x1D60' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x03C6")
    '\x1D61' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x03C7")
    '\x2070' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0030")
    '\x2071' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0069")
    '\x2074' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0034")
    '\x2075' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0035")
    '\x2076' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0036")
    '\x2077' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0037")
    '\x2078' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0038")
    '\x2079' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0039")
    '\x207A' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x002B")
    '\x207B' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x2212")
    '\x207C' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x003D")
    '\x207D' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0028")
    '\x207E' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0029")
    '\x207F' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x006E")
    '\x2120' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0053\x004D")
    '\x2122' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0054\x004D")
    '\x3192' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E00")
    '\x3193' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E8C")
    '\x3194' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E09")
    '\x3195' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x56DB")
    '\x3196' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E0A")
    '\x3197' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E2D")
    '\x3198' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E0B")
    '\x3199' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x7532")
    '\x319A' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E59")
    '\x319B' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E19")
    '\x319C' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4E01")
    '\x319D' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x5929")
    '\x319E' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x5730")
    '\x319F' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x4EBA")
    '\x02C0' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0294")
    '\x02C1' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0295")
    '\x06E5' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x0648")
    '\x06E6' -> CslJson Text -> CslJson Text
forall a. CslJson a -> CslJson a
CslSup (Text -> CslJson Text
forall a. a -> CslJson a
CslText "\x064A")
    _        -> Text -> CslJson Text
forall a. a -> CslJson a
CslText (Text -> CslJson Text) -> Text -> CslJson Text
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c