{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns      #-}

{-# LANGUAGE PatternGuards      #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Text.CSL.Output.Pandoc
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Andrea Rossato <andrea.rossato@unitn.it>
-- Stability   :  unstable
-- Portability :  unportable
--
-- The pandoc output formatter for CSL
--
-----------------------------------------------------------------------------

module Text.CSL.Output.Pandoc
    ( renderPandoc
    , renderPandoc'
    , headInline
    , initInline
    , lastInline
    , tailInline
    , tailFirstInlineStr
    , toCapital
    ) where

import Prelude
import           Data.List              (dropWhileEnd)
import           Data.Maybe             (fromMaybe)
import           Data.Text              (Text)
import qualified Data.Text              as T
import           Text.CSL.Style
import           Text.CSL.Util          (headInline, initInline, lastInline,
                                         proc, proc', tailFirstInlineStr,
                                         tailInline, toCapital)
import           Text.Pandoc.Definition
import           Text.Pandoc.XML        (fromEntities)

renderPandoc :: Style -> Formatted -> [Inline]
renderPandoc :: Style -> Formatted -> [Inline]
renderPandoc sty :: Style
sty
    = ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc (Style -> [Inline] -> [Inline]
convertQuoted Style
sty) ([Inline] -> [Inline])
-> (Formatted -> [Inline]) -> Formatted -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (Typeable a, Data b) => (a -> a) -> b -> b
proc' (Style -> [Inline] -> [Inline]
clean' Style
sty) ([Inline] -> [Inline])
-> (Formatted -> [Inline]) -> Formatted -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
flipFlop ([Inline] -> [Inline])
-> (Formatted -> [Inline]) -> Formatted -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      [Inline] -> [Inline]
fixBreaks ([Inline] -> [Inline])
-> (Formatted -> [Inline]) -> Formatted -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Formatted -> [Inline]
unFormatted

-- remove leading/trailing LineBreak
fixBreaks :: [Inline] -> [Inline]
fixBreaks :: [Inline] -> [Inline]
fixBreaks = (Inline -> Bool) -> [Inline] -> [Inline]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Inline
LineBreak) ([Inline] -> [Inline])
-> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Bool) -> [Inline] -> [Inline]
forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd (Inline -> Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Inline
LineBreak)

renderPandoc' :: Style -> (Formatted, Text) -> Block
renderPandoc' :: Style -> (Formatted, Text) -> Block
renderPandoc' sty :: Style
sty (form :: Formatted
form, citId :: Text
citId) = Attr -> [Block] -> Block
Div ("ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
citId, [], []) [[Inline] -> Block
Para ([Inline] -> Block) -> [Inline] -> Block
forall a b. (a -> b) -> a -> b
$ Style -> Formatted -> [Inline]
renderPandoc Style
sty Formatted
form]

clean' :: Style -> [Inline] -> [Inline]
clean' :: Style -> [Inline] -> [Inline]
clean' _   []  = []
clean' sty :: Style
sty (i :: Inline
i:is :: [Inline]
is) =
  case Inline
iInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[Inline]
is of
      (Str "" : rest :: [Inline]
rest) -> Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
rest
      (Str xs :: Text
xs : Str ys :: Text
ys : rest :: [Inline]
rest) -> Style -> [Inline] -> [Inline]
clean' Style
sty ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. (a -> b) -> a -> b
$ Text -> Inline
Str (Text
xs Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ys) Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
rest
      (Link a1 :: Attr
a1 lab1 :: [Inline]
lab1 (Text -> Maybe (Char, Text)
T.uncons -> Just ('#',r1 :: Text
r1), "")
       : Str "\8211" : Link a2 :: Attr
a2 lab2 :: [Inline]
lab2 (Text -> Maybe (Char, Text)
T.uncons -> Just ('#',r2 :: Text
r2), "") : rest :: [Inline]
rest)
        | Text
r1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
r2, Attr
a1 Attr -> Attr -> Bool
forall a. Eq a => a -> a -> Bool
== Attr
a2 ->
           Attr -> [Inline] -> Target -> Inline
