git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Fall back on distribution reference.docx.

* Undid changes to parseXml in last commit. * Instead of a string fallback, we have parseXml fall back on the reference.docx that comes with pandoc if the user's reference.docx does not contain a needed file. * Closes #1185.

commit0c7e084342b2a077f83809e6613979adcefb1592 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 4 May 2014, 10:54 (12 years ago) parentd728715
1 file changed+15−14
src/Text/Pandoc/Writers/Docx.hs+15−14
src/Text/Pandoc/Writers/Docx.hs+15−14
@@ -116,6 +116,7 @@ writeDocx opts doc@(Pandoc meta _) = do
116116 case writerReferenceDocx opts of
117117 Just f -> B.readFile f
118118 Nothing -> readDataFile datadir "reference.docx"
119+ distArchive <- liftM (toArchive . toLazy) $ readDataFile Nothing "reference.docx"
119120
120121 ((contents, footnotes), st) <- runStateT (writeOpenXML opts{writerWrapText = False} doc')
121122 defaultWriterState
@@ -217,7 +218,7 @@ writeDocx opts doc@(Pandoc meta _) = do
217218 -- styles
218219 let newstyles = styleToOpenXml $ writerHighlightStyle opts
219220 let stylepath = "word/styles.xml"
220− styledoc <- parseXml refArchive stylepath Nothing
221+ styledoc <- parseXml refArchive distArchive stylepath
221222 let styledoc' = styledoc{ elContent = elContent styledoc ++
222223 [Elem x | x <- newstyles, writerHighlight opts] }
223224 let styleEntry = toEntry stylepath epochtime $ renderXml styledoc'
@@ -256,20 +257,20 @@ writeDocx opts doc@(Pandoc meta _) = do
256257 ]
257258 let relsEntry = toEntry relsPath epochtime $ renderXml rels
258259
259− let entryFromArchive path fallback =
260+ let entryFromArchive path =
260261 (toEntry path epochtime . renderXml) `fmap`
261− parseXml refArchive path fallback
262− docPropsAppEntry <- entryFromArchive "docProps/app.xml" Nothing
263− themeEntry <- entryFromArchive "word/theme/theme1.xml" Nothing
264− fontTableEntry <- entryFromArchive "word/fontTable.xml" Nothing
265− settingsEntry <- entryFromArchive "word/settings.xml" Nothing
266− webSettingsEntry <- entryFromArchive "word/webSettings.xml" Nothing
262+ parseXml refArchive distArchive path
263+ docPropsAppEntry <- entryFromArchive "docProps/app.xml"
264+ themeEntry <- entryFromArchive "word/theme/theme1.xml"
265+ fontTableEntry <- entryFromArchive "word/fontTable.xml"
266+ settingsEntry <- entryFromArchive "word/settings.xml"
267+ webSettingsEntry <- entryFromArchive "word/webSettings.xml"
267268 let miscRels = [ f | f <- filesInArchive refArchive
268269 , "word/_rels/" `isPrefixOf` f
269270 , ".xml.rels" `isSuffixOf` f
270271 , f /= "word/_rels/document.xml.rels"
271272 , f /= "word/_rels/footnotes.xml.rels" ]
272− miscRelEntries <- mapM (\f -> entryFromArchive f Nothing) miscRels
273+ miscRelEntries <- mapM entryFromArchive miscRels
273274
274275 -- Create archive
275276 let archive = foldr addEntryToArchive emptyArchive $
@@ -815,10 +816,10 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
815816br :: Element
816817br = mknode "w:r" [] [mknode "w:br" [("w:type","textWrapping")] () ]
817818
818−parseXml :: Archive -> String -> Maybe String -> IO Element
819−parseXml refArchive relpath fallback =
820− case (findEntryByPath relpath refArchive
821− >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) `mplus`
822− (fallback >>= parseXMLDoc) of
819+parseXml :: Archive -> Archive -> String -> IO Element
820+parseXml refArchive distArchive relpath =
821+ case ((findEntryByPath relpath refArchive `mplus`
822+ findEntryByPath relpath distArchive)
823+ >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
823824 Just d -> return d
824825 Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"