git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: support --number-sections.

Closes #1413.

commit1e84178431b3fc18de92b86c7f09f4908d955a92 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 22 Jul 2020, 10:33 (6 years ago) parent3bccc08
31 files changed+23−5
MANUAL.txt+2−1 data/docx/word/styles.xml+4 src/Text/Pandoc/Writers/Docx.hs+17−4 test/docx/golden/block_quotes.docx test/docx/golden/codeblock.docx test/docx/golden/comments.docx test/docx/golden/custom_style_no_reference.docx test/docx/golden/custom_style_preserve.docx test/docx/golden/definition_list.docx test/docx/golden/document-properties-short-desc.docx test/docx/golden/document-properties.docx test/docx/golden/headers.docx test/docx/golden/image.docx test/docx/golden/inline_code.docx test/docx/golden/inline_formatting.docx test/docx/golden/inline_images.docx test/docx/golden/link_in_notes.docx test/docx/golden/links.docx test/docx/golden/lists.docx test/docx/golden/lists_continuing.docx test/docx/golden/lists_restarting.docx test/docx/golden/nested_anchors_in_header.docx test/docx/golden/notes.docx test/docx/golden/table_one_row.docx test/docx/golden/table_with_list_cell.docx test/docx/golden/tables.docx test/docx/golden/track_changes_deletion.docx test/docx/golden/track_changes_insertion.docx test/docx/golden/track_changes_move.docx test/docx/golden/unicode.docx test/docx/golden/verbatim_subsuper.docx
MANUAL.txt+2−1
@@ -982,7 +982,7 @@ header when requesting a document from a URL:
982982
983983`-N`, `--number-sections`
984984
985−: Number section headings in LaTeX, ConTeXt, HTML, or EPUB output.
985+: Number section headings in LaTeX, ConTeXt, HTML, Docx, or EPUB output.
986986 By default, sections are not numbered. Sections with class
987987 `unnumbered` will never be numbered, even if `--number-sections`
988988 is specified.
@@ -1125,6 +1125,7 @@ header when requesting a document from a URL:
11251125 - Verbatim Char
11261126 - Footnote Reference
11271127 - Hyperlink
1128+ - Section Number
11281129
11291130 Table style:
11301131
data/docx/word/styles.xml+4
@@ -414,6 +414,10 @@
414414 <w:sz w:val="22" />
415415 </w:rPr>
416416 </w:style>
417+ <w:style w:type="character" w:customStyle="1" w:styleId="SectionNumber">
418+ <w:name w:val="Section Number" />
419+ <w:basedOn w:val="BodyTextChar" />
420+ </w:style>
417421 <w:style w:type="character" w:styleId="FootnoteReference">
418422 <w:name w:val="Footnote Reference" />
419423 <w:basedOn w:val="BodyTextChar" />
src/Text/Pandoc/Writers/Docx.hs+17−4
@@ -210,8 +210,11 @@ writeDocx :: (PandocMonad m)
210210 => WriterOptions -- ^ Writer options
211211 -> Pandoc -- ^ Document to convert
212212 -> m BL.ByteString
213−writeDocx opts doc@(Pandoc meta _) = do
214− let doc' = walk fixDisplayMath doc
213+writeDocx opts doc = do
214+ let Pandoc meta blocks = walk fixDisplayMath doc
215+ let blocks' = makeSections True Nothing blocks
216+ let doc' = Pandoc meta blocks'
217+
215218 username <- P.lookupEnv "USERNAME"
216219 utctime <- P.getCurrentTime
217220 oldUserDataDir <- P.getUserDataDir
@@ -898,11 +901,21 @@ blockToOpenXML' opts (Div (ident,_classes,kvs) bs) = do
898901 header <- dirmod $ stylemod $ blocksToOpenXML opts hs
899902 contents <- dirmod $ bibmod $ stylemod $ blocksToOpenXML opts bs'
900903 wrapBookmark ident $ header <> contents
901−blockToOpenXML' opts (Header lev (ident,_,_) lst) = do
904+blockToOpenXML' opts (Header lev (ident,_,kvs) lst) = do
902905 setFirstPara
903906 paraProps <- withParaPropM (pStyleM (fromString $ "Heading "++show lev)) $
904907 getParaProps False
905− contents <- inlinesToOpenXML opts lst
908+ number <-
909+ if writerNumberSections opts
910+ then
911+ case lookup "number" kvs of
912+ Just n -> do
913+ num <- withTextPropM (rStyleM "SectionNumber")
914+ (inlineToOpenXML opts (Str n))
915+ return $ num ++ [mknode "w:r" [] [mknode "w:tab" [] ()]]
916+ Nothing -> return []
917+ else return []
918+ contents <- (number ++) <$> inlinesToOpenXML opts lst
906919 if T.null ident
907920 then return [mknode "w:p" [] (paraProps ++ contents)]
908921 else do
test/docx/golden/block_quotes.docx

Binary file not shown.

test/docx/golden/codeblock.docx

Binary file not shown.

test/docx/golden/comments.docx

Binary file not shown.

test/docx/golden/custom_style_no_reference.docx

Binary file not shown.

test/docx/golden/custom_style_preserve.docx

Binary file not shown.

test/docx/golden/definition_list.docx

Binary file not shown.

test/docx/golden/document-properties-short-desc.docx

Binary file not shown.

test/docx/golden/document-properties.docx

Binary file not shown.

test/docx/golden/headers.docx

Binary file not shown.

test/docx/golden/image.docx

Binary file not shown.

test/docx/golden/inline_code.docx

Binary file not shown.

test/docx/golden/inline_formatting.docx

Binary file not shown.

test/docx/golden/inline_images.docx

Binary file not shown.

test/docx/golden/link_in_notes.docx

Binary file not shown.

test/docx/golden/links.docx

Binary file not shown.

test/docx/golden/lists.docx

Binary file not shown.

test/docx/golden/lists_continuing.docx

Binary file not shown.

test/docx/golden/lists_restarting.docx

Binary file not shown.

test/docx/golden/nested_anchors_in_header.docx

Binary file not shown.

test/docx/golden/notes.docx

Binary file not shown.

test/docx/golden/table_one_row.docx

Binary file not shown.

test/docx/golden/table_with_list_cell.docx

Binary file not shown.

test/docx/golden/tables.docx

Binary file not shown.

test/docx/golden/track_changes_deletion.docx

Binary file not shown.

test/docx/golden/track_changes_insertion.docx

Binary file not shown.

test/docx/golden/track_changes_move.docx

Binary file not shown.

test/docx/golden/unicode.docx

Binary file not shown.

test/docx/golden/verbatim_subsuper.docx

Binary file not shown.