Link Attr
a1 ([Inline]
lab1 [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Text -> Inline
Str "\8211"] [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline]
lab2) (Char -> Text -> Text
T.cons '#' Text
r1, "") Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
rest
      (Span ("",[],[]) inls :: [Inline]
inls : _) -> [Inline]
inls [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
is
      (Span ("",["csl-inquote"],kvs :: [Target]
kvs) inls :: [Inline]
inls : _) ->
         let isOuter :: Bool
isOuter = Text -> [Target] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "position" [Target]
kvs Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just "outer"
         in  case [Inline] -> Maybe Char
headInline [Inline]
is of
               Just x :: Char
x -> if Char
x Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (".," :: String) Bool -> Bool -> Bool
&& Style -> Bool
isPunctuationInQuote Style
sty
                         then if [Inline] -> Maybe Char
lastInline [Inline]
inls Maybe Char -> [Maybe Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (Char -> Maybe Char) -> [Char] -> [Maybe Char]
forall a b. (a -> b) -> [a] -> [b]
map Char -> Maybe Char
forall a. a -> Maybe a
Just ".,;:!?"
                              then Bool -> [Inline] -> [Inline]
quoted Bool
isOuter [Inline]
inls [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++
                                   Style -> [Inline] -> [Inline]
clean' Style
sty ([Inline] -> [Inline]
tailInline [Inline]
is)
                              else Bool -> [Inline] -> [Inline]
quoted Bool
isOuter ([Inline]
inls [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Text -> Inline
Str (Char -> Text
T.singleton Char
x)]) [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++
                                     Style -> [Inline] -> [Inline]
clean' Style
sty ([Inline] -> [Inline]
tailInline [Inline]
is)
                         else Bool -> [Inline] -> [Inline]
quoted Bool
isOuter [Inline]
inls [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
is
               _      ->      Bool -> [Inline] -> [Inline]
quoted Bool
isOuter [Inline]
inls [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
is
      (Quoted t :: QuoteType
t inls :: [Inline]
inls : _) -> Bool -> [Inline] -> [Inline]
quoted (QuoteType
t QuoteType -> QuoteType -> Bool
forall a. Eq a => a -> a -> Bool
== QuoteType
DoubleQuote) [Inline]
inls [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
is
      _      -> if [Inline] -> Maybe Char
lastInline [Inline
i] Maybe Char -> Maybe Char -> Bool
forall a. Eq a => a -> a -> Bool
== [Inline] -> Maybe Char
headInline [Inline]
is Bool -> Bool -> Bool
&& Bool
isPunct
                   then Inline
i Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Style -> [Inline] -> [Inline]
clean' Style
sty ([Inline] -> [Inline]
tailInline [Inline]
is)
                   else Inline
i Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Style -> [Inline] -> [Inline]
clean' Style
sty [Inline]
is
    where
      isPunct :: Bool
isPunct = (Char -> Bool) -> Maybe Char -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (".,;:!? " :: String)) (Maybe Char -> Bool) -> Maybe Char -> Bool
forall a b. (a -> b) -> a -> b
$ [Inline] -> Maybe Char
headInline [Inline]
is
      locale :: Locale
locale  = case Style -> [Locale]
styleLocale Style
sty of
                     (x :: Locale
x:_) -> Locale
x
                     []    -> Text -> Text -> [Target] -> [CslTerm] -> [Element] -> Locale
Locale "" "" [] [] [] -- should not happen
      getQuote :: Text -> Text -> Inline
getQuote s :: Text
s d :: Text
d     = case [CslTerm
term | CslTerm
term <- Locale -> [CslTerm]
localeTerms Locale
locale, CslTerm -> Text
cslTerm CslTerm
term Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
s] of
                               (x :: CslTerm
x:_) -> Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ CslTerm -> Text
termSingular CslTerm
x
                               _     -> Text -> Inline
Str Text
d
      openQuoteOuter :: Inline
openQuoteOuter   = Text -> Text -> Inline
getQuote "open-quote" "“"
      openQuoteInner :: Inline
openQuoteInner   = Text -> Text -> Inline
getQuote "open-inner-quote" "‘"
      closeQuoteOuter :: Inline
closeQuoteOuter  = Text -> Text -> Inline
getQuote "close-quote" "”"
      closeQuoteInner :: Inline
closeQuoteInner  = Text -> Text -> Inline
getQuote "close-inner-quote" "’"
      quoted :: Bool -> [Inline] -> [Inline]
quoted True ils :: [Inline]
ils  = Inline
openQuoteOuter Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
ils [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline
closeQuoteOuter]
      quoted False ils :: [Inline]
ils = Inline
openQuoteInner Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
ils [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline
closeQuoteInner]

convertQuoted :: Style -> [Inline] -> [Inline]
convertQuoted :: Style -> [Inline] -> [Inline]
convertQuoted s :: Style
s = [Inline] -> [Inline]
convertQuoted'
    where
      locale :: Locale
locale = let l :: [Locale]
l = Style -> [Locale]
styleLocale Style
s in case [Locale]
l of [x :: Locale
x] -> Locale
x; _   -> Text -> Text -> [Target] -> [CslTerm] -> [Element] -> Locale
Locale "" "" [] [] []
      getQuote :: Text -> Text -> Text
getQuote  x :: Text
x y :: Text
y = Text -> Text
fromEntities (Text -> Text) -> (Locale -> Text) -> Locale -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CslTerm -> Text
termSingular (CslTerm -> Text) -> (Locale -> CslTerm) -> Locale -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CslTerm -> Maybe CslTerm -> CslTerm
forall a. a -> Maybe a -> a
fromMaybe CslTerm
newTerm {termSingular :: Text
termSingular = Text
x} (Maybe CslTerm -> CslTerm)
-> (Locale -> Maybe CslTerm) -> Locale -> CslTerm
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                      Text -> Form -> [CslTerm] -> Maybe CslTerm
findTerm Text
y Form
Long ([CslTerm] -> Maybe CslTerm)
-> (Locale -> [CslTerm]) -> Locale -> Maybe CslTerm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Locale -> [CslTerm]
localeTerms (Locale -> Text) -> Locale -> Text
forall a b. (a -> b) -> a -> b
$ Locale
locale
      doubleQuotesO :: Text
doubleQuotesO = Text -> Text -> Text
getQuote "\"" "open-quote"
      doubleQuotesC :: Text
doubleQuotesC = Text -> Text -> Text
getQuote "\"" "close-quote"
      singleQuotesO :: Text
singleQuotesO = Text -> Text -> Text
getQuote "'"  "open-inner-quote"
      singleQuotesC :: Text
singleQuotesC = Text -> Text -> Text
getQuote "'"  "close-inner-quote"
      convertQuoted' :: [Inline] -> [Inline]
convertQuoted' o :: [Inline]
o
          | (Quoted DoubleQuote t :: [Inline]
t:xs :: [Inline]
xs) <- [Inline]
o = Text -> Inline
Str Text
doubleQuotesO Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
t [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Text -> Inline
Str Text
doubleQuotesC Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline] -> [Inline]
convertQuoted' [Inline]
xs
          | (Quoted SingleQuote t :: [Inline]
t:xs :: [Inline]
xs) <- [Inline]
o = Text -> Inline
Str Text
singleQuotesO Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
t [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Text -> Inline
Str Text
singleQuotesC Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline] -> [Inline]
convertQuoted' [Inline]
xs
          | (x :: Inline
x                   :xs :: [Inline]
xs) <- [Inline]
o = Inline
x Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline] -> [Inline]
convertQuoted' [Inline]
xs
          | Bool
otherwise                      = []

-- flip-flop

data FlipFlopState = FlipFlopState
     { FlipFlopState -> Bool
inEmph        :: Bool
     , FlipFlopState -> Bool
inStrong      :: Bool
     , FlipFlopState -> Bool
inSmallCaps   :: Bool
     , FlipFlopState -> Bool
inOuterQuotes :: Bool
     }

flipFlop :: [Inline] -> [Inline]
flipFlop :: [Inline] -> [Inline]
flipFlop = (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' (FlipFlopState -> Inline -> Inline)
-> FlipFlopState -> Inline -> Inline
forall a b. (a -> b) -> a -> b
$ Bool -> Bool -> Bool -> Bool -> FlipFlopState
FlipFlopState Bool
False Bool
False Bool
False Bool
False)

flipFlop' :: FlipFlopState -> Inline -> Inline
flipFlop' :: FlipFlopState -> Inline -> Inline
flipFlop' st :: FlipFlopState
st (Emph ils :: [Inline]
ils) =
  (if FlipFlopState -> Bool
inEmph FlipFlopState
st then Attr -> [Inline] -> Inline
Span ("",["csl-no-emph"],[]) else [Inline] -> Inline
Emph)
  ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st{ inEmph :: Bool
inEmph = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FlipFlopState -> Bool
inEmph FlipFlopState
st }) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Strong ils :: [Inline]
ils) =
  (if FlipFlopState -> Bool
inStrong FlipFlopState
st then Attr -> [Inline] -> Inline
Span ("",["csl-no-strong"],[]) else [Inline] -> Inline
Strong)
  ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st{ inStrong :: Bool
inStrong = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FlipFlopState -> Bool
inStrong FlipFlopState
st }) [Inline]
ils
flipFlop' st :: FlipFlopState
st (SmallCaps ils :: [Inline]
ils) =
  (if FlipFlopState -> Bool
inSmallCaps FlipFlopState
st then Attr -> [Inline] -> Inline
Span ("",["csl-no-smallcaps"],[]) else [Inline] -> Inline
SmallCaps)
  ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st{ inSmallCaps :: Bool
inSmallCaps = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FlipFlopState -> Bool
inSmallCaps FlipFlopState
st }) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Strikeout ils :: [Inline]
ils) =
  [Inline] -> Inline
