diff options
author | Nikolay Yakimov <root@livid.pp.ru> | 2015-02-23 01:53:47 +0300 |
---|---|---|
committer | Nikolay Yakimov <root@livid.pp.ru> | 2015-02-23 01:53:47 +0300 |
commit | 7ae7f0c051b83e41c8bb4c0f15a2b57f76cd6298 (patch) | |
tree | e75988ced8aa4113343ba2c3161a5f1e20ce2f07 /src | |
parent | 8b3acde9deaeb30ba75299001ea1b15345983f3c (diff) | |
download | pandoc-7ae7f0c051b83e41c8bb4c0f15a2b57f76cd6298.tar.gz |
Also skip SourceCode style if exists
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 64da9a497..ba8a28de0 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -63,7 +63,7 @@ import qualified Control.Exception as E import Text.Pandoc.MIME (MimeType, getMimeType, getMimeTypeDef, extensionFromMimeType) import Control.Applicative ((<$>), (<|>), (<*>)) -import Data.Maybe (fromMaybe, mapMaybe) +import Data.Maybe (fromMaybe, mapMaybe, maybeToList) import Data.Char (toLower) data ListMarker = NoMarker @@ -394,7 +394,7 @@ writeDocx opts doc@(Pandoc meta _) = do linkrels -- styles - let newstyles = styleToOpenXml charStyles $ writerHighlightStyle opts + let newstyles = styleToOpenXml charStyles paraStyles $ writerHighlightStyle opts let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) } where modifyContent @@ -404,7 +404,7 @@ writeDocx opts doc@(Pandoc meta _) = do notTokStyle _ = True notStyle = (/= myName "style") . elName notTokId = maybe True (`notElem` tokStys) . getAttrStyleId - tokStys = map show $ enumFromTo KeywordTok NormalTok + tokStys = "SourceCode" : map show (enumFromTo KeywordTok NormalTok) let styleEntry = toEntry stylepath epochtime $ renderXml styledoc' -- construct word/numbering.xml @@ -481,12 +481,13 @@ writeDocx opts doc@(Pandoc meta _) = do miscRelEntries ++ otherMediaEntries return $ fromArchive archive -styleToOpenXml :: CharStyleMap -> Style -> [Element] -styleToOpenXml (CharStyleMap m) style = parStyle : mapMaybe toStyle alltoktypes +styleToOpenXml :: CharStyleMap -> ParaStyleMap -> Style -> [Element] +styleToOpenXml (CharStyleMap csm) (ParaStyleMap psm) style = + maybeToList parStyle ++ mapMaybe toStyle alltoktypes where alltoktypes = enumFromTo KeywordTok NormalTok - toStyle toktype = - if M.member (map toLower $ show toktype) m then Nothing - else Just $ + styleExists m styleName = M.member (map toLower styleName) m + toStyle toktype | styleExists csm $ show toktype = Nothing + | otherwise = Just $ mknode "w:style" [("w:type","character"), ("w:customStyle","1"),("w:styleId",show toktype)] [ mknode "w:name" [("w:val",show toktype)] () @@ -508,7 +509,9 @@ styleToOpenXml (CharStyleMap m) style = parStyle : mapMaybe toStyle alltoktypes tokBg toktype = maybe "auto" (drop 1 . fromColor) $ (tokenBackground =<< lookup toktype tokStyles) `mplus` backgroundColor style - parStyle = mknode "w:style" [("w:type","paragraph"), + parStyle | styleExists psm "Source Code" = Nothing + | otherwise = Just $ + mknode "w:style" [("w:type","paragraph"), ("w:customStyle","1"),("w:styleId","SourceCode")] [ mknode "w:name" [("w:val","Source Code")] () , mknode "w:basedOn" [("w:val","Normal")] () |