git.iko.soy/typeable/pandoc
on master help sign in
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.

commitba59e5447ffe8d15dd7fee69a7aa03706ce3c49b authorJesse Rosenthal <jrosenthal@jhu.edu> dateThu 12 Feb 2015, 08:52 (12 years ago) parentc2f32f4
2 files changed+17−1
data/reference.docx src/Text/Pandoc/Writers/Docx.hs+17−1
data/reference.docx

Binary file not shown.

src/Text/Pandoc/Writers/Docx.hs+17−1
@@ -114,7 +114,7 @@ defaultWriterState :: WriterState
114114defaultWriterState = WriterState{
115115 stTextProperties = []
116116 , stParaProperties = []
117− , stFootnotes = []
117+ , stFootnotes = defaultFootnotes
118118 , stSectionIds = []
119119 , stExternalLinks = M.empty
120120 , stImages = M.empty
@@ -1073,6 +1073,22 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
10731073br :: Element
10741074br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
10751075
1076+-- Word will insert these footnotes into the settings.xml file
1077+-- (whether or not they're visible in the document). If they're in the
1078+-- file, but not in the footnotes.xml file, it will produce
1079+-- problems. So we want to make sure we insert them into our document.
1080+defaultFootnotes :: [Element]
1081+defaultFootnotes = [ mknode "w:footnote"
1082+ [("w:type", "separator"), ("w:id", "-1")] $
1083+ [ mknode "w:p" [] $
1084+ [mknode "w:r" [] $
1085+ [ mknode "w:separator" [] ()]]]
1086+ , mknode "w:footnote"
1087+ [("w:type", "continuationSeparator"), ("w:id", "0")] $
1088+ [ mknode "w:p" [] $
1089+ [ mknode "w:r" [] $
1090+ [ mknode "w:continuationSeparator" [] ()]]]]
1091+
10761092parseXml :: Archive -> Archive -> String -> IO Element
10771093parseXml refArchive distArchive relpath =
10781094 case ((findEntryByPath relpath refArchive `mplus`