{-# LANGUAGE FlexibleContexts #-}
module Text.Pandoc.Writers.Docx.StyleMap ( StyleMaps(..)
, ParaStyleName
, CharStyleName
, getStyleMaps
, getStyleIdFromName
, hasStyleName
, fromStyleId
, fromStyleName
) where
import Text.Pandoc.Readers.Docx.Parse.Styles
import Codec.Archive.Zip
import qualified Data.Map as M
import qualified Data.Text as T
import Data.String
import Data.Char (isSpace)
data StyleMaps = StyleMaps { StyleMaps -> CharStyleNameMap
smCharStyle :: CharStyleNameMap, StyleMaps -> ParaStyleNameMap
smParaStyle :: ParaStyleNameMap }
type ParaStyleNameMap = M.Map ParaStyleName ParStyle
type CharStyleNameMap = M.Map CharStyleName CharStyle
getStyleIdFromName :: (Ord sn, FromStyleName sn, IsString (StyleId sty), HasStyleId sty)
=> sn -> M.Map sn sty -> StyleId sty
getStyleIdFromName :: forall sn sty.
(Ord sn, FromStyleName sn, IsString (StyleId sty),
HasStyleId sty) =>
sn -> Map sn sty -> StyleId sty
getStyleIdFromName sn
s = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (sn -> StyleId sty
fallback sn
s) forall a. HasStyleId a => a -> StyleId a
getStyleId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup sn
s
where fallback :: sn -> StyleId sty
fallback = forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
T.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpace) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromStyleName a => a -> Text
fromStyleName
hasStyleName :: (Ord sn, HasStyleId sty)
=> sn -> M.Map sn sty -> Bool
hasStyleName :: forall sn sty. (Ord sn, HasStyleId sty) => sn -> Map sn sty -> Bool
hasStyleName sn
styleName = forall k a. Ord k => k -> Map k a -> Bool
M.member sn
styleName
getStyleMaps :: Archive -> StyleMaps
getStyleMaps :: Archive -> StyleMaps
getStyleMaps = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry CharStyleNameMap -> ParaStyleNameMap -> StyleMaps
StyleMaps forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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' forall a. HasStyleName a => a -> StyleName a
getStyleName forall a. HasStyleName a => a -> StyleName a
getStyleName