diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-07-22 10:33:33 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-07-22 11:53:31 -0700 |
commit | 1e84178431b3fc18de92b86c7f09f4908d955a92 (patch) | |
tree | 9426fe16b140310aa5a367d5d2b6c9fb45306e1d /src/Text | |
parent | 3bccc08f6c6ac5c3973d67a4e62266c26507033d (diff) | |
download | pandoc-1e84178431b3fc18de92b86c7f09f4908d955a92.tar.gz |
Docx writer: support --number-sections.
Closes #1413.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 89f100720..f448c4ce2 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -210,8 +210,11 @@ writeDocx :: (PandocMonad m) => WriterOptions -- ^ Writer options -> Pandoc -- ^ Document to convert -> m BL.ByteString -writeDocx opts doc@(Pandoc meta _) = do - let doc' = walk fixDisplayMath doc +writeDocx opts doc = do + let Pandoc meta blocks = walk fixDisplayMath doc + let blocks' = makeSections True Nothing blocks + let doc' = Pandoc meta blocks' + username <- P.lookupEnv "USERNAME" utctime <- P.getCurrentTime oldUserDataDir <- P.getUserDataDir @@ -898,11 +901,21 @@ blockToOpenXML' opts (Div (ident,_classes,kvs) bs) = do header <- dirmod $ stylemod $ blocksToOpenXML opts hs contents <- dirmod $ bibmod $ stylemod $ blocksToOpenXML opts bs' wrapBookmark ident $ header <> contents -blockToOpenXML' opts (Header lev (ident,_,_) lst) = do +blockToOpenXML' opts (Header lev (ident,_,kvs) lst) = do setFirstPara paraProps <- withParaPropM (pStyleM (fromString $ "Heading "++show lev)) $ getParaProps False - contents <- inlinesToOpenXML opts lst + number <- + if writerNumberSections opts + then + case lookup "number" kvs of + Just n -> do + num <- withTextPropM (rStyleM "SectionNumber") + (inlineToOpenXML opts (Str n)) + return $ num ++ [mknode "w:r" [] [mknode "w:tab" [] ()]] + Nothing -> return [] + else return [] + contents <- (number ++) <$> inlinesToOpenXML opts lst if T.null ident then return [mknode "w:p" [] (paraProps ++ contents)] else do |