@@ -63,7 +63,7 @@ import qualified Control.Exception as E
63import Text.Pandoc.MIME (MimeType, getMimeType, getMimeTypeDef,
63import Text.Pandoc.MIME (MimeType, getMimeType, getMimeTypeDef,
64 extensionFromMimeType)
64 extensionFromMimeType)
65import Control.Applicative ((<$>), (<|>), (<*>))
65import Control.Applicative ((<$>), (<|>), (<*>))
66−import Data.Maybe (fromMaybe, mapMaybe)
66+import Data.Maybe (fromMaybe, mapMaybe, maybeToList)
67import Data.Char (toLower)
67import Data.Char (toLower)
69data ListMarker = NoMarker
69data ListMarker = NoMarker
@@ -394,7 +394,7 @@ writeDocx opts doc@(Pandoc meta _) = do
396 -- styles
396 -- styles
397− let newstyles = styleToOpenXml charStyles $ writerHighlightStyle opts
397+ let newstyles = styleToOpenXml charStyles paraStyles $ writerHighlightStyle opts
398 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
398 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
400 modifyContent
400 modifyContent
@@ -404,7 +404,7 @@ writeDocx opts doc@(Pandoc meta _) = do
404 notTokStyle _ = True
404 notTokStyle _ = True
405 notStyle = (/= myName "style") . elName
405 notStyle = (/= myName "style") . elName
406 notTokId = maybe True (`notElem` tokStys) . getAttrStyleId
406 notTokId = maybe True (`notElem` tokStys) . getAttrStyleId
407− tokStys = map show $ enumFromTo KeywordTok NormalTok
407+ tokStys = "SourceCode" : map show (enumFromTo KeywordTok NormalTok)
408 let styleEntry = toEntry stylepath epochtime $ renderXml styledoc'
408 let styleEntry = toEntry stylepath epochtime $ renderXml styledoc'
410 -- construct word/numbering.xml
410 -- construct word/numbering.xml
@@ -481,12 +481,13 @@ writeDocx opts doc@(Pandoc meta _) = do
481 miscRelEntries ++ otherMediaEntries
481 miscRelEntries ++ otherMediaEntries
482 return $ fromArchive archive
482 return $ fromArchive archive
484−styleToOpenXml :: CharStyleMap -> Style -> [Element]
484+styleToOpenXml :: CharStyleMap -> ParaStyleMap -> Style -> [Element]
485+styleToOpenXml (CharStyleMap csm) (ParaStyleMap psm) style =
485−styleToOpenXml (CharStyleMap m) style = parStyle : mapMaybe toStyle alltoktypes
486+ maybeToList parStyle ++ mapMaybe toStyle alltoktypes
486 where alltoktypes = enumFromTo KeywordTok NormalTok
487 where alltoktypes = enumFromTo KeywordTok NormalTok
488− if M.member (map toLower $ show toktype) m then Nothing
488+ styleExists m styleName = M.member (map toLower styleName) m
489− else Just $
489+ toStyle toktype | styleExists csm $ show toktype = Nothing
490+ | otherwise = Just $
490 mknode "w:style" [("w:type","character"),
491 mknode "w:style" [("w:type","character"),
491 ("w:customStyle","1"),("w:styleId",show toktype)]
492 ("w:customStyle","1"),("w:styleId",show toktype)]
492 [ mknode "w:name" [("w:val",show toktype)] ()
493 [ mknode "w:name" [("w:val",show toktype)] ()
@@ -508,7 +509,9 @@ styleToOpenXml (CharStyleMap m) style = parStyle : mapMaybe toStyle alltoktypes
508 tokBg toktype = maybe "auto" (drop 1 . fromColor)
509 tokBg toktype = maybe "auto" (drop 1 . fromColor)
509 $ (tokenBackground =<< lookup toktype tokStyles)
510 $ (tokenBackground =<< lookup toktype tokStyles)
510 `mplus` backgroundColor style
511 `mplus` backgroundColor style
512+ parStyle | styleExists psm "Source Code" = Nothing
513+ | otherwise = Just $
511− parStyle = mknode "w:style" [("w:type","paragraph"),
514+ mknode "w:style" [("w:type","paragraph"),
512 ("w:customStyle","1"),("w:styleId","SourceCode")]
515 ("w:customStyle","1"),("w:styleId","SourceCode")]
513 [ mknode "w:name" [("w:val","Source Code")] ()
516 [ mknode "w:name" [("w:val","Source Code")] ()
514 , mknode "w:basedOn" [("w:val","Normal")] ()
517 , mknode "w:basedOn" [("w:val","Normal")] ()