aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2015-02-12 08:52:40 -0500
committerJesse Rosenthal <jrosenthal@jhu.edu>2015-02-12 09:21:41 -0500
commitba59e5447ffe8d15dd7fee69a7aa03706ce3c49b (patch)
treeb9357dec3618eb5fc3f4ea1e2cb8e1423b75261f
parentc2f32f4e8fb34df84c5b42a3893233e319fcfd3a (diff)
downloadpandoc-ba59e5447ffe8d15dd7fee69a7aa03706ce3c49b.tar.gz
Docx writer: Add footnotes id -1 and 0.
Word uses, by default, footnotes with id -1 and 0 for separators. If a user modifies reference.docx, they will end up with a settings.xml file that references these footnotes, but no such footnotes in the document. This will produce a corruption error. Here we add these to the document and settings.xml file, so future modifications won't break the file.
-rw-r--r--data/reference.docxbin8393 -> 8474 bytes
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs18
2 files changed, 17 insertions, 1 deletions
diff --git a/data/reference.docx b/data/reference.docx
index 39f4fc19e..c2e5075b1 100644
--- a/data/reference.docx
+++ b/data/reference.docx
Binary files differ
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 8d1721f4d..441392918 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -114,7 +114,7 @@ defaultWriterState :: WriterState
defaultWriterState = WriterState{
stTextProperties = []
, stParaProperties = []
- , stFootnotes = []
+ , stFootnotes = defaultFootnotes
, stSectionIds = []
, stExternalLinks = M.empty
, stImages = M.empty
@@ -1073,6 +1073,22 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
br :: Element
br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
+-- Word will insert these footnotes into the settings.xml file
+-- (whether or not they're visible in the document). If they're in the
+-- file, but not in the footnotes.xml file, it will produce
+-- problems. So we want to make sure we insert them into our document.
+defaultFootnotes :: [Element]
+defaultFootnotes = [ mknode "w:footnote"
+ [("w:type", "separator"), ("w:id", "-1")] $
+ [ mknode "w:p" [] $
+ [mknode "w:r" [] $
+ [ mknode "w:separator" [] ()]]]
+ , mknode "w:footnote"
+ [("w:type", "continuationSeparator"), ("w:id", "0")] $
+ [ mknode "w:p" [] $
+ [ mknode "w:r" [] $
+ [ mknode "w:continuationSeparator" [] ()]]]]
+
parseXml :: Archive -> Archive -> String -> IO Element
parseXml refArchive distArchive relpath =
case ((findEntryByPath relpath refArchive `mplus`