git.iko.soy/typeable/pandoc
on master help sign in
Better fix for #2187.

* Reverted kludgy change to make-windows-installer.bat. * Removed make-reference-fiels.hs. * Moved the individual ingredients of reference.docx and reference.odt to the data directory. * Removed reference.docx and reference.odt from data directory. * We now build the reference archives from their ingredient pieces in the docx and odt writers, instead of having a reference.docx or reference.odt intermediary. This should fix #2187. It also simplifies the bulid procedure. The one thing users may notice is different is that you can no longer get the reference.docx or reference.odt using `--print-default-data-file`. Instead, simply generate a docx or odt using pandoc with a blank or minimal input, and use that (or a customized version) with `--reference-docx` or `--reference-odt`.

commitb241472a90e8cdb3146acfbe555f50abd4b3b302 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 28 May 2015, 18:15 (11 years ago) parentc1f6d5e
5 files changed+78−65
Setup.hs+2−13 pandoc.cabal+19−33 src/Text/Pandoc/Writers/Docx.hs+36−11 src/Text/Pandoc/Writers/ODT.hs+21−4 windows/make-windows-installer.bat−4
Setup.hs+2−13
@@ -38,12 +38,11 @@ main = defaultMainWithHooks $ simpleUserHooks {
3838 , instHook = \pkgdescr ->
3939 instHook simpleUserHooks pkgdescr{ executables =
4040 [x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
41− , postBuild = \args bf pkgdescr lbi -> do
41+ , postBuild = \args bf pkgdescr lbi ->
4242 makeManPages args bf pkgdescr lbi
43− makeReferenceFiles args bf pkgdescr lbi
4443 }
4544 where
46− noInstall = ["make-pandoc-man-pages","make-reference-files"]
45+ noInstall = ["make-pandoc-man-pages"]
4746
4847ppBlobSuffixHandler :: PPSuffixHandler
4948ppBlobSuffixHandler = ("hsb", \_ _ ->
@@ -64,13 +63,3 @@ makeManPages _ bf _ LocalBuildInfo{buildDir=buildDir}
6463 where
6564 verbosity = fromFlagOrDefault normal $ buildVerbosity bf
6665 progPath = buildDir </> "make-pandoc-man-pages" </> "make-pandoc-man-pages"
67−
68−makeReferenceFiles :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
69−makeReferenceFiles _ bf _ LocalBuildInfo{buildDir=buildDir}
70− = mapM_
71− (rawSystemExit verbosity progPath . return)
72− referenceFormats
73− where
74− verbosity = fromFlagOrDefault normal $ buildVerbosity bf
75− progPath = buildDir </> "make-reference-files" </> "make-reference-files"
76− referenceFormats = ["docx", "odt"]
pandoc.cabal+19−33
@@ -69,28 +69,6 @@ Data-Files:
6969 data/templates/default.org
7070 data/templates/default.epub
7171 data/templates/default.epub3
72− -- data for ODT writer
73− data/reference.odt
74− -- data for docx writer
75− data/reference.docx
76− -- stylesheet for EPUB writer
77− data/epub.css
78− -- data for LaTeXMathML writer
79− data/LaTeXMathML.js
80− data/MathMLinHTML.js
81− -- data for dzslides writer
82− data/dzslides/template.html
83− -- sample lua custom writer
84− data/sample.lua
85− -- documentation
86− README, COPYRIGHT
87−Extra-Source-Files:
88− -- documentation
89− INSTALL, BUGS, CONTRIBUTING.md, changelog
90− -- code to create pandoc.1 man page
91− Makefile
92− man/man1/pandoc.1.template
93− man/man5/pandoc_markdown.5.template
9472 -- source files for reference.docx
9573 data/docx/[Content_Types].xml
9674 data/docx/_rels/.rels
@@ -116,7 +94,25 @@ Extra-Source-Files:
11694 data/odt/Configurations2/accelerator/current.xml
11795 data/odt/Thumbnails/thumbnail.png
11896 data/odt/META-INF/manifest.xml
119− -- trypandoc
97+ -- stylesheet for EPUB writer
98+ data/epub.css
99+ -- data for LaTeXMathML writer
100+ data/LaTeXMathML.js
101+ data/MathMLinHTML.js
102+ -- data for dzslides writer
103+ data/dzslides/template.html
104+ -- sample lua custom writer
105+ data/sample.lua
106+ -- documentation
107+ README, COPYRIGHT
108+Extra-Source-Files:
109+ -- documentation
110+ INSTALL, BUGS, CONTRIBUTING.md, changelog
111+ -- code to create pandoc.1 man page
112+ Makefile
113+ man/man1/pandoc.1.template
114+ man/man5/pandoc_markdown.5.template
115+ -- trypandoc
120116 trypandoc/Makefile
121117 trypandoc/index.html
122118 -- tests
@@ -439,16 +435,6 @@ Executable make-pandoc-man-pages
439435 Default-Language: Haskell98
440436 Buildable: True
441437
442−Executable make-reference-files
443− Main-Is: make-reference-files.hs
444− Hs-Source-Dirs: data
445− Build-Depends: zip-archive >= 0.2.3.4 && < 0.3,
446− base >= 4.2 && < 5,
447− filepath >= 1.1 && < 1.5,
448− directory >= 1 && < 1.3,
449− bytestring >= 0.9 && < 0.11
450− Default-Language: Haskell2010
451−
452438Test-Suite test-pandoc
453439 Type: exitcode-stdio-1.0
454440 Main-Is: test-pandoc.hs
src/Text/Pandoc/Writers/Docx.hs+36−11
@@ -211,11 +211,10 @@ writeDocx opts doc@(Pandoc meta _) = do
211211 let doc' = stripInvalidChars . walk fixDisplayMath $ doc
212212 username <- lookup "USERNAME" <$> getEnvironment
213213 utctime <- getCurrentTime
214− refArchive <- liftM (toArchive . toLazy) $
215− case writerReferenceDocx opts of
216− Just f -> B.readFile f
217− Nothing -> readDataFile datadir "reference.docx"
218− distArchive <- liftM (toArchive . toLazy) $ readDataFile datadir "reference.docx"
214+ distArchive <- getDefaultReferenceDocx datadir
215+ refArchive <- case writerReferenceDocx opts of
216+ Just f -> liftM (toArchive . toLazy) $ B.readFile f
217+ Nothing -> return distArchive
219218
220219 parsedDoc <- parseXml refArchive distArchive "word/document.xml"
221220 let wname f qn = qPrefix qn == Just "w" && f (qName qn)
@@ -474,7 +473,7 @@ writeDocx opts doc@(Pandoc meta _) = do
474473 settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime settingsList
475474
476475 let entryFromArchive arch path =
477− maybe (fail $ path ++ " corrupt or missing in reference docx")
476+ maybe (fail $ path ++ " missing in reference docx")
478477 return
479478 (findEntryByPath path arch `mplus` findEntryByPath path distArchive)
480479 docPropsAppEntry <- entryFromArchive refArchive "docProps/app.xml"
@@ -1204,11 +1203,12 @@ defaultFootnotes = [ mknode "w:footnote"
12041203
12051204parseXml :: Archive -> Archive -> String -> IO Element
12061205parseXml refArchive distArchive relpath =
1207− case ((findEntryByPath relpath refArchive `mplus`
1208− findEntryByPath relpath distArchive)
1209− >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
1210− Just d -> return d
1211− Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"
1206+ case findEntryByPath relpath refArchive `mplus`
1207+ findEntryByPath relpath distArchive of
1208+ Nothing -> fail $ relpath ++ " missing in reference docx"
1209+ Just e -> case parseXMLDoc . UTF8.toStringLazy . fromEntry $ e of
1210+ Nothing -> fail $ relpath ++ " corrupt in reference docx"
1211+ Just d -> return d
12121212
12131213-- | Scales the image to fit the page
12141214-- sizes are passed in emu
@@ -1219,3 +1219,28 @@ fitToPage (x, y) pageWidth
12191219 (pageWidth, round $
12201220 ((fromIntegral pageWidth) / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
12211221 | otherwise = (x, y)
1222+
1223+getDefaultReferenceDocx :: Maybe FilePath -> IO Archive
1224+getDefaultReferenceDocx datadir = do
1225+ let paths = ["[Content_Types].xml",
1226+ "_rels/.rels",
1227+ "docProps/app.xml",
1228+ "docProps/core.xml",
1229+ "word/document.xml",
1230+ "word/fontTable.xml",
1231+ "word/footnotes.xml",
1232+ "word/numbering.xml",
1233+ "word/settings.xml",
1234+ "word/webSettings.xml",
1235+ "word/styles.xml",
1236+ "word/_rels/document.xml.rels",
1237+ "word/_rels/footnotes.xml.rels",
1238+ "word/theme/theme1.xml"]
1239+ let pathToEntry path = do epochtime <- (floor . utcTimeToPOSIXSeconds) <$>
1240+ getCurrentTime
1241+ contents <- toLazy <$> readDataFile datadir
1242+ ("docx/" ++ path)
1243+ return $ toEntry path epochtime contents
1244+ entries <- mapM pathToEntry paths
1245+ let archive = foldr addEntryToArchive emptyArchive entries
1246+ return archive
src/Text/Pandoc/Writers/ODT.hs+21−4
@@ -60,11 +60,10 @@ writeODT :: WriterOptions -- ^ Writer options
6060writeODT opts doc@(Pandoc meta _) = do
6161 let datadir = writerUserDataDir opts
6262 let title = docTitle meta
63− refArchive <- liftM toArchive $
63+ refArchive <-
6464 case writerReferenceODT opts of
65− Just f -> B.readFile f
66− Nothing -> (B.fromChunks . (:[])) `fmap`
67− readDataFile datadir "reference.odt"
65+ Just f -> liftM toArchive $ B.readFile f
66+ Nothing -> getDefaultReferenceODT datadir
6867 -- handle formulas and pictures
6968 picEntriesRef <- newIORef ([] :: [Entry])
7069 doc' <- walkM (transformPicMath opts picEntriesRef) $ walk fixDisplayMath doc
@@ -178,3 +177,21 @@ transformPicMath _ entriesRef (Math t math) = do
178177 , ("xlink:actuate", "onLoad")]
179178
180179transformPicMath _ _ x = return x
180+
181+getDefaultReferenceODT :: Maybe FilePath -> IO Archive
182+getDefaultReferenceODT datadir = do
183+ let paths = ["mimetype",
184+ "manifest.rdf",
185+ "styles.xml",
186+ "content.xml",
187+ "meta.xml",
188+ "settings.xml",
189+ "Configurations2/accelerator/current.xml",
190+ "Thumbnails/thumbnail.png",
191+ "META-INF/manifest.xml"]
192+ let pathToEntry path = do epochtime <- floor `fmap` getPOSIXTime
193+ contents <- (B.fromChunks . (:[])) `fmap`
194+ readDataFile datadir ("odt/" ++ path)
195+ return $ toEntry path epochtime contents
196+ entries <- mapM pathToEntry paths
197+ return $ foldr addEntryToArchive emptyArchive entries
windows/make-windows-installer.bat−4
@@ -5,10 +5,6 @@ cabal sandbox init
55cabal clean
66cabal install hsb2hs
77if %errorlevel% neq 0 exit /b %errorlevel%
8−REM We do it once to regenrate data/reference.docx/odt
9−cabal install -v1 --force --reinstall
10−cabal clean
11−REM then again for real, because otherwise it won't work with embed_data_files:
128cabal install -v1 --force --reinstall --flags="embed_data_files" . pandoc-citeproc
139if %errorlevel% neq 0 exit /b %errorlevel%
1410strip .\.cabal-sandbox\bin\pandoc.exe