{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.Docx.Parse.Styles (
CharStyleId(..)
, CharStyle
, ParaStyleId(..)
, ParStyle(..)
, ParIndentation(..)
, RunStyle(..)
, HasStyleName
, StyleName
, ParaStyleName
, CharStyleName
, FromStyleName
, VertAlign(..)
, StyleId
, HasStyleId
, archiveToStyles'
, getStyleId
, getStyleName
, cStyleData
, fromStyleName
, fromStyleId
, stringToInteger
, getIndentation
, getNumInfo
, elemToRunStyle
, defaultRunStyle
, checkOnOff
) where
import Codec.Archive.Zip
import Control.Applicative ((<|>))
import Data.Function (on)
import Data.String (IsString(..))
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Text.Read
import Data.Text (Text)
import Data.Maybe
import Data.Coerce
import Text.Pandoc.Readers.Docx.Util
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.XML.Light
newtype CharStyleId = CharStyleId T.Text
deriving (Int -> CharStyleId -> ShowS
[CharStyleId] -> ShowS
CharStyleId -> String
(Int -> CharStyleId -> ShowS)
-> (CharStyleId -> String)
-> ([CharStyleId] -> ShowS)
-> Show CharStyleId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CharStyleId -> ShowS
showsPrec :: Int -> CharStyleId -> ShowS
$cshow :: CharStyleId -> String
show :: CharStyleId -> String
$cshowList :: [CharStyleId] -> ShowS
showList :: [CharStyleId] -> ShowS
Show, CharStyleId -> CharStyleId -> Bool
(CharStyleId -> CharStyleId -> Bool)
-> (CharStyleId -> CharStyleId -> Bool) -> Eq CharStyleId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CharStyleId -> CharStyleId -> Bool
== :: CharStyleId -> CharStyleId -> Bool
$c/= :: CharStyleId -> CharStyleId -> Bool
/= :: CharStyleId -> CharStyleId -> Bool
Eq, Eq CharStyleId
Eq CharStyleId =>
(CharStyleId -> CharStyleId -> Ordering)
-> (CharStyleId -> CharStyleId -> Bool)
-> (CharStyleId -> CharStyleId -> Bool)
-> (CharStyleId -> CharStyleId -> Bool)
-> (CharStyleId -> CharStyleId -> Bool)
-> (CharStyleId -> CharStyleId -> CharStyleId)
-> (CharStyleId -> CharStyleId -> CharStyleId)
-> Ord CharStyleId
CharStyleId -> CharStyleId -> Bool
CharStyleId -> CharStyleId -> Ordering
CharStyleId -> CharStyleId -> CharStyleId
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
$ccompare :: CharStyleId -> CharStyleId -> Ordering
compare :: CharStyleId -> CharStyleId -> Ordering
$c< :: CharStyleId -> CharStyleId -> Bool
< :: CharStyleId -> CharStyleId -> Bool
$c<= :: CharStyleId -> CharStyleId -> Bool
<= :: CharStyleId -> CharStyleId -> Bool
$c> :: CharStyleId -> CharStyleId -> Bool
> :: CharStyleId -> CharStyleId -> Bool
$c>= :: CharStyleId -> CharStyleId -> Bool
>= :: CharStyleId -> CharStyleId -> Bool
$cmax :: CharStyleId -> CharStyleId -> CharStyleId
max :: CharStyleId -> CharStyleId -> CharStyleId
$cmin :: CharStyleId -> CharStyleId -> CharStyleId
min :: CharStyleId -> CharStyleId -> CharStyleId
Ord, String -> CharStyleId
(String -> CharStyleId) -> IsString CharStyleId
forall a. (String -> a) -> IsString a
$cfromString :: String -> CharStyleId
fromString :: String -> CharStyleId
IsString, CharStyleId -> Text
(CharStyleId -> Text) -> FromStyleId CharStyleId
forall a. (a -> Text) -> FromStyleId a
$cfromStyleId :: CharStyleId -> Text
fromStyleId :: CharStyleId -> Text
FromStyleId)
newtype ParaStyleId = ParaStyleId T.Text
deriving (Int -> ParaStyleId -> ShowS
[ParaStyleId] -> ShowS
ParaStyleId -> String
(Int -> ParaStyleId -> ShowS)
-> (ParaStyleId -> String)
-> ([ParaStyleId] -> ShowS)
-> Show ParaStyleId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParaStyleId -> ShowS
showsPrec :: Int -> ParaStyleId -> ShowS
$cshow :: ParaStyleId -> String
show :: ParaStyleId -> String
$cshowList :: [ParaStyleId] -> ShowS
showList :: [ParaStyleId] -> ShowS
Show, ParaStyleId -> ParaStyleId -> Bool
(ParaStyleId -> ParaStyleId -> Bool)
-> (ParaStyleId -> ParaStyleId -> Bool) -> Eq ParaStyleId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ParaStyleId -> ParaStyleId -> Bool
== :: ParaStyleId -> ParaStyleId -> Bool
$c/= :: ParaStyleId -> ParaStyleId -> Bool
/= :: ParaStyleId -> ParaStyleId -> Bool
Eq, Eq ParaStyleId
Eq ParaStyleId =>
(ParaStyleId -> ParaStyleId -> Ordering)
-> (ParaStyleId -> ParaStyleId -> Bool)
-> (ParaStyleId -> ParaStyleId -> Bool)
-> (ParaStyleId -> ParaStyleId -> Bool)
-> (ParaStyleId -> ParaStyleId -> Bool)
-> (ParaStyleId -> ParaStyleId -> ParaStyleId)
-> (ParaStyleId -> ParaStyleId -> ParaStyleId)
-> Ord ParaStyleId
ParaStyleId -> ParaStyleId -> Bool
ParaStyleId -> ParaStyleId -> Ordering
ParaStyleId -> ParaStyleId -> ParaStyleId
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
$ccompare :: ParaStyleId -> ParaStyleId -> Ordering
compare :: ParaStyleId -> ParaStyleId -> Ordering
$c< :: ParaStyleId -> ParaStyleId -> Bool
< :: ParaStyleId -> ParaStyleId -> Bool
$c<= :: ParaStyleId -> ParaStyleId -> Bool
<= :: ParaStyleId -> ParaStyleId -> Bool
$c> :: ParaStyleId -> ParaStyleId -> Bool
> :: ParaStyleId -> ParaStyleId -> Bool
$c>= :: ParaStyleId -> ParaStyleId -> Bool
>= :: ParaStyleId -> ParaStyleId -> Bool
$cmax :: ParaStyleId -> ParaStyleId -> ParaStyleId
max :: ParaStyleId -> ParaStyleId -> ParaStyleId
$cmin :: ParaStyleId -> ParaStyleId -> ParaStyleId
min :: ParaStyleId -> ParaStyleId -> ParaStyleId
Ord, String -> ParaStyleId
(String -> ParaStyleId) -> IsString ParaStyleId
forall a. (String -> a) -> IsString a
$cfromString :: String -> ParaStyleId
fromString :: String -> ParaStyleId
IsString, ParaStyleId -> Text
(ParaStyleId -> Text) -> FromStyleId ParaStyleId
forall a. (a -> Text) -> FromStyleId a
$cfromStyleId :: ParaStyleId -> Text
fromStyleId :: ParaStyleId -> Text
FromStyleId)
newtype CharStyleName = CharStyleName CIString
deriving (Int -> CharStyleName -> ShowS
[CharStyleName] -> ShowS
CharStyleName -> String
(Int -> CharStyleName -> ShowS)
-> (CharStyleName -> String)
-> ([CharStyleName] -> ShowS)
-> Show CharStyleName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CharStyleName -> ShowS
showsPrec :: Int -> CharStyleName -> ShowS
$cshow :: CharStyleName -> String
show :: CharStyleName -> String
$cshowList :: [CharStyleName] -> ShowS
showList :: [CharStyleName] -> ShowS
Show, CharStyleName -> CharStyleName -> Bool
(CharStyleName -> CharStyleName -> Bool)
-> (CharStyleName -> CharStyleName -> Bool) -> Eq CharStyleName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CharStyleName -> CharStyleName -> Bool
== :: CharStyleName -> CharStyleName -> Bool
$c/= :: CharStyleName -> CharStyleName -> Bool
/= :: CharStyleName -> CharStyleName -> Bool
Eq, Eq CharStyleName
Eq CharStyleName =>
(CharStyleName -> CharStyleName -> Ordering)
-> (CharStyleName -> CharStyleName -> Bool)
-> (CharStyleName -> CharStyleName -> Bool)
-> (CharStyleName -> CharStyleName -> Bool)
-> (CharStyleName -> CharStyleName -> Bool)
-> (CharStyleName -> CharStyleName -> CharStyleName)
-> (CharStyleName -> CharStyleName -> CharStyleName)
-> Ord CharStyleName
CharStyleName -> CharStyleName -> Bool
CharStyleName -> CharStyleName -> Ordering
CharStyleName -> CharStyleName -> CharStyleName
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
$ccompare :: CharStyleName -> CharStyleName -> Ordering
compare :: CharStyleName -> CharStyleName -> Ordering
$c< :: CharStyleName -> CharStyleName -> Bool
< :: CharStyleName -> CharStyleName -> Bool
$c<= :: CharStyleName -> CharStyleName -> Bool
<= :: CharStyleName -> CharStyleName -> Bool
$c> :: CharStyleName -> CharStyleName -> Bool
> :: CharStyleName -> CharStyleName -> Bool
$c>= :: CharStyleName -> CharStyleName -> Bool
>= :: CharStyleName -> CharStyleName -> Bool
$cmax :: CharStyleName -> CharStyleName -> CharStyleName
max :: CharStyleName -> CharStyleName -> CharStyleName
$cmin :: CharStyleName -> CharStyleName -> CharStyleName
min :: CharStyleName -> CharStyleName -> CharStyleName
Ord, String -> CharStyleName
(String -> CharStyleName) -> IsString CharStyleName
forall a. (String -> a) -> IsString a
$cfromString :: String -> CharStyleName
fromString :: String -> CharStyleName
IsString, CharStyleName -> Text
(CharStyleName -> Text) -> FromStyleName CharStyleName
forall a. (a -> Text) -> FromStyleName a
$cfromStyleName :: CharStyleName -> Text
fromStyleName :: CharStyleName -> Text
FromStyleName)
newtype ParaStyleName = ParaStyleName CIString
deriving (Int -> ParaStyleName -> ShowS
[ParaStyleName] -> ShowS
ParaStyleName -> String
(Int -> ParaStyleName -> ShowS)
-> (ParaStyleName -> String)
-> ([ParaStyleName] -> ShowS)
-> Show ParaStyleName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParaStyleName -> ShowS
showsPrec :: Int -> ParaStyleName -> ShowS
$cshow :: ParaStyleName -> String
show :: ParaStyleName -> String
$cshowList :: [ParaStyleName] -> ShowS
showList :: [ParaStyleName] -> ShowS
Show, ParaStyleName -> ParaStyleName -> Bool
(ParaStyleName -> ParaStyleName -> Bool)
-> (ParaStyleName -> ParaStyleName -> Bool) -> Eq ParaStyleName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ParaStyleName -> ParaStyleName -> Bool
== :: ParaStyleName -> ParaStyleName -> Bool
$c/= :: ParaStyleName -> ParaStyleName -> Bool
/= :: ParaStyleName -> ParaStyleName -> Bool
Eq, Eq ParaStyleName
Eq ParaStyleName =>
(ParaStyleName -> ParaStyleName -> Ordering)
-> (ParaStyleName -> ParaStyleName -> Bool)
-> (ParaStyleName -> ParaStyleName -> Bool)
-> (ParaStyleName -> ParaStyleName -> Bool)
-> (ParaStyleName -> ParaStyleName -> Bool)
-> (ParaStyleName -> ParaStyleName -> ParaStyleName)
-> (ParaStyleName -> ParaStyleName -> ParaStyleName)
-> Ord ParaStyleName
ParaStyleName -> ParaStyleName -> Bool
ParaStyleName -> ParaStyleName -> Ordering
ParaStyleName -> ParaStyleName -> ParaStyleName
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
$ccompare :: ParaStyleName -> ParaStyleName -> Ordering
compare :: ParaStyleName -> ParaStyleName -> Ordering
$c< :: ParaStyleName -> ParaStyleName -> Bool
< :: ParaStyleName -> ParaStyleName -> Bool
$c<= :: ParaStyleName -> ParaStyleName -> Bool
<= :: ParaStyleName -> ParaStyleName -> Bool
$c> :: ParaStyleName -> ParaStyleName -> Bool
> :: ParaStyleName -> ParaStyleName -> Bool
$c>= :: ParaStyleName -> ParaStyleName -> Bool
>= :: ParaStyleName -> ParaStyleName -> Bool
$cmax :: ParaStyleName -> ParaStyleName -> ParaStyleName
max :: ParaStyleName -> ParaStyleName -> ParaStyleName
$cmin :: ParaStyleName -> ParaStyleName -> ParaStyleName
min :: ParaStyleName -> ParaStyleName -> ParaStyleName
Ord, String -> ParaStyleName
(String -> ParaStyleName) -> IsString ParaStyleName
forall a. (String -> a) -> IsString a
$cfromString :: String -> ParaStyleName
fromString :: String -> ParaStyleName
IsString, ParaStyleName -> Text
(ParaStyleName -> Text) -> FromStyleName ParaStyleName
forall a. (a -> Text) -> FromStyleName a
$cfromStyleName :: ParaStyleName -> Text
fromStyleName :: ParaStyleName -> Text
FromStyleName)
newtype CIString = CIString T.Text deriving (Int -> CIString -> ShowS
[CIString] -> ShowS
CIString -> String
(Int -> CIString -> ShowS)
-> (CIString -> String) -> ([CIString] -> ShowS) -> Show CIString
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CIString -> ShowS
showsPrec :: Int -> CIString -> ShowS
$cshow :: CIString -> String
show :: CIString -> String
$cshowList :: [CIString] -> ShowS
showList :: [CIString] -> ShowS
Show, String -> CIString
(String -> CIString) -> IsString CIString
forall a. (String -> a) -> IsString a
$cfromString :: String -> CIString
fromString :: String -> CIString
IsString, CIString -> Text
(CIString -> Text) -> FromStyleName CIString
forall a. (a -> Text) -> FromStyleName a
$cfromStyleName :: CIString -> Text
fromStyleName :: CIString -> Text
FromStyleName)
class FromStyleName a where
fromStyleName :: a -> T.Text
instance FromStyleName String where
fromStyleName :: String -> Text
fromStyleName = String -> Text
T.pack
instance FromStyleName T.Text where
fromStyleName :: Text -> Text
fromStyleName = Text -> Text
forall a. a -> a
id
class FromStyleId a where
fromStyleId :: a -> T.Text
instance FromStyleId String where
fromStyleId :: String -> Text
fromStyleId = String -> Text
T.pack
instance FromStyleId T.Text where
fromStyleId :: Text -> Text
fromStyleId = Text -> Text
forall a. a -> a
id
instance Eq CIString where
== :: CIString -> CIString -> Bool
(==) = Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Text -> Text -> Bool)
-> (CIString -> Text) -> CIString -> CIString -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Text -> Text
T.toCaseFold (Text -> Text) -> (CIString -> Text) -> CIString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CIString -> Text
forall a b. Coercible a b => a -> b
coerce
instance Ord CIString where
compare :: CIString -> CIString -> Ordering
compare = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Text -> Text -> Ordering)
-> (CIString -> Text) -> CIString -> CIString -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Text -> Text
T.toCaseFold (Text -> Text) -> (CIString -> Text) -> CIString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CIString -> Text
forall a b. Coercible a b => a -> b
coerce
data VertAlign = BaseLn | SupScrpt | SubScrpt
deriving Int -> VertAlign -> ShowS
[VertAlign] -> ShowS
VertAlign -> String
(Int -> VertAlign -> ShowS)
-> (VertAlign -> String)
-> ([VertAlign] -> ShowS)
-> Show VertAlign
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VertAlign -> ShowS
showsPrec :: Int -> VertAlign -> ShowS
$cshow :: VertAlign -> String
show :: VertAlign -> String
$cshowList :: [VertAlign] -> ShowS
showList :: [VertAlign] -> ShowS
Show
data CharStyle = CharStyle { CharStyle -> CharStyleId
cStyleId :: CharStyleId
, CharStyle -> CharStyleName
cStyleName :: CharStyleName
, CharStyle -> RunStyle
cStyleData :: RunStyle
} deriving (Int -> CharStyle -> ShowS
[CharStyle] -> ShowS
CharStyle -> String
(Int -> CharStyle -> ShowS)
-> (CharStyle -> String)
-> ([CharStyle] -> ShowS)
-> Show CharStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CharStyle -> ShowS
showsPrec :: Int -> CharStyle -> ShowS
$cshow :: CharStyle -> String
show :: CharStyle -> String
$cshowList :: [CharStyle] -> ShowS
showList :: [CharStyle] -> ShowS
Show)
data RunStyle = RunStyle { RunStyle -> Maybe Bool
isBold :: Maybe Bool
, RunStyle -> Maybe Bool
isBoldCTL :: Maybe Bool
, RunStyle -> Maybe Bool
isItalic :: Maybe Bool
, RunStyle -> Maybe Bool
isItalicCTL :: Maybe Bool
, RunStyle -> Maybe Bool
isSmallCaps :: Maybe Bool
, RunStyle -> Maybe Bool
isStrike :: Maybe Bool
, RunStyle -> Maybe Bool
isRTL :: Maybe Bool
, RunStyle -> Maybe Bool
isForceCTL :: Maybe Bool
, RunStyle -> Maybe Text
rHighlight :: Maybe Text
, RunStyle -> Maybe VertAlign
rVertAlign :: Maybe VertAlign
, RunStyle -> Maybe Text
rUnderline :: Maybe Text
, RunStyle -> Maybe CharStyle
rParentStyle :: Maybe CharStyle
}
deriving Int -> RunStyle -> ShowS
[RunStyle] -> ShowS
RunStyle -> String
(Int -> RunStyle -> ShowS)
-> (RunStyle -> String) -> ([RunStyle] -> ShowS) -> Show RunStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RunStyle -> ShowS
showsPrec :: Int -> RunStyle -> ShowS
$cshow :: RunStyle -> String
show :: RunStyle -> String
$cshowList :: [RunStyle] -> ShowS
showList :: [RunStyle] -> ShowS
Show
data ParIndentation = ParIndentation { ParIndentation -> Maybe Integer
leftParIndent :: Maybe Integer
, ParIndentation -> Maybe Integer
rightParIndent :: Maybe Integer
, ParIndentation -> Maybe Integer
hangingParIndent :: Maybe Integer}
deriving Int -> ParIndentation -> ShowS
[ParIndentation] -> ShowS
ParIndentation -> String
(Int -> ParIndentation -> ShowS)
-> (ParIndentation -> String)
-> ([ParIndentation] -> ShowS)
-> Show ParIndentation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParIndentation -> ShowS
showsPrec :: Int -> ParIndentation -> ShowS
$cshow :: ParIndentation -> String
show :: ParIndentation -> String
$cshowList :: [ParIndentation] -> ShowS
showList :: [ParIndentation] -> ShowS
Show
data ParStyle = ParStyle { ParStyle -> Maybe (ParaStyleName, Int)
headingLev :: Maybe (ParaStyleName, Int)
, ParStyle -> Maybe ParIndentation
indent :: Maybe ParIndentation
, ParStyle -> Maybe (Text, Text)
numInfo :: Maybe (T.Text, T.Text)
, ParStyle -> Maybe ParStyle
psParentStyle :: Maybe ParStyle
, ParStyle -> ParaStyleName
pStyleName :: ParaStyleName
, ParStyle -> ParaStyleId
pStyleId :: ParaStyleId
}
deriving Int -> ParStyle -> ShowS
[ParStyle] -> ShowS
ParStyle -> String
(Int -> ParStyle -> ShowS)
-> (ParStyle -> String) -> ([ParStyle] -> ShowS) -> Show ParStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParStyle -> ShowS
showsPrec :: Int -> ParStyle -> ShowS
$cshow :: ParStyle -> String
show :: ParStyle -> String
$cshowList :: [ParStyle] -> ShowS
showList :: [ParStyle] -> ShowS
Show
defaultRunStyle :: RunStyle
defaultRunStyle :: RunStyle
defaultRunStyle = RunStyle { isBold :: Maybe Bool
isBold = Maybe Bool
forall a. Maybe a
Nothing
, isBoldCTL :: Maybe Bool
isBoldCTL = Maybe Bool
forall a. Maybe a
Nothing
, isItalic :: Maybe Bool
isItalic = Maybe Bool
forall a. Maybe a
Nothing
, isItalicCTL :: Maybe Bool
isItalicCTL = Maybe Bool
forall a. Maybe a
Nothing
, isSmallCaps :: Maybe Bool
isSmallCaps = Maybe Bool
forall a. Maybe a
Nothing
, isStrike :: Maybe Bool
isStrike = Maybe Bool
forall a. Maybe a
Nothing
, isRTL :: Maybe Bool
isRTL = Maybe Bool
forall a. Maybe a
Nothing
, isForceCTL :: Maybe Bool
isForceCTL = Maybe Bool
forall a. Maybe a
Nothing
, rHighlight :: Maybe Text
rHighlight = Maybe Text
forall a. Maybe a
Nothing
, rVertAlign :: Maybe VertAlign
rVertAlign = Maybe VertAlign
forall a. Maybe a
Nothing
, rUnderline :: Maybe Text
rUnderline = Maybe Text
forall a. Maybe a
Nothing
, rParentStyle :: Maybe CharStyle
rParentStyle = Maybe CharStyle
forall a. Maybe a
Nothing
}
archiveToStyles'
:: (Ord k1, Ord k2, ElemToStyle a1, ElemToStyle a2)
=> (a1 -> k1) -> (a2 -> k2) -> Archive -> (M.Map k1 a1, M.Map k2 a2)
archiveToStyles' :: forall k1 k2 a1 a2.
(Ord k1, Ord k2, ElemToStyle a1, ElemToStyle a2) =>
(a1 -> k1) -> (a2 -> k2) -> Archive -> (Map k1 a1, Map k2 a2)
archiveToStyles' a1 -> k1
conv1 a2 -> k2
conv2 Archive
zf =
case String -> Archive -> Maybe Entry
findEntryByPath String
"word/styles.xml" Archive
zf of
Maybe Entry
Nothing -> (Map k1 a1
forall k a. Map k a
M.empty, Map k2 a2
forall k a. Map k a
M.empty)
Just Entry
entry ->
case Text -> Either Text Element
parseXMLElement (Text -> Either Text Element)
-> (Entry -> Text) -> Entry -> Either Text Element
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
UTF8.toTextLazy (ByteString -> Text) -> (Entry -> ByteString) -> Entry -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Entry -> ByteString
fromEntry (Entry -> Either Text Element) -> Entry -> Either Text Element
forall a b. (a -> b) -> a -> b
$ Entry
entry of
Left Text
_ -> (Map k1 a1
forall k a. Map k a
M.empty, Map k2 a2
forall k a. Map k a
M.empty)
Right Element
styElem ->
let namespaces :: NameSpaces
namespaces = Element -> NameSpaces
elemToNameSpaces Element
styElem
in
( [(k1, a1)] -> Map k1 a1
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(k1, a1)] -> Map k1 a1) -> [(k1, a1)] -> Map k1 a1
forall a b. (a -> b) -> a -> b
$ (a1 -> (k1, a1)) -> [a1] -> [(k1, a1)]
forall a b. (a -> b) -> [a] -> [b]
map (\a1
r -> (a1 -> k1
conv1 a1
r, a1
r)) ([a1] -> [(k1, a1)]) -> [a1] -> [(k1, a1)]
forall a b. (a -> b) -> a -> b
$
NameSpaces -> Element -> Maybe a1 -> [a1]
forall a. ElemToStyle a => NameSpaces -> Element -> Maybe a -> [a]
buildBasedOnList NameSpaces
namespaces Element
styElem Maybe a1
forall a. Maybe a
Nothing,
[(k2, a2)] -> Map k2 a2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(k2, a2)] -> Map k2 a2) -> [(k2, a2)] -> Map k2 a2
forall a b. (a -> b) -> a -> b
$ (a2 -> (k2, a2)) -> [a2] -> [(k2, a2)]
forall a b. (a -> b) -> [a] -> [b]
map (\a2
p -> (a2 -> k2
conv2 a2
p, a2
p)) ([a2] -> [(k2, a2)]) -> [a2] -> [(k2, a2)]
forall a b. (a -> b) -> a -> b
$
NameSpaces -> Element -> Maybe a2 -> [a2]
forall a. ElemToStyle a => NameSpaces -> Element -> Maybe a -> [a]
buildBasedOnList NameSpaces
namespaces Element
styElem Maybe a2
forall a. Maybe a
Nothing)
isBasedOnStyle :: (ElemToStyle a, FromStyleId (StyleId a)) => NameSpaces -> Element -> Maybe a -> Bool
isBasedOnStyle :: forall a.
(ElemToStyle a, FromStyleId (StyleId a)) =>
NameSpaces -> Element -> Maybe a -> Bool
isBasedOnStyle NameSpaces
ns Element
element Maybe a
parentStyle
| NameSpaces -> Text -> Text -> Element -> Bool
isElem NameSpaces
ns Text
"w" Text
"style" Element
element
, Just Text
styleType <- NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"type" Element
element
, Text
styleType Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe a -> Text
forall a. ElemToStyle a => Maybe a -> Text
cStyleType Maybe a
parentStyle
, Just Text
basedOnVal <- NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"basedOn" Element
element Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val"
, Just a
ps <- Maybe a
parentStyle = Text
basedOnVal Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== StyleId a -> Text
forall a. FromStyleId a => a -> Text
fromStyleId (a -> StyleId a
forall a. HasStyleId a => a -> StyleId a
getStyleId a
ps)
| NameSpaces -> Text -> Text -> Element -> Bool
isElem NameSpaces
ns Text
"w" Text
"style" Element
element
, Just Text
styleType <- NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"type" Element
element
, Text
styleType Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe a -> Text
forall a. ElemToStyle a => Maybe a -> Text
cStyleType Maybe a
parentStyle
, Maybe Element
Nothing <- NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"basedOn" Element
element
, Maybe a
Nothing <- Maybe a
parentStyle = Bool
True
| Bool
otherwise = Bool
False
class HasStyleId a => ElemToStyle a where
cStyleType :: Maybe a -> Text
elemToStyle :: NameSpaces -> Element -> Maybe a -> Maybe a
class FromStyleId (StyleId a) => HasStyleId a where
type StyleId a
getStyleId :: a -> StyleId a
class FromStyleName (StyleName a) => HasStyleName a where
type StyleName a
getStyleName :: a -> StyleName a
instance ElemToStyle CharStyle where
cStyleType :: Maybe CharStyle -> Text
cStyleType Maybe CharStyle
_ = Text
"character"
elemToStyle :: NameSpaces -> Element -> Maybe CharStyle -> Maybe CharStyle
elemToStyle NameSpaces
ns Element
element Maybe CharStyle
parentStyle
| NameSpaces -> Text -> Text -> Element -> Bool
isElem NameSpaces
ns Text
"w" Text
"style" Element
element
, Just Text
"character" <- NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"type" Element
element =
NameSpaces -> Element -> Maybe CharStyle -> Maybe CharStyle
elemToCharStyle NameSpaces
ns Element
element Maybe CharStyle
parentStyle
| Bool
otherwise = Maybe CharStyle
forall a. Maybe a
Nothing
instance HasStyleId CharStyle where
type StyleId CharStyle = CharStyleId
getStyleId :: CharStyle -> StyleId CharStyle
getStyleId = CharStyle -> StyleId CharStyle
CharStyle -> CharStyleId
cStyleId
instance HasStyleName CharStyle where
type StyleName CharStyle = CharStyleName
getStyleName :: CharStyle -> StyleName CharStyle
getStyleName = CharStyle -> StyleName CharStyle
CharStyle -> CharStyleName
cStyleName
instance ElemToStyle ParStyle where
cStyleType :: Maybe ParStyle -> Text
cStyleType Maybe ParStyle
_ = Text
"paragraph"
elemToStyle :: NameSpaces -> Element -> Maybe ParStyle -> Maybe ParStyle
elemToStyle NameSpaces
ns Element
element Maybe ParStyle
parentStyle
| NameSpaces -> Text -> Text -> Element -> Bool
isElem NameSpaces
ns Text
"w" Text
"style" Element
element
, Just Text
"paragraph" <- NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"type" Element
element
= NameSpaces -> Element -> Maybe ParStyle -> Maybe ParStyle
elemToParStyleData NameSpaces
ns Element
element Maybe ParStyle
parentStyle
| Bool
otherwise = Maybe ParStyle
forall a. Maybe a
Nothing
instance HasStyleId ParStyle where
type StyleId ParStyle = ParaStyleId
getStyleId :: ParStyle -> StyleId ParStyle
getStyleId = ParStyle -> StyleId ParStyle
ParStyle -> ParaStyleId
pStyleId
instance HasStyleName ParStyle where
type StyleName ParStyle = ParaStyleName
getStyleName :: ParStyle -> StyleName ParStyle
getStyleName = ParStyle -> StyleName ParStyle
ParStyle -> ParaStyleName
pStyleName
getStyleChildren :: (ElemToStyle a) => NameSpaces -> Element -> Maybe a -> [a]
getStyleChildren :: forall a. ElemToStyle a => NameSpaces -> Element -> Maybe a -> [a]
getStyleChildren NameSpaces
ns Element
element Maybe a
parentStyle
| NameSpaces -> Text -> Text -> Element -> Bool
isElem NameSpaces
ns Text
"w" Text
"styles" Element
element =
(Element -> Maybe a) -> [Element] -> [a]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\Element
e -> NameSpaces -> Element -> Maybe a -> Maybe a
forall a.
ElemToStyle a =>
NameSpaces -> Element -> Maybe a -> Maybe a
elemToStyle NameSpaces
ns Element
e Maybe a
parentStyle) ([Element] -> [a]) -> [Element] -> [a]
forall a b. (a -> b) -> a -> b
$
(Element -> Bool) -> Element -> [Element]
filterChildren (\Element
e' -> NameSpaces -> Element -> Maybe a -> Bool
forall a.
(ElemToStyle a, FromStyleId (StyleId a)) =>
NameSpaces -> Element -> Maybe a -> Bool
isBasedOnStyle NameSpaces
ns Element
e' Maybe a
parentStyle) Element
element
| Bool
otherwise = []
buildBasedOnList :: (ElemToStyle a) => NameSpaces -> Element -> Maybe a -> [a]
buildBasedOnList :: forall a. ElemToStyle a => NameSpaces -> Element -> Maybe a -> [a]
buildBasedOnList NameSpaces
ns Element
element Maybe a
rootStyle =
case NameSpaces -> Element -> Maybe a -> [a]
forall a. ElemToStyle a => NameSpaces -> Element -> Maybe a -> [a]
getStyleChildren NameSpaces
ns Element
element Maybe a
rootStyle of
[] -> []
[a]
stys -> [a]
stys [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++
(a -> [a]) -> [a] -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (NameSpaces -> Element -> Maybe a -> [a]
forall a. ElemToStyle a => NameSpaces -> Element -> Maybe a -> [a]
buildBasedOnList NameSpaces
ns Element
element (Maybe a -> [a]) -> (a -> Maybe a) -> a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just) [a]
stys
stringToInteger :: Text -> Maybe Integer
stringToInteger :: Text -> Maybe Integer
stringToInteger Text
s = case Reader Integer
forall a. Integral a => Reader a
Data.Text.Read.decimal Text
s of
Right (Integer
x,Text
_) -> Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
x
Left String
_ -> Maybe Integer
forall a. Maybe a
Nothing
checkOnOff :: NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff :: NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr QName
tag
| Just Element
t <- QName -> Element -> Maybe Element
findChild QName
tag Element
rPr
, Just Text
val <- NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val" Element
t =
Bool -> Maybe Bool
forall a. a -> Maybe a
Just (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ case Text
val of
Text
"true" -> Bool
True
Text
"false" -> Bool
False
Text
"on" -> Bool
True
Text
"off" -> Bool
False
Text
"1" -> Bool
True
Text
"0" -> Bool
False
Text
_ -> Bool
False
| Just Element
_ <- QName -> Element -> Maybe Element
findChild QName
tag Element
rPr = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
checkOnOff NameSpaces
_ Element
_ QName
_ = Maybe Bool
forall a. Maybe a
Nothing
elemToCharStyle :: NameSpaces
-> Element -> Maybe CharStyle -> Maybe CharStyle
elemToCharStyle :: NameSpaces -> Element -> Maybe CharStyle -> Maybe CharStyle
elemToCharStyle NameSpaces
ns Element
element Maybe CharStyle
parentStyle
= CharStyleId -> CharStyleName -> RunStyle -> CharStyle
CharStyle (CharStyleId -> CharStyleName -> RunStyle -> CharStyle)
-> Maybe CharStyleId
-> Maybe (CharStyleName -> RunStyle -> CharStyle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> CharStyleId
CharStyleId (Text -> CharStyleId) -> Maybe Text -> Maybe CharStyleId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"styleId" Element
element)
Maybe (CharStyleName -> RunStyle -> CharStyle)
-> Maybe CharStyleName -> Maybe (RunStyle -> CharStyle)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> NameSpaces -> Element -> Maybe CharStyleName
forall a. Coercible Text a => NameSpaces -> Element -> Maybe a
getElementStyleName NameSpaces
ns Element
element
Maybe (RunStyle -> CharStyle) -> Maybe RunStyle -> Maybe CharStyle
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RunStyle -> Maybe RunStyle
forall a. a -> Maybe a
Just (NameSpaces -> Element -> Maybe CharStyle -> RunStyle
elemToRunStyle NameSpaces
ns Element
element Maybe CharStyle
parentStyle)
elemToRunStyle :: NameSpaces -> Element -> Maybe CharStyle -> RunStyle
elemToRunStyle :: NameSpaces -> Element -> Maybe CharStyle -> RunStyle
elemToRunStyle NameSpaces
ns Element
element Maybe CharStyle
parentStyle
| Just Element
rPr <- NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"rPr" Element
element =
RunStyle
{
isBold :: Maybe Bool
isBold = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"b")
, isBoldCTL :: Maybe Bool
isBoldCTL = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"bCs")
, isItalic :: Maybe Bool
isItalic = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"i")
, isItalicCTL :: Maybe Bool
isItalicCTL = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"iCs")
, isSmallCaps :: Maybe Bool
isSmallCaps = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"smallCaps")
, isStrike :: Maybe Bool
isStrike = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"strike")
, isRTL :: Maybe Bool
isRTL = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"rtl")
, isForceCTL :: Maybe Bool
isForceCTL = NameSpaces -> Element -> QName -> Maybe Bool
checkOnOff NameSpaces
ns Element
rPr (NameSpaces -> Text -> Text -> QName
elemName NameSpaces
ns Text
"w" Text
"cs")
, rHighlight :: Maybe Text
rHighlight =
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"highlight" Element
rPr Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val"
, rVertAlign :: Maybe VertAlign
rVertAlign =
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"vertAlign" Element
rPr Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val" Maybe Text -> (Text -> Maybe VertAlign) -> Maybe VertAlign
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
\Text
v -> VertAlign -> Maybe VertAlign
forall a. a -> Maybe a
Just (VertAlign -> Maybe VertAlign) -> VertAlign -> Maybe VertAlign
forall a b. (a -> b) -> a -> b
$ case Text
v of
Text
"superscript" -> VertAlign
SupScrpt
Text
"subscript" -> VertAlign
SubScrpt
Text
_ -> VertAlign
BaseLn
, rUnderline :: Maybe Text
rUnderline =
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"u" Element
rPr Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val"
, rParentStyle :: Maybe CharStyle
rParentStyle = Maybe CharStyle
parentStyle
}
elemToRunStyle NameSpaces
_ Element
_ Maybe CharStyle
_ = RunStyle
defaultRunStyle
getHeaderLevel :: NameSpaces -> Element -> Maybe (ParaStyleName, Int)
NameSpaces
ns Element
element
| Just ParaStyleName
styleName <- NameSpaces -> Element -> Maybe ParaStyleName
forall a. Coercible Text a => NameSpaces -> Element -> Maybe a
getElementStyleName NameSpaces
ns Element
element
, Just Integer
n <- Text -> Maybe Integer
stringToInteger (Text -> Maybe Integer) -> Maybe Text -> Maybe Integer
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
(Text -> Text -> Maybe Text
T.stripPrefix Text
"heading " (Text -> Maybe Text) -> (Text -> Text) -> Text -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$
ParaStyleName -> Text
forall a. FromStyleName a => a -> Text
fromStyleName ParaStyleName
styleName)
, Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0 = (ParaStyleName, Int) -> Maybe (ParaStyleName, Int)
forall a. a -> Maybe a
Just (ParaStyleName
styleName, Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
n)
getHeaderLevel NameSpaces
_ Element
_ = Maybe (ParaStyleName, Int)
forall a. Maybe a
Nothing
getIndentation :: NameSpaces -> Element -> Maybe ParIndentation
getIndentation :: NameSpaces -> Element -> Maybe ParIndentation
getIndentation NameSpaces
ns Element
el = do
Element
indElement <- NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"pPr" Element
el Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"ind"
ParIndentation -> Maybe ParIndentation
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (ParIndentation -> Maybe ParIndentation)
-> ParIndentation -> Maybe ParIndentation
forall a b. (a -> b) -> a -> b
$ ParIndentation
{
leftParIndent :: Maybe Integer
leftParIndent = NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"left" Element
indElement Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"start" Element
indElement Maybe Text -> (Text -> Maybe Integer) -> Maybe Integer
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Text -> Maybe Integer
stringToInteger
, rightParIndent :: Maybe Integer
rightParIndent = NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"right" Element
indElement Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"end" Element
indElement Maybe Text -> (Text -> Maybe Integer) -> Maybe Integer
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Text -> Maybe Integer
stringToInteger
, hangingParIndent :: Maybe Integer
hangingParIndent = NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"hanging" Element
indElement Maybe Text -> (Text -> Maybe Integer) -> Maybe Integer
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
Text -> Maybe Integer
stringToInteger
}
getElementStyleName :: Coercible T.Text a => NameSpaces -> Element -> Maybe a
getElementStyleName :: forall a. Coercible Text a => NameSpaces -> Element -> Maybe a
getElementStyleName NameSpaces
ns Element
el = Text -> a
forall a b. Coercible a b => a -> b
coerce (Text -> a) -> Maybe Text -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
((NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"name" Element
el Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val")
Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"styleId" Element
el)
getNumInfo :: NameSpaces -> Element -> Maybe (T.Text, T.Text)
getNumInfo :: NameSpaces -> Element -> Maybe (Text, Text)
getNumInfo NameSpaces
ns Element
element = do
let numPr :: Maybe Element
numPr = NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"pPr" Element
element Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"numPr"
lvl :: Text
lvl = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"0" (Maybe Element
numPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"ilvl" Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val")
Text
numId <- Maybe Element
numPr Maybe Element -> (Element -> Maybe Element) -> Maybe Element
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Element
findChildByName NameSpaces
ns Text
"w" Text
"numId" Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"val"
(Text, Text) -> Maybe (Text, Text)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
numId, Text
lvl)
elemToParStyleData :: NameSpaces -> Element -> Maybe ParStyle -> Maybe ParStyle
elemToParStyleData :: NameSpaces -> Element -> Maybe ParStyle -> Maybe ParStyle
elemToParStyleData NameSpaces
ns Element
element Maybe ParStyle
parentStyle
| Just Text
styleId <- NameSpaces -> Text -> Text -> Element -> Maybe Text
findAttrByName NameSpaces
ns Text
"w" Text
"styleId" Element
element
, Just ParaStyleName
styleName <- NameSpaces -> Element -> Maybe ParaStyleName
forall a. Coercible Text a => NameSpaces -> Element -> Maybe a
getElementStyleName NameSpaces
ns Element
element
= ParStyle -> Maybe ParStyle
forall a. a -> Maybe a
Just (ParStyle -> Maybe ParStyle) -> ParStyle -> Maybe ParStyle
forall a b. (a -> b) -> a -> b
$ ParStyle
{
headingLev :: Maybe (ParaStyleName, Int)
headingLev = NameSpaces -> Element -> Maybe (ParaStyleName, Int)
getHeaderLevel NameSpaces
ns Element
element
, indent :: Maybe ParIndentation
indent = NameSpaces -> Element -> Maybe ParIndentation
getIndentation NameSpaces
ns Element
element
, numInfo :: Maybe (Text, Text)
numInfo = NameSpaces -> Element -> Maybe (Text, Text)
getNumInfo NameSpaces
ns Element
element
, psParentStyle :: Maybe ParStyle
psParentStyle = Maybe ParStyle
parentStyle
, pStyleName :: ParaStyleName
pStyleName = ParaStyleName
styleName
, pStyleId :: ParaStyleId
pStyleId = Text -> ParaStyleId
ParaStyleId Text
styleId
}
elemToParStyleData NameSpaces
_ Element
_ Maybe ParStyle
_ = Maybe ParStyle
forall a. Maybe a
Nothing