git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Take over document formatting from reference.docx.

This includes margins, page size, page orientation.

commit23a9b800a35d3c17d29a278b6bb218f05642d282 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 31 May 2014, 22:02 (12 years ago) parent072411e
1 file changed+30−17
src/Text/Pandoc/Writers/Docx.hs+30−17
src/Text/Pandoc/Writers/Docx.hs+30−17
@@ -204,11 +204,35 @@ writeDocx opts doc@(Pandoc meta _) = do
204204 let toImageEntry (_,path,_,_,img) = toEntry ("word/" ++ path) epochtime $ toLazy img
205205 let imageEntries = map toImageEntry imgs
206206
207+ -- adjust contents to add sectPr from reference.docx
208+ let docpath = "word/document.xml"
209+ parsedDoc <- parseXml refArchive distArchive docpath
210+ let sectprs = filterElementsName (\qn -> qPrefix qn == Just "w" &&
211+ qName qn == "sectPr")
212+ parsedDoc
213+
214+ let stdAttributes =
215+ [("xmlns:w","http://schemas.openxmlformats.org/wordprocessingml/2006/main")
216+ ,("xmlns:m","http://schemas.openxmlformats.org/officeDocument/2006/math")
217+ ,("xmlns:r","http://schemas.openxmlformats.org/officeDocument/2006/relationships")
218+ ,("xmlns:o","urn:schemas-microsoft-com:office:office")
219+ ,("xmlns:v","urn:schemas-microsoft-com:vml")
220+ ,("xmlns:w10","urn:schemas-microsoft-com:office:word")
221+ ,("xmlns:a","http://schemas.openxmlformats.org/drawingml/2006/main")
222+ ,("xmlns:pic","http://schemas.openxmlformats.org/drawingml/2006/picture")
223+ ,("xmlns:wp","http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing")]
224+
225+ let contents' = contents ++ sectprs
226+ let docContents = mknode "w:document" stdAttributes
227+ $ mknode "w:body" [] $ contents'
228+
207229 -- word/document.xml
208− let contentEntry = toEntry "word/document.xml" epochtime $ renderXml contents
230+ let contentEntry = toEntry "word/document.xml" epochtime
231+ $ renderXml docContents
209232
210233 -- footnotes
211− let footnotesEntry = toEntry "word/footnotes.xml" epochtime $ renderXml footnotes
234+ let notes = mknode "w:footnotes" stdAttributes footnotes
235+ let footnotesEntry = toEntry "word/footnotes.xml" epochtime $ renderXml notes
212236
213237 -- footnote rels
214238 let footnoteRelEntry = toEntry "word/_rels/footnotes.xml.rels" epochtime
@@ -392,8 +416,9 @@ mkLvl marker lvl =
392416getNumId :: WS Int
393417getNumId = length `fmap` gets stLists
394418
395−-- | Convert Pandoc document to two OpenXML elements (the main document and footnotes).
396−writeOpenXML :: WriterOptions -> Pandoc -> WS (Element, Element)
419+-- | Convert Pandoc document to two lists of
420+-- OpenXML elements (the main document and footnotes).
421+writeOpenXML :: WriterOptions -> Pandoc -> WS ([Element], [Element])
397422writeOpenXML opts (Pandoc meta blocks) = do
398423 let tit = docTitle meta ++ case lookupMeta "subtitle" meta of
399424 Just (MetaBlocks [Plain xs]) -> LineBreak : xs
@@ -411,19 +436,7 @@ writeOpenXML opts (Pandoc meta blocks) = do
411436 doc' <- blocksToOpenXML opts blocks'
412437 notes' <- reverse `fmap` gets stFootnotes
413438 let meta' = title ++ authors ++ date
414− let stdAttributes =
415− [("xmlns:w","http://schemas.openxmlformats.org/wordprocessingml/2006/main")
416− ,("xmlns:m","http://schemas.openxmlformats.org/officeDocument/2006/math")
417− ,("xmlns:r","http://schemas.openxmlformats.org/officeDocument/2006/relationships")
418− ,("xmlns:o","urn:schemas-microsoft-com:office:office")
419− ,("xmlns:v","urn:schemas-microsoft-com:vml")
420− ,("xmlns:w10","urn:schemas-microsoft-com:office:word")
421− ,("xmlns:a","http://schemas.openxmlformats.org/drawingml/2006/main")
422− ,("xmlns:pic","http://schemas.openxmlformats.org/drawingml/2006/picture")
423− ,("xmlns:wp","http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing")]
424− let doc = mknode "w:document" stdAttributes $ mknode "w:body" [] (meta' ++ doc')
425− let notes = mknode "w:footnotes" stdAttributes notes'
426− return (doc, notes)
439+ return (meta' ++ doc', notes')
427440
428441-- | Convert a list of Pandoc blocks to OpenXML.
429442blocksToOpenXML :: WriterOptions -> [Block] -> WS [Element]