{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
module Text.CSL.Eval.Output where
import Prelude
import Data.Maybe (mapMaybe)
import Data.String (fromString)
import Data.Text (Text)
import qualified Data.Text as T
import Text.CSL.Output.Pandoc (lastInline)
import Text.CSL.Style
import Text.CSL.Util (capitalize, isPunct, titlecase,
unTitlecase)
import Text.Pandoc.Definition
import Text.Pandoc.Walk (walk)
import Text.Parsec
import Text.Parsec.Text (Parser)
formatString :: Text -> Formatted
formatString :: Text -> Formatted
formatString s :: Text
s =
case Parsec Text () [Inline]
-> SourceName -> Text -> Either ParseError [Inline]
forall s t a.
Stream s Identity t =>
Parsec s () a -> SourceName -> s -> Either ParseError a
parse Parsec Text () [Inline]
pAffix (Text -> SourceName
T.unpack Text
s) Text
s of
Left _ -> SourceName -> Formatted
forall a. IsString a => SourceName -> a
fromString (Text -> SourceName
T.unpack Text
s)
Right ils :: [Inline]
ils -> [Inline] -> Formatted
Formatted [Inline]
ils
pAffix :: Parser [Inline]
pAffix :: Parsec Text () [Inline]
pAffix = ParsecT Text () Identity Inline -> Parsec Text () [Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Text () Identity Inline
pRaw ParsecT Text () Identity Inline
-> ParsecT Text () Identity Inline
-> ParsecT Text () Identity Inline
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text () Identity Inline
pString ParsecT Text () Identity Inline
-> ParsecT Text () Identity Inline
-> ParsecT Text () Identity Inline
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Text () Identity Inline
pSpace)
pRaw :: Parser Inline
pRaw :: ParsecT Text () Identity Inline
pRaw = ParsecT Text () Identity Inline -> ParsecT Text () Identity Inline
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text () Identity Inline
-> ParsecT Text () Identity Inline)
-> ParsecT Text () Identity Inline
-> ParsecT Text () Identity Inline
forall a b. (a -> b) -> a -> b
$ do
SourceName
_ <- SourceName -> ParsecT Text () Identity SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string "{{"
SourceName
format <- ParsecT Text () Identity Char
-> ParsecT Text () Identity SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT Text () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter
SourceName
_ <- SourceName -> ParsecT Text () Identity SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string "}}"
SourceName
contents <- ParsecT Text () Identity Char
-> ParsecT Text () Identity SourceName
-> ParsecT Text () Identity SourceName
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT Text () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar (ParsecT Text () Identity SourceName
-> ParsecT Text () Identity SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourceName -> ParsecT Text () Identity SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string ("{{/" SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ SourceName
format SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ "}}")))
Inline -> ParsecT Text () Identity Inline
forall (m :: * -> *) a. Monad m => a -> m a
return (Inline -> ParsecT Text () Identity Inline)
-> Inline -> ParsecT Text () Identity Inline
forall a b. (a -> b) -> a -> b
$ Format -> Text -> Inline
RawInline (Text -> Format
Format (Text -> Format) -> Text -> Format
forall a b. (a -> b) -> a -> b
$ SourceName -> Text
T.pack SourceName
format) (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ SourceName -> Text
T.pack SourceName
contents
pString :: Parser Inline
pString :: ParsecT Text () Identity Inline
pString = Text -> Inline
Str (Text -> Inline) -> (SourceName -> Text) -> SourceName -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> Text
T.pack (SourceName -> Inline)
-> ParsecT Text () Identity SourceName
-> ParsecT Text () Identity Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Text () Identity Char
-> ParsecT Text () Identity SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (SourceName -> ParsecT Text () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
noneOf " \t\n\r{}") ParsecT Text () Identity SourceName
-> ParsecT Text () Identity SourceName
-> ParsecT Text () Identity SourceName
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> ParsecT Text () Identity Char
-> ParsecT Text () Identity SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 1 (SourceName -> ParsecT Text () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
oneOf "{}"))
pSpace :: Parser Inline
pSpace :: ParsecT Text () Identity Inline
pSpace = Inline
Space Inline
-> ParsecT Text () Identity SourceName
-> ParsecT Text () Identity Inline
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text () Identity Char
-> ParsecT Text () Identity SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (SourceName -> ParsecT Text () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m Char
oneOf " \t\n\r")
output :: Formatting -> Text -> [Output]
output :: Formatting -> Text -> [Output]
output fm :: Formatting
fm s :: Text
s = case Text -> Maybe (Char, Text)
T.uncons Text
s of
Nothing -> []
Just (' ', xs :: Text
xs) -> Output
OSpace Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: Formatting -> Text -> [Output]
output Formatting
fm Text
xs
_ -> [Text -> Formatting -> Output
OStr Text
s Formatting
fm]
appendOutput :: Formatting -> [Output] -> [Output]
appendOutput :: Formatting -> [Output] -> [Output]
appendOutput fm :: Formatting
fm xs :: [Output]
xs = [[Output] -> Formatting -> Output
Output [Output]
xs Formatting
fm | [Output]
xs [Output] -> [Output] -> Bool
forall a. Eq a => a -> a -> Bool
/= []]
outputList :: Formatting -> Delimiter -> [Output] -> [Output]
outputList :: Formatting -> Text -> [Output] -> [Output]
outputList fm :: Formatting
fm d :: Text
d = Formatting -> [Output] -> [Output]
appendOutput Formatting
fm ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Output] -> [Output]
addDelim Text
d ([Output] -> [Output])
-> ([Output] -> [Output]) -> [Output] -> [Output]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Output -> Maybe Output) -> [Output] -> [Output]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Output -> Maybe Output
cleanOutput'
where
cleanOutput' :: Output -> Maybe Output
cleanOutput' o :: Output
o
| Output xs :: [Output]
xs f :: Formatting
f <- Output
o = case [Output] -> [Output]
cleanOutput [Output]
xs of
[] -> Maybe Output
forall a. Maybe a
Nothing
ys :: [Output]
ys -> Output -> Maybe Output
forall a. a -> Maybe a
Just ([Output] -> Formatting -> Output
Output [Output]
ys Formatting
f)
| Bool
otherwise = Output -> Maybe Output
rmEmptyOutput Output
o
cleanOutput :: [Output] -> [Output]
cleanOutput :: [Output] -> [Output]
cleanOutput = [Output] -> [Output]
flatten
where
flatten :: [Output] -> [Output]
flatten [] = []
flatten (o :: Output
o:os :: [Output]
os)
| Output
ONull <- Output
o = [Output] -> [Output]
flatten [Output]
os
| Output xs :: [Output]
xs f :: Formatting
f <- Output
o
, Formatting
f Formatting -> Formatting -> Bool
forall a. Eq a => a -> a -> Bool
== Formatting
emptyFormatting = [Output] -> [Output]
flatten ((Output -> Maybe Output) -> [Output] -> [Output]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Output -> Maybe Output
rmEmptyOutput [Output]
xs) [Output] -> [Output] -> [Output]
forall a. [a] -> [a] -> [a]
++ [Output] -> [Output]
flatten [Output]
os
| Output xs :: [Output]
xs f :: Formatting
f <- Output
o = [Output] -> Formatting -> Output
Output ([Output] -> [Output]
flatten ([Output] -> [Output]) -> [Output] -> [Output]
forall a b. (a -> b) -> a -> b
$ (Output -> Maybe Output) -> [Output] -> [Output]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Output -> Maybe Output
rmEmptyOutput [Output]
xs) Formatting
f Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output] -> [Output]
flatten [Output]
os
| Bool
otherwise = ([Output] -> [Output])
-> (Output -> [Output] -> [Output])
-> Maybe Output
-> [Output]
-> [Output]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Output] -> [Output]
forall a. a -> a
id (:) (Output -> Maybe Output
rmEmptyOutput Output
o) ([Output] -> [Output]) -> [Output] -> [Output]
forall a b. (a -> b) -> a -> b
$ [Output] -> [Output]
flatten [Output]
os
rmEmptyOutput :: Output -> Maybe Output
rmEmptyOutput :: Output -> Maybe Output
rmEmptyOutput o :: Output
o
| Output [] _ <- Output
o = Maybe Output
forall a. Maybe a
Nothing
| OStr "" _ <- Output
o = Maybe Output
forall a. Maybe a
Nothing
| OPan [] <- Output
o = Maybe Output
forall a. Maybe a
Nothing
| OStatus [] <- Output
o = Maybe Output
forall a. Maybe a
Nothing
| ODel "" <- Output
o = Maybe Output
forall a. Maybe a
Nothing
| Bool
otherwise = Output -> Maybe Output
forall a. a -> Maybe a
Just Output
o
addDelim :: Text -> [Output] -> [Output]
addDelim :: Text -> [Output] -> [Output]
addDelim "" = [Output] -> [Output]
forall a. a -> a
id
addDelim d :: Text
d = (Output -> [Output] -> [Output])
-> [Output] -> [Output] -> [Output]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Output -> [Output] -> [Output]
check []
where
check :: Output -> [Output] -> [Output]
check ONull xs :: [Output]
xs = [Output]
xs
check x :: Output
x [] = [Output
x]
check x :: Output
x (z :: Output
z:zs :: [Output]
zs) = if Output -> Formatted
formatOutput Output
x Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
== Formatted
forall a. Monoid a => a
mempty Bool -> Bool -> Bool
|| Output -> Formatted
formatOutput Output
z Formatted -> Formatted -> Bool
forall a. Eq a => a -> a -> Bool
== Formatted
forall a. Monoid a => a
mempty
then Output
x Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: Output
z Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
zs
else Output
x Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: Text -> Output
ODel Text
d Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: Output
z Output -> [Output] -> [Output]
forall a. a -> [a] -> [a]
: [Output]
zs
noOutputError :: Output
noOutputError :: Output
noOutputError = CiteprocError -> Output
OErr CiteprocError
NoOutput
noBibDataError :: Cite -> Output
noBibDataError :: Cite -> Output
noBibDataError c :: Cite
c = CiteprocError -> Output
OErr (CiteprocError -> Output) -> CiteprocError -> Output
forall a b. (a -> b) -> a -> b
$ Text -> CiteprocError
ReferenceNotFound (Cite -> Text
citeId Cite
c)
oStr :: Text -> [Output]
oStr :: Text -> [Output]
oStr s :: Text
s = Text -> Formatting -> [Output]
oStr' Text
s Formatting
emptyFormatting
oStr' :: Text -> Formatting -> [Output]
oStr' :: Text -> Formatting -> [Output]
oStr' "" _ = []
oStr' s :: Text
s f :: Formatting
f = [Text -> Formatting -> Output
OStr Text
s Formatting
f]
oPan :: [Inline] -> [Output]
oPan :: [Inline] -> [Output]
oPan [] = []
oPan ils :: [Inline]
ils = [[Inline] -> Output
OPan [Inline]
ils]
oPan' :: [Inline] -> Formatting -> [Output]
oPan' :: [Inline] -> Formatting -> [Output]
oPan' [] _ = []
oPan' ils :: [Inline]
ils f :: Formatting
f = [[Output] -> Formatting -> Output
Output [[Inline] -> Output
OPan [Inline]
ils] Formatting
f]
formatOutputList :: [Output] -> Formatted
formatOutputList :: [Output] -> Formatted
formatOutputList = [Formatted] -> Formatted
forall a. Monoid a => [a] -> a
mconcat ([Formatted] -> Formatted)
-> ([Output] -> [Formatted]) -> [Output] -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Output -> Formatted) -> [Output] -> [Formatted]
forall a b. (a -> b) -> [a] -> [b]
map Output -> Formatted
formatOutput
formatOutput :: Output -> Formatted
formatOutput :: Output -> Formatted
formatOutput o :: Output
o =
case Output
o of
OSpace -> [Inline] -> Formatted
Formatted [Inline
Space]
OPan i :: [Inline]
i -> [Inline] -> Formatted
Formatted [Inline]
i
OStatus i :: [Inline]
i -> [Inline] -> Formatted
Formatted [Inline]
i
ODel "" -> [Inline] -> Formatted
Formatted []
ODel " " -> [Inline] -> Formatted
Formatted [Inline
Space]
ODel "\n" -> [Inline] -> Formatted
Formatted [Inline
SoftBreak]
ODel s :: Text
s -> Text -> Formatted
formatString Text
s
OStr "" _ -> [Inline] -> Formatted
Formatted []
OStr s :: Text
s f :: Formatting
f -> Formatting -> Formatted -> Formatted
addFormatting Formatting
f (Formatted -> Formatted) -> Formatted -> Formatted
forall a b. (a -> b) -> a -> b
$ Text -> Formatted
formatString Text
s
OErr NoOutput -> [Inline] -> Formatted
Formatted [Attr -> [Inline] -> Inline
Span ("",["citeproc-no-output"],[])
[[Inline] -> Inline
Strong [Text -> Inline
Str "???"]]]
OErr (ReferenceNotFound r :: Text
r)
-> [Inline] -> Formatted
Formatted [Attr -> [Inline] -> Inline
Span ("",["citeproc-not-found"],
[("data-reference-id",Text
r)])
[[Inline] -> Inline
Strong [Text -> Inline
Str "???"]]]
OLabel "" _ -> [Inline] -> Formatted
Formatted []
OLabel s :: Text
s f :: Formatting
f -> Formatting -> Formatted -> Formatted
addFormatting Formatting
f (Formatted -> Formatted) -> Formatted -> Formatted
forall a b. (a -> b) -> a -> b
$ Text -> Formatted
formatString Text
s
ODate os :: [Output]
os -> [Output] -> Formatted
formatOutputList [Output]
os
OYear s :: Text
s _ f :: Formatting
f -> Formatting -> Formatted -> Formatted
addFormatting Formatting
f (Formatted -> Formatted) -> Formatted -> Formatted
forall a b. (a -> b) -> a -> b
$ Text -> Formatted
formatString Text
s
OYearSuf s :: Text
s _ _ f :: Formatting
f -> Formatting -> Formatted -> Formatted
addFormatting Formatting
f (Formatted -> Formatted) -> Formatted -> Formatted
forall a b. (a -> b) -> a -> b
$ Text -> Formatted
formatString Text
s
ONum i :: Int
i f :: Formatting
f -> Output -> Formatted
formatOutput (Text -> Formatting -> Output
OStr (SourceName -> Text
T.pack (Int -> SourceName
forall a. Show a => a -> SourceName
show Int
i)) Formatting
f)
OCitNum i :: Int
i f :: Formatting
f -> if Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
then [Inline] -> Formatted
Formatted [[Inline] -> Inline
Strong [Text -> Inline
Str "???"]]
else Output -> Formatted
formatOutput (Text -> Formatting -> Output
OStr (SourceName -> Text
T.pack (SourceName -> Text) -> SourceName -> Text
forall a b. (a -> b) -> a -> b
$ Int -> SourceName
forall a. Show a => a -> SourceName
show Int
i) Formatting
f)
OCitLabel s :: Text
s f :: Formatting
f -> if Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== ""
then [Inline] -> Formatted
Formatted [[Inline] -> Inline
Strong [Text -> Inline
Str "???"]]
else Output -> Formatted
formatOutput (Text -> Formatting -> Output
OStr Text
s Formatting
f)
OName _ os :: [Output]
os _ f :: Formatting
f -> Output -> Formatted
formatOutput ([Output] -> Formatting -> Output
Output [Output]
os Formatting
f)
OContrib _ _ os :: [Output]
os _ _ -> [Output] -> Formatted
formatOutputList [Output]
os
OLoc os :: [Output]
os f :: Formatting
f -> Output -> Formatted
formatOutput ([Output] -> Formatting -> Output
Output [Output]
os Formatting
f)
Output [] _ -> [Inline] -> Formatted
Formatted []
Output os :: [Output]
os f :: Formatting
f -> Formatting -> Formatted -> Formatted
addFormatting Formatting
f (Formatted -> Formatted) -> Formatted -> Formatted
forall a b. (a -> b) -> a -> b
$ [Output] -> Formatted
formatOutputList [Output]
os
_ -> [Inline] -> Formatted
Formatted []
addFormatting :: Formatting -> Formatted -> Formatted
addFormatting :: Formatting -> Formatted -> Formatted
addFormatting f :: Formatting
f =
Formatted -> Formatted
addDisplay (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
addLink (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
addSuffix (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
pref (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
quote (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
font (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
text_case (Formatted -> Formatted)
-> (Formatted -> Formatted) -> Formatted -> Formatted
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> Formatted
strip_periods
where addLink :: Formatted -> Formatted
addLink i :: Formatted
i = case Formatting -> Text
hyperlink Formatting
f of
"" -> Formatted
i
url :: Text
url -> [Inline] -> Formatted
Formatted [Attr -> [Inline] -> Target -> Inline
Link Attr
nullAttr (Formatted -> [Inline]
unFormatted Formatted
i) (Text
url, "")]
pref :: Formatted -> Formatted
pref i :: Formatted
i = case Formatting -> Text
prefix Formatting
f of
"" -> Formatted
i
x :: Text
x -> Text -> Formatted
formatString Text
x Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> Formatted
i
addSuffix :: Formatted -> Formatted
addSuffix i :: Formatted
i
| Text -> Bool
T.null (Formatting -> Text
suffix Formatting
f) = Formatted
i
| Bool -> ((Char, Text) -> Bool) -> Maybe (Char, Text) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Char -> Bool
isPunct (Char -> Bool) -> ((Char, Text) -> Char) -> (Char, Text) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char, Text) -> Char
forall a b. (a, b) -> a
fst) (Text -> Maybe (Char, Text)
T.uncons (Formatting -> Text
suffix Formatting
f))
, case [Inline] -> Maybe Char
lastInline (Formatted -> [Inline]
unFormatted Formatted
i) of {Just c :: Char
c | Char -> Bool
isPunct Char
c -> Bool
True; _ -> Bool
False}
= Formatted
i Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> Text -> Formatted
formatString (Text -> Text
T.tail (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Formatting -> Text
suffix Formatting
f)
| Bool
otherwise = Formatted
i Formatted -> Formatted -> Formatted
forall a. Semigroup a => a -> a -> a
<> Text -> Formatted
formatString (Formatting -> Text
suffix Formatting
f)
strip_periods :: Formatted -> Formatted
strip_periods (Formatted ils :: [Inline]
ils) = [Inline] -> Formatted
Formatted ((Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
removePeriod [Inline]
ils)
removePeriod :: Inline -> Inline
removePeriod (Str xs :: Text
xs) | Formatting -> Bool
stripPeriods Formatting
f = Text -> Inline
Str ((Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='.') Text
xs)
removePeriod x :: Inline
x = Inline
x
quote :: Formatted -> Formatted
quote (Formatted []) = [Inline] -> Formatted
Formatted []
quote (Formatted ils :: [Inline]
ils) =
case Formatting -> Quote
quotes Formatting
f of
NoQuote -> [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Inline]
valign [Inline]
ils
NativeQuote -> [Inline] -> Formatted
Formatted
[Attr -> [Inline] -> Inline
Span ("",["csl-inquote"],[]) [Inline]
ils]
_ -> [Inline] -> Formatted
Formatted [QuoteType -> [Inline] -> Inline
Quoted QuoteType
DoubleQuote ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Inline]
valign [Inline]
ils]
addDisplay :: Formatted -> Formatted
addDisplay (Formatted []) = [Inline] -> Formatted
Formatted []
addDisplay (Formatted ils :: [Inline]
ils) =
case Formatting -> Text
display Formatting
f of
"block" -> [Inline] -> Formatted
Formatted (Inline
LineBreak Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
ils [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++
[Inline
LineBreak])
_ -> [Inline] -> Formatted
Formatted [Inline]
ils
font :: Formatted -> Formatted
font (Formatted ils :: [Inline]
ils)
| Formatting -> Bool
noDecor Formatting
f = [Inline] -> Formatted
Formatted [Attr -> [Inline] -> Inline
Span ("",["nodecor"],[]) [Inline]
ils]
| Bool
otherwise = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Inline]
font_variant ([Inline] -> [Inline])
-> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
font_style ([Inline] -> [Inline])
-> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
font_weight ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (a -> b) -> a -> b
$ [Inline]
ils
font_variant :: [Inline] -> [Inline]
font_variant ils :: [Inline]
ils =
case Formatting -> Text
fontVariant Formatting
f of
"small-caps" -> [[Inline] -> Inline
SmallCaps [Inline]
ils]
_ -> [Inline]
ils
font_style :: [Inline] -> [Inline]
font_style ils :: [Inline]
ils =
case Formatting -> Text
fontStyle Formatting
f of
"italic" -> [[Inline] -> Inline
Emph [Inline]
ils]
"oblique" -> [[Inline] -> Inline
Emph [Inline]
ils]
_ -> [Inline]
ils
font_weight :: [Inline] -> [Inline]
font_weight ils :: [Inline]
ils =
case Formatting -> Text
fontWeight Formatting
f of
"bold" -> [[Inline] -> Inline
Strong [Inline]
ils]
_ -> [Inline]
ils
text_case :: Formatted -> Formatted
text_case (Formatted []) = [Inline] -> Formatted
Formatted []
text_case (Formatted ils :: [Inline]
ils@(i :: Inline
i:is' :: [Inline]
is'))
| Formatting -> Bool
noCase Formatting
f = [Inline] -> Formatted
Formatted [Attr -> [Inline] -> Inline
Span ("",["nocase"],[]) [Inline]
ils]
| Bool
otherwise = [Inline] -> Formatted
Formatted ([Inline] -> Formatted) -> [Inline] -> Formatted
forall a b. (a -> b) -> a -> b
$
case Formatting -> Text
textCase Formatting
f of
"lowercase" -> (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
lowercaseStr [Inline]
ils
"uppercase" -> (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
uppercaseStr [Inline]
ils
"capitalize-all" -> (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
capitalizeStr [Inline]
ils
"title" -> [Inline] -> [Inline]
titlecase [Inline]
ils
"capitalize-first"
-> case Inline
i of
Str cs :: Text
cs -> Text -> Inline
Str (Text -> Text
capitalize Text
cs) Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
is'
_ -> [Inline] -> [Inline]
unTitlecase [Inline
i] [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline]
is'
"sentence" -> [Inline] -> [Inline]
unTitlecase [Inline]
ils
_ -> [Inline]
ils
lowercaseStr :: Inline -> Inline
lowercaseStr (Str xs :: Text
xs) = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toLower Text
xs
lowercaseStr x :: Inline
x = Inline
x
uppercaseStr :: Inline -> Inline
uppercaseStr (Str xs :: Text
xs) = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toUpper Text
xs
uppercaseStr x :: Inline
x = Inline
x
capitalizeStr :: Inline -> Inline
capitalizeStr (Str xs :: Text
xs) = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ Text -> Text
capitalize Text
xs
capitalizeStr x :: Inline
x = Inline
x
valign :: [Inline] -> [Inline]
valign [] = []
valign ils :: [Inline]
ils
| Text
"sup" <- Formatting -> Text
verticalAlign Formatting
f = [[Inline] -> Inline
Superscript [Inline]
ils]
| Text
"sub" <- Formatting -> Text
verticalAlign Formatting
f = [[Inline] -> Inline
Subscript [Inline]
ils]
| Text
"baseline" <- Formatting -> Text
verticalAlign Formatting
f =
[Attr -> [Inline] -> Inline
Span ("",["csl-baseline"],[]) [Inline]
ils]
| Bool
otherwise = [Inline]
ils