@@ -64,8 +64,8 @@ import Text.Pandoc.Compat.Monoid ((<>))
6464import Text.Pandoc.MIME (MimeType, getMimeType, getMimeTypeDef,
6565 extensionFromMimeType)
6666import Control.Applicative ((<|>))
67−import Data.Maybe (fromMaybe, mapMaybe, maybeToList)
68−import Data.Char (ord)
67+import Data.Maybe (fromMaybe, mapMaybe, maybeToList, isNothing)
68+import Data.Char (ord, isSpace, toLower)
6969
7070data ListMarker = NoMarker
7171 | BulletMarker
@@ -405,8 +405,14 @@ writeDocx opts doc@(Pandoc meta _) = do
405405 $ renderXml $ mknode "Relationships" [("xmlns","http://schemas.openxmlformats.org/package/2006/relationships")]
406406 linkrels
407407
408− -- styles
409− let newstyles = styleToOpenXml styleMaps $ writerHighlightStyle opts
408+ -- styles We only want to inject paragraph properties that are not
409+ -- already in the style map. Note that keys in the stylemap are
410+ -- normalized as lowercase.
411+ let newDynamicParaProps = filter
412+ (\sty -> isNothing $ M.lookup (toLower <$> sty) $ getMap $ sParaStyleMap styleMaps)
413+ (stDynamicParaProps st)
414+ let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
415+ (styleToOpenXml styleMaps $ writerHighlightStyle opts)
410416 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
411417 where
412418 modifyContent
@@ -501,6 +507,19 @@ writeDocx opts doc@(Pandoc meta _) = do
501507 miscRelEntries ++ otherMediaEntries
502508 return $ fromArchive archive
503509
510+
511+newParaPropToOpenXml :: String -> Element
512+newParaPropToOpenXml s =
513+ let styleId = filter (not . isSpace) s
514+ in mknode "w:style" [ ("w:type", "paragraph")
515+ , ("w:customStyle", "1")
516+ , ("w:styleId", styleId)]
517+ [ mknode "w:name" [("w:val", s)] ()
518+ , mknode "w:basedOn" [("w:val","BodyText")] ()
519+ , mknode "w:qFormat" [] ()
520+ ]
521+
522+
504523styleToOpenXml :: StyleMaps -> Style -> [Element]
505524styleToOpenXml sm style =
506525 maybeToList parStyle ++ mapMaybe toStyle alltoktypes