Docx writer: support --number-sections.

Closes #1413.
This commit is contained in:
John MacFarlane 2020-07-22 10:33:33 -07:00
parent 3bccc08f6c
commit 1e84178431
31 changed files with 23 additions and 5 deletions

View file

@ -982,7 +982,7 @@ header when requesting a document from a URL:
`-N`, `--number-sections`
: Number section headings in LaTeX, ConTeXt, HTML, or EPUB output.
: Number section headings in LaTeX, ConTeXt, HTML, Docx, or EPUB output.
By default, sections are not numbered. Sections with class
`unnumbered` will never be numbered, even if `--number-sections`
is specified.
@ -1125,6 +1125,7 @@ header when requesting a document from a URL:
- Verbatim Char
- Footnote Reference
- Hyperlink
- Section Number
Table style:

View file

@ -414,6 +414,10 @@
<w:sz w:val="22" />
</w:rPr>
</w:style>
<w:style w:type="character" w:customStyle="1" w:styleId="SectionNumber">
<w:name w:val="Section Number" />
<w:basedOn w:val="BodyTextChar" />
</w:style>
<w:style w:type="character" w:styleId="FootnoteReference">
<w:name w:val="Footnote Reference" />
<w:basedOn w:val="BodyTextChar" />

View file

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.