From 65c80822e7900e92b4bba67912da77062654cc26 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 3 Mar 2015 13:08:52 +0300 Subject: Code cleanup --- src/Text/Pandoc/Readers/Docx/StyleMap.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Text/Pandoc/Readers/Docx') diff --git a/src/Text/Pandoc/Readers/Docx/StyleMap.hs b/src/Text/Pandoc/Readers/Docx/StyleMap.hs index 2e3d6db95..5a4e9cfc2 100644 --- a/src/Text/Pandoc/Readers/Docx/StyleMap.hs +++ b/src/Text/Pandoc/Readers/Docx/StyleMap.hs @@ -1,7 +1,4 @@ -module Text.Pandoc.Readers.Docx.StyleMap ( StyleMap - , ParaStyleMap - , CharStyleMap - , StyleMaps(..) +module Text.Pandoc.Readers.Docx.StyleMap ( StyleMaps(..) , defaultStyleMaps , getStyleMaps , getStyleId @@ -58,23 +55,26 @@ getStyleMaps :: Element -> StyleMaps getStyleMaps docElem = fromMaybe state' $ execStateT genStyleMap state' where state' = defaultStyleMaps {sNameSpaces = elemToNameSpaces docElem} - insertPara key val = modify $ \s -> - s { sParaStyleMap = insert key val $ sParaStyleMap s } - insertChar key val = modify $ \s -> - s { sCharStyleMap = insert key val $ sCharStyleMap s } genStyleItem e = do styleType <- getStyleType e - nameVal <- getNameVal e styleId <- getAttrStyleId e - let nameValLC = map toLower nameVal + nameValLowercase <- map toLower `fmap` getNameVal e case styleType of - ParaStyle -> insertPara nameValLC styleId - CharStyle -> insertChar nameValLC styleId + ParaStyle -> modParaStyleMap $ insert nameValLowercase styleId + CharStyle -> modCharStyleMap $ insert nameValLowercase styleId genStyleMap = do style <- elemName' "style" let styles = findChildren style docElem forM_ styles genStyleItem +modParaStyleMap :: (ParaStyleMap -> ParaStyleMap) -> StateM () +modParaStyleMap f = modify $ \s -> + s {sParaStyleMap = f $ sParaStyleMap s} + +modCharStyleMap :: (CharStyleMap -> CharStyleMap) -> StateM () +modCharStyleMap f = modify $ \s -> + s {sCharStyleMap = f $ sCharStyleMap s} + getStyleType :: Element -> StateM StyleType getStyleType e = do styleTypeStr <- getAttrType e -- cgit v1.2.3