Strikeout ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Superscript ils :: [Inline]
ils) =
  [Inline] -> Inline
Superscript ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Subscript ils :: [Inline]
ils) =
  [Inline] -> Inline
Subscript ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Quoted _ ils :: [Inline]
ils) =
  QuoteType -> [Inline] -> Inline
Quoted (if FlipFlopState -> Bool
inOuterQuotes FlipFlopState
st then QuoteType
SingleQuote else QuoteType
DoubleQuote)
  ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st{ inOuterQuotes :: Bool
inOuterQuotes = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FlipFlopState -> Bool
inOuterQuotes FlipFlopState
st }) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Span (_, ["csl-inquote"], _) ils :: [Inline]
ils) =
  Attr -> [Inline] -> Inline
Span ("", ["csl-inquote"], [("position", if FlipFlopState -> Bool
inOuterQuotes FlipFlopState
st then "inner" else "outer")])
  ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st{ inOuterQuotes :: Bool
inOuterQuotes = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ FlipFlopState -> Bool
inOuterQuotes FlipFlopState
st }) [Inline]
ils
flipFlop' st :: FlipFlopState
st (Span (id' :: Text
id',classes :: [Text]
classes,kvs :: [Target]
kvs) ils :: [Inline]
ils)
  | "nodecor" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
classes = Attr -> [Inline] -> Inline
Span (Text
id',[Text]
classes',[Target]
kvs) ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils
  | Bool
otherwise = Attr -> [Inline] -> Inline
Span (Text
id',[Text]
classes,[Target]
kvs) ([Inline] -> Inline) -> [Inline] -> Inline
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils
     where classes' :: [Text]
classes' = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "nodecor") [Text]
classes [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
                       ["csl-no-emph"      | FlipFlopState -> Bool
inEmph FlipFlopState
st] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
                       ["csl-no-strong"    | FlipFlopState -> Bool
inStrong FlipFlopState
st] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
                       ["csl-no-smallcaps" | FlipFlopState -> Bool
inSmallCaps FlipFlopState
st]
flipFlop' st :: FlipFlopState
st (Link attr :: Attr
attr ils :: [Inline]
ils t :: Target
t) =
  Attr -> [Inline] -> Target -> Inline
Link Attr
attr ((Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils) Target
t
flipFlop' st :: FlipFlopState
st (Note [Para ils :: [Inline]
ils]) =
  [Block] -> Inline
Note [[Inline] -> Block
Para ([Inline] -> Block) -> [Inline] -> Block
forall a b. (a -> b) -> a -> b
$ (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. (a -> b) -> [a] -> [b]
map (FlipFlopState -> Inline -> Inline
flipFlop' FlipFlopState
st) [Inline]
ils]
flipFlop' _ il :: Inline
il = Inline
il