aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-07-22 10:33:33 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2020-07-22 11:53:31 -0700
commit1e84178431b3fc18de92b86c7f09f4908d955a92 (patch)
tree9426fe16b140310aa5a367d5d2b6c9fb45306e1d
parent3bccc08f6c6ac5c3973d67a4e62266c26507033d (diff)
downloadpandoc-1e84178431b3fc18de92b86c7f09f4908d955a92.tar.gz
Docx writer: support --number-sections.
Closes #1413.
-rw-r--r--MANUAL.txt3
-rw-r--r--data/docx/word/styles.xml4
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs21
-rw-r--r--test/docx/golden/block_quotes.docxbin10036 -> 10052 bytes
-rw-r--r--test/docx/golden/codeblock.docxbin9882 -> 9904 bytes
-rw-r--r--test/docx/golden/comments.docxbin10216 -> 10239 bytes
-rw-r--r--test/docx/golden/custom_style_no_reference.docxbin9980 -> 10003 bytes
-rw-r--r--test/docx/golden/custom_style_preserve.docxbin10606 -> 10624 bytes
-rw-r--r--test/docx/golden/definition_list.docxbin9873 -> 9895 bytes
-rw-r--r--test/docx/golden/document-properties-short-desc.docxbin9884 -> 9906 bytes
-rw-r--r--test/docx/golden/document-properties.docxbin10361 -> 10384 bytes
-rw-r--r--test/docx/golden/headers.docxbin10022 -> 10040 bytes
-rw-r--r--test/docx/golden/image.docxbin26698 -> 26718 bytes
-rw-r--r--test/docx/golden/inline_code.docxbin9817 -> 9840 bytes
-rw-r--r--test/docx/golden/inline_formatting.docxbin9987 -> 10010 bytes
-rw-r--r--test/docx/golden/inline_images.docxbin26753 -> 26776 bytes
-rw-r--r--test/docx/golden/link_in_notes.docxbin10039 -> 10061 bytes
-rw-r--r--test/docx/golden/links.docxbin10217 -> 10236 bytes
-rw-r--r--test/docx/golden/lists.docxbin10307 -> 10325 bytes
-rw-r--r--test/docx/golden/lists_continuing.docxbin10091 -> 10113 bytes
-rw-r--r--test/docx/golden/lists_restarting.docxbin10091 -> 10113 bytes
-rw-r--r--test/docx/golden/nested_anchors_in_header.docxbin10179 -> 10199 bytes
-rw-r--r--test/docx/golden/notes.docxbin9989 -> 10006 bytes
-rw-r--r--test/docx/golden/table_one_row.docxbin9863 -> 9885 bytes
-rw-r--r--test/docx/golden/table_with_list_cell.docxbin10238 -> 10260 bytes
-rw-r--r--test/docx/golden/tables.docxbin10252 -> 10273 bytes
-rw-r--r--test/docx/golden/track_changes_deletion.docxbin9861 -> 9884 bytes
-rw-r--r--test/docx/golden/track_changes_insertion.docxbin9844 -> 9867 bytes
-rw-r--r--test/docx/golden/track_changes_move.docxbin9878 -> 9901 bytes
-rw-r--r--test/docx/golden/unicode.docxbin9802 -> 9825 bytes
-rw-r--r--test/docx/golden/verbatim_subsuper.docxbin9850 -> 9873 bytes
31 files changed, 23 insertions, 5 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 7ed69b09d..5f110dc5f 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -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:
diff --git a/data/docx/word/styles.xml b/data/docx/word/styles.xml
index 583596266..6bb5a3f52 100644
--- a/data/docx/word/styles.xml
+++ b/data/docx/word/styles.xml
@@ -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" />
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
diff --git a/test/docx/golden/block_quotes.docx b/test/docx/golden/block_quotes.docx
index d478369f7..94eb8e811 100644
--- a/test/docx/golden/block_quotes.docx
+++ b/test/docx/golden/block_quotes.docx
Binary files differ
diff --git a/test/docx/golden/codeblock.docx b/test/docx/golden/codeblock.docx
index f986b0055..ee796a1fb 100644
--- a/test/docx/golden/codeblock.docx
+++ b/test/docx/golden/codeblock.docx
Binary files differ
diff --git a/test/docx/golden/comments.docx b/test/docx/golden/comments.docx
index fbb919260..a19f77278 100644
--- a/test/docx/golden/comments.docx
+++ b/test/docx/golden/comments.docx
Binary files differ
diff --git a/test/docx/golden/custom_style_no_reference.docx b/test/docx/golden/custom_style_no_reference.docx
index f14537def..c6195737f 100644
--- a/test/docx/golden/custom_style_no_reference.docx
+++ b/test/docx/golden/custom_style_no_reference.docx
Binary files differ
diff --git a/test/docx/golden/custom_style_preserve.docx b/test/docx/golden/custom_style_preserve.docx
index 64e42e9d3..9997672ba 100644
--- a/test/docx/golden/custom_style_preserve.docx
+++ b/test/docx/golden/custom_style_preserve.docx
Binary files differ
diff --git a/test/docx/golden/definition_list.docx b/test/docx/golden/definition_list.docx
index 1afb20e6c..a4abcd463 100644
--- a/test/docx/golden/definition_list.docx
+++ b/test/docx/golden/definition_list.docx
Binary files differ
diff --git a/test/docx/golden/document-properties-short-desc.docx b/test/docx/golden/document-properties-short-desc.docx
index ba7cc8df0..d18c110b6 100644
--- a/test/docx/golden/document-properties-short-desc.docx
+++ b/test/docx/golden/document-properties-short-desc.docx
Binary files differ
diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx
index 426a908bb..39d87a31a 100644
--- a/test/docx/golden/document-properties.docx
+++ b/test/docx/golden/document-properties.docx
Binary files differ
diff --git a/test/docx/golden/headers.docx b/test/docx/golden/headers.docx
index 63e754b5c..6458ce105 100644
--- a/test/docx/golden/headers.docx
+++ b/test/docx/golden/headers.docx
Binary files differ
diff --git a/test/docx/golden/image.docx b/test/docx/golden/image.docx
index 04a6f2041..90362a709 100644
--- a/test/docx/golden/image.docx
+++ b/test/docx/golden/image.docx
Binary files differ
diff --git a/test/docx/golden/inline_code.docx b/test/docx/golden/inline_code.docx
index ae415a3a1..3002a2b7d 100644
--- a/test/docx/golden/inline_code.docx
+++ b/test/docx/golden/inline_code.docx
Binary files differ
diff --git a/test/docx/golden/inline_formatting.docx b/test/docx/golden/inline_formatting.docx
index ddfd45280..c5f6ce186 100644
--- a/test/docx/golden/inline_formatting.docx
+++ b/test/docx/golden/inline_formatting.docx
Binary files differ
diff --git a/test/docx/golden/inline_images.docx b/test/docx/golden/inline_images.docx
index 00a4e77c7..99e1e5e79 100644
--- a/test/docx/golden/inline_images.docx
+++ b/test/docx/golden/inline_images.docx
Binary files differ
diff --git a/test/docx/golden/link_in_notes.docx b/test/docx/golden/link_in_notes.docx
index 18c7ec8c4..a1003b47e 100644
--- a/test/docx/golden/link_in_notes.docx
+++ b/test/docx/golden/link_in_notes.docx
Binary files differ
diff --git a/test/docx/golden/links.docx b/test/docx/golden/links.docx
index 3e99c48f3..86f0230ca 100644
--- a/test/docx/golden/links.docx
+++ b/test/docx/golden/links.docx
Binary files differ
diff --git a/test/docx/golden/lists.docx b/test/docx/golden/lists.docx
index 84cb1b277..c64cbf46b 100644
--- a/test/docx/golden/lists.docx
+++ b/test/docx/golden/lists.docx
Binary files differ
diff --git a/test/docx/golden/lists_continuing.docx b/test/docx/golden/lists_continuing.docx
index ee1cb3d49..8fbd3190c 100644
--- a/test/docx/golden/lists_continuing.docx
+++ b/test/docx/golden/lists_continuing.docx
Binary files differ
diff --git a/test/docx/golden/lists_restarting.docx b/test/docx/golden/lists_restarting.docx
index 8725ffe82..e4d75764d 100644
--- a/test/docx/golden/lists_restarting.docx
+++ b/test/docx/golden/lists_restarting.docx
Binary files differ
diff --git a/test/docx/golden/nested_anchors_in_header.docx b/test/docx/golden/nested_anchors_in_header.docx
index 96b999707..3a1286e31 100644
--- a/test/docx/golden/nested_anchors_in_header.docx
+++ b/test/docx/golden/nested_anchors_in_header.docx
Binary files differ
diff --git a/test/docx/golden/notes.docx b/test/docx/golden/notes.docx
index 17dfa8c54..de39a4305 100644
--- a/test/docx/golden/notes.docx
+++ b/test/docx/golden/notes.docx
Binary files differ
diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx
index 1a7ddf476..b3cf7b27d 100644
--- a/test/docx/golden/table_one_row.docx
+++ b/test/docx/golden/table_one_row.docx
Binary files differ
diff --git a/test/docx/golden/table_with_list_cell.docx b/test/docx/golden/table_with_list_cell.docx
index e200c8cf5..64b5f1d59 100644
--- a/test/docx/golden/table_with_list_cell.docx
+++ b/test/docx/golden/table_with_list_cell.docx
Binary files differ
diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx
index 5b0a728e3..38b4d2391 100644
--- a/test/docx/golden/tables.docx
+++ b/test/docx/golden/tables.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_deletion.docx b/test/docx/golden/track_changes_deletion.docx
index 1ab4f1d0e..97c060915 100644
--- a/test/docx/golden/track_changes_deletion.docx
+++ b/test/docx/golden/track_changes_deletion.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_insertion.docx b/test/docx/golden/track_changes_insertion.docx
index c9f3c8a88..a1f141043 100644
--- a/test/docx/golden/track_changes_insertion.docx
+++ b/test/docx/golden/track_changes_insertion.docx
Binary files differ
diff --git a/test/docx/golden/track_changes_move.docx b/test/docx/golden/track_changes_move.docx
index acf11e7f7..fbfd8ec59 100644
--- a/test/docx/golden/track_changes_move.docx
+++ b/test/docx/golden/track_changes_move.docx
Binary files differ
diff --git a/test/docx/golden/unicode.docx b/test/docx/golden/unicode.docx
index 97ca3e7e5..4daf635e9 100644
--- a/test/docx/golden/unicode.docx
+++ b/test/docx/golden/unicode.docx
Binary files differ
diff --git a/test/docx/golden/verbatim_subsuper.docx b/test/docx/golden/verbatim_subsuper.docx
index 279b11279..984f16abd 100644
--- a/test/docx/golden/verbatim_subsuper.docx
+++ b/test/docx/golden/verbatim_subsuper.docx
Binary files differ