git.iko.soy/typeable/pandoc
on master help sign in
Also skip SourceCode style if exists
commit7ae7f0c051b83e41c8bb4c0f15a2b57f76cd6298 authorNikolay Yakimov <root@livid.pp.ru> dateMon 23 Feb 2015, 01:53 (12 years ago) parent8b3acde
1 file changed+12−9
src/Text/Pandoc/Writers/Docx.hs+12−9
src/Text/Pandoc/Writers/Docx.hs+12−9
@@ -63,7 +63,7 @@ import qualified Control.Exception as E
6363import Text.Pandoc.MIME (MimeType, getMimeType, getMimeTypeDef,
6464 extensionFromMimeType)
6565import Control.Applicative ((<$>), (<|>), (<*>))
66−import Data.Maybe (fromMaybe, mapMaybe)
66+import Data.Maybe (fromMaybe, mapMaybe, maybeToList)
6767import Data.Char (toLower)
6868
6969data ListMarker = NoMarker
@@ -394,7 +394,7 @@ writeDocx opts doc@(Pandoc meta _) = do
394394 linkrels
395395
396396 -- styles
397− let newstyles = styleToOpenXml charStyles $ writerHighlightStyle opts
397+ let newstyles = styleToOpenXml charStyles paraStyles $ writerHighlightStyle opts
398398 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
399399 where
400400 modifyContent
@@ -404,7 +404,7 @@ writeDocx opts doc@(Pandoc meta _) = do
404404 notTokStyle _ = True
405405 notStyle = (/= myName "style") . elName
406406 notTokId = maybe True (`notElem` tokStys) . getAttrStyleId
407− tokStys = map show $ enumFromTo KeywordTok NormalTok
407+ tokStys = "SourceCode" : map show (enumFromTo KeywordTok NormalTok)
408408 let styleEntry = toEntry stylepath epochtime $ renderXml styledoc'
409409
410410 -- construct word/numbering.xml
@@ -481,12 +481,13 @@ writeDocx opts doc@(Pandoc meta _) = do
481481 miscRelEntries ++ otherMediaEntries
482482 return $ fromArchive archive
483483
484−styleToOpenXml :: CharStyleMap -> Style -> [Element]
485−styleToOpenXml (CharStyleMap m) style = parStyle : mapMaybe toStyle alltoktypes
484+styleToOpenXml :: CharStyleMap -> ParaStyleMap -> Style -> [Element]
485+styleToOpenXml (CharStyleMap csm) (ParaStyleMap psm) style =
486+ maybeToList parStyle ++ mapMaybe toStyle alltoktypes
486487 where alltoktypes = enumFromTo KeywordTok NormalTok
487− toStyle toktype =
488− if M.member (map toLower $ show toktype) m then Nothing
489− else Just $
488+ styleExists m styleName = M.member (map toLower styleName) m
489+ toStyle toktype | styleExists csm $ show toktype = Nothing
490+ | otherwise = Just $
490491 mknode "w:style" [("w:type","character"),
491492 ("w:customStyle","1"),("w:styleId",show toktype)]
492493 [ mknode "w:name" [("w:val",show toktype)] ()
@@ -508,7 +509,9 @@ styleToOpenXml (CharStyleMap m) style = parStyle : mapMaybe toStyle alltoktypes
508509 tokBg toktype = maybe "auto" (drop 1 . fromColor)
509510 $ (tokenBackground =<< lookup toktype tokStyles)
510511 `mplus` backgroundColor style
511− parStyle = mknode "w:style" [("w:type","paragraph"),
512+ parStyle | styleExists psm "Source Code" = Nothing
513+ | otherwise = Just $
514+ mknode "w:style" [("w:type","paragraph"),
512515 ("w:customStyle","1"),("w:styleId","SourceCode")]
513516 [ mknode "w:name" [("w:val","Source Code")] ()
514517 , mknode "w:basedOn" [("w:val","Normal")] ()