diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-25 20:47:58 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-25 20:47:58 +0100 |
commit | 654859af4a9c1c4a8c344328e5ce120ab6f126fe (patch) | |
tree | be984f4fa67bb02c6787d6dc636e5c0a68470fda | |
parent | 5441e11b06a1ef70bf4b13d63e57d2350484bb08 (diff) | |
download | pandoc-654859af4a9c1c4a8c344328e5ce120ab6f126fe.tar.gz |
Docx writer: use Set for dynamic styles to avoid duplicates.
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 6abb58f22..3636a94ba 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -128,8 +128,8 @@ data WriterState = WriterState{ , stStyleMaps :: StyleMaps , stFirstPara :: Bool , stTocTitle :: [Inline] - , stDynamicParaProps :: [String] - , stDynamicTextProps :: [String] + , stDynamicParaProps :: Set.Set String + , stDynamicTextProps :: Set.Set String } defaultWriterState :: WriterState @@ -144,8 +144,8 @@ defaultWriterState = WriterState{ , stStyleMaps = defaultStyleMaps , stFirstPara = False , stTocTitle = [Str "Table of Contents"] - , stDynamicParaProps = [] - , stDynamicTextProps = [] + , stDynamicParaProps = Set.empty + , stDynamicTextProps = Set.empty } type WS m = ReaderT WriterEnv (StateT WriterState m) @@ -443,11 +443,11 @@ writeDocx opts doc@(Pandoc meta _) = do -- are normalized as lowercase. let newDynamicParaProps = filter (\sty -> isNothing $ M.lookup (toLower <$> sty) $ getMap $ sParaStyleMap styleMaps) - (stDynamicParaProps st) + (Set.toList $ stDynamicParaProps st) newDynamicTextProps = filter (\sty -> isNothing $ M.lookup (toLower <$> sty) $ getMap $ sCharStyleMap styleMaps) - (stDynamicTextProps st) + (Set.toList $ stDynamicTextProps st) let newstyles = map newParaPropToOpenXml newDynamicParaProps ++ map newTextPropToOpenXml newDynamicTextProps ++ @@ -800,7 +800,8 @@ blockToOpenXML' opts (Div (ident,classes,kvs) bs) = do stylemod <- case lookup dynamicStyleKey kvs of Just sty -> do modify $ \s -> - s{stDynamicParaProps = sty : (stDynamicParaProps s)} + s{stDynamicParaProps = Set.insert sty + (stDynamicParaProps s)} return $ withParaPropM (pStyleM sty) _ -> return id dirmod <- case lookup "dir" kvs of @@ -1053,7 +1054,8 @@ inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do stylemod <- case lookup dynamicStyleKey kvs of Just sty -> do modify $ \s -> - s{stDynamicTextProps = sty : (stDynamicTextProps s)} + s{stDynamicTextProps = Set.insert sty + (stDynamicTextProps s)} return $ withTextProp (rCustomStyle sty) _ -> return id let dirmod = case lookup "dir" kvs of |