aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Setup.hs15
-rw-r--r--pandoc.cabal52
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs47
-rw-r--r--src/Text/Pandoc/Writers/ODT.hs25
-rw-r--r--windows/make-windows-installer.bat4
5 files changed, 78 insertions, 65 deletions
diff --git a/Setup.hs b/Setup.hs
index bba8e884c..fe1798763 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -38,12 +38,11 @@ main = defaultMainWithHooks $ simpleUserHooks {
, instHook = \pkgdescr ->
instHook simpleUserHooks pkgdescr{ executables =
[x | x <- executables pkgdescr, exeName x `notElem` noInstall] }
- , postBuild = \args bf pkgdescr lbi -> do
+ , postBuild = \args bf pkgdescr lbi ->
makeManPages args bf pkgdescr lbi
- makeReferenceFiles args bf pkgdescr lbi
}
where
- noInstall = ["make-pandoc-man-pages","make-reference-files"]
+ noInstall = ["make-pandoc-man-pages"]
ppBlobSuffixHandler :: PPSuffixHandler
ppBlobSuffixHandler = ("hsb", \_ _ ->
@@ -64,13 +63,3 @@ makeManPages _ bf _ LocalBuildInfo{buildDir=buildDir}
where
verbosity = fromFlagOrDefault normal $ buildVerbosity bf
progPath = buildDir </> "make-pandoc-man-pages" </> "make-pandoc-man-pages"
-
-makeReferenceFiles :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
-makeReferenceFiles _ bf _ LocalBuildInfo{buildDir=buildDir}
- = mapM_
- (rawSystemExit verbosity progPath . return)
- referenceFormats
- where
- verbosity = fromFlagOrDefault normal $ buildVerbosity bf
- progPath = buildDir </> "make-reference-files" </> "make-reference-files"
- referenceFormats = ["docx", "odt"]
diff --git a/pandoc.cabal b/pandoc.cabal
index 13c089ba4..e2a6396a5 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -69,28 +69,6 @@ Data-Files:
data/templates/default.org
data/templates/default.epub
data/templates/default.epub3
- -- data for ODT writer
- data/reference.odt
- -- data for docx writer
- data/reference.docx
- -- stylesheet for EPUB writer
- data/epub.css
- -- data for LaTeXMathML writer
- data/LaTeXMathML.js
- data/MathMLinHTML.js
- -- data for dzslides writer
- data/dzslides/template.html
- -- sample lua custom writer
- data/sample.lua
- -- documentation
- README, COPYRIGHT
-Extra-Source-Files:
- -- documentation
- INSTALL, BUGS, CONTRIBUTING.md, changelog
- -- code to create pandoc.1 man page
- Makefile
- man/man1/pandoc.1.template
- man/man5/pandoc_markdown.5.template
-- source files for reference.docx
data/docx/[Content_Types].xml
data/docx/_rels/.rels
@@ -116,7 +94,25 @@ Extra-Source-Files:
data/odt/Configurations2/accelerator/current.xml
data/odt/Thumbnails/thumbnail.png
data/odt/META-INF/manifest.xml
- -- trypandoc
+ -- stylesheet for EPUB writer
+ data/epub.css
+ -- data for LaTeXMathML writer
+ data/LaTeXMathML.js
+ data/MathMLinHTML.js
+ -- data for dzslides writer
+ data/dzslides/template.html
+ -- sample lua custom writer
+ data/sample.lua
+ -- documentation
+ README, COPYRIGHT
+Extra-Source-Files:
+ -- documentation
+ INSTALL, BUGS, CONTRIBUTING.md, changelog
+ -- code to create pandoc.1 man page
+ Makefile
+ man/man1/pandoc.1.template
+ man/man5/pandoc_markdown.5.template
+ -- trypandoc
trypandoc/Makefile
trypandoc/index.html
-- tests
@@ -439,16 +435,6 @@ Executable make-pandoc-man-pages
Default-Language: Haskell98
Buildable: True
-Executable make-reference-files
- Main-Is: make-reference-files.hs
- Hs-Source-Dirs: data
- Build-Depends: zip-archive >= 0.2.3.4 && < 0.3,
- base >= 4.2 && < 5,
- filepath >= 1.1 && < 1.5,
- directory >= 1 && < 1.3,
- bytestring >= 0.9 && < 0.11
- Default-Language: Haskell2010
-
Test-Suite test-pandoc
Type: exitcode-stdio-1.0
Main-Is: test-pandoc.hs
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 475f4e2ac..04368e730 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -211,11 +211,10 @@ writeDocx opts doc@(Pandoc meta _) = do
let doc' = stripInvalidChars . walk fixDisplayMath $ doc
username <- lookup "USERNAME" <$> getEnvironment
utctime <- getCurrentTime
- refArchive <- liftM (toArchive . toLazy) $
- case writerReferenceDocx opts of
- Just f -> B.readFile f
- Nothing -> readDataFile datadir "reference.docx"
- distArchive <- liftM (toArchive . toLazy) $ readDataFile datadir "reference.docx"
+ distArchive <- getDefaultReferenceDocx datadir
+ refArchive <- case writerReferenceDocx opts of
+ Just f -> liftM (toArchive . toLazy) $ B.readFile f
+ Nothing -> return distArchive
parsedDoc <- parseXml refArchive distArchive "word/document.xml"
let wname f qn = qPrefix qn == Just "w" && f (qName qn)
@@ -474,7 +473,7 @@ writeDocx opts doc@(Pandoc meta _) = do
settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime settingsList
let entryFromArchive arch path =
- maybe (fail $ path ++ " corrupt or missing in reference docx")
+ maybe (fail $ path ++ " missing in reference docx")
return
(findEntryByPath path arch `mplus` findEntryByPath path distArchive)
docPropsAppEntry <- entryFromArchive refArchive "docProps/app.xml"
@@ -1204,11 +1203,12 @@ defaultFootnotes = [ mknode "w:footnote"
parseXml :: Archive -> Archive -> String -> IO Element
parseXml refArchive distArchive relpath =
- case ((findEntryByPath relpath refArchive `mplus`
- findEntryByPath relpath distArchive)
- >>= parseXMLDoc . UTF8.toStringLazy . fromEntry) of
- Just d -> return d
- Nothing -> fail $ relpath ++ " corrupt or missing in reference docx"
+ case findEntryByPath relpath refArchive `mplus`
+ findEntryByPath relpath distArchive of
+ Nothing -> fail $ relpath ++ " missing in reference docx"
+ Just e -> case parseXMLDoc . UTF8.toStringLazy . fromEntry $ e of
+ Nothing -> fail $ relpath ++ " corrupt in reference docx"
+ Just d -> return d
-- | Scales the image to fit the page
-- sizes are passed in emu
@@ -1219,3 +1219,28 @@ fitToPage (x, y) pageWidth
(pageWidth, round $
((fromIntegral pageWidth) / ((fromIntegral :: Integer -> Double) x)) * (fromIntegral y))
| otherwise = (x, y)
+
+getDefaultReferenceDocx :: Maybe FilePath -> IO Archive
+getDefaultReferenceDocx datadir = do
+ let paths = ["[Content_Types].xml",
+ "_rels/.rels",
+ "docProps/app.xml",
+ "docProps/core.xml",
+ "word/document.xml",
+ "word/fontTable.xml",
+ "word/footnotes.xml",
+ "word/numbering.xml",
+ "word/settings.xml",
+ "word/webSettings.xml",
+ "word/styles.xml",
+ "word/_rels/document.xml.rels",
+ "word/_rels/footnotes.xml.rels",
+ "word/theme/theme1.xml"]
+ let pathToEntry path = do epochtime <- (floor . utcTimeToPOSIXSeconds) <$>
+ getCurrentTime
+ contents <- toLazy <$> readDataFile datadir
+ ("docx/" ++ path)
+ return $ toEntry path epochtime contents
+ entries <- mapM pathToEntry paths
+ let archive = foldr addEntryToArchive emptyArchive entries
+ return archive
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
index e7c1cf32e..51e06cea8 100644
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -60,11 +60,10 @@ writeODT :: WriterOptions -- ^ Writer options
writeODT opts doc@(Pandoc meta _) = do
let datadir = writerUserDataDir opts
let title = docTitle meta
- refArchive <- liftM toArchive $
+ refArchive <-
case writerReferenceODT opts of
- Just f -> B.readFile f
- Nothing -> (B.fromChunks . (:[])) `fmap`
- readDataFile datadir "reference.odt"
+ Just f -> liftM toArchive $ B.readFile f
+ Nothing -> getDefaultReferenceODT datadir
-- handle formulas and pictures
picEntriesRef <- newIORef ([] :: [Entry])
doc' <- walkM (transformPicMath opts picEntriesRef) $ walk fixDisplayMath doc
@@ -178,3 +177,21 @@ transformPicMath _ entriesRef (Math t math) = do
, ("xlink:actuate", "onLoad")]
transformPicMath _ _ x = return x
+
+getDefaultReferenceODT :: Maybe FilePath -> IO Archive
+getDefaultReferenceODT datadir = do
+ let paths = ["mimetype",
+ "manifest.rdf",
+ "styles.xml",
+ "content.xml",
+ "meta.xml",
+ "settings.xml",
+ "Configurations2/accelerator/current.xml",
+ "Thumbnails/thumbnail.png",
+ "META-INF/manifest.xml"]
+ let pathToEntry path = do epochtime <- floor `fmap` getPOSIXTime
+ contents <- (B.fromChunks . (:[])) `fmap`
+ readDataFile datadir ("odt/" ++ path)
+ return $ toEntry path epochtime contents
+ entries <- mapM pathToEntry paths
+ return $ foldr addEntryToArchive emptyArchive entries
diff --git a/windows/make-windows-installer.bat b/windows/make-windows-installer.bat
index 5b0e7f567..d4816fa69 100644
--- a/windows/make-windows-installer.bat
+++ b/windows/make-windows-installer.bat
@@ -5,10 +5,6 @@ cabal sandbox init
cabal clean
cabal install hsb2hs
if %errorlevel% neq 0 exit /b %errorlevel%
-REM We do it once to regenrate data/reference.docx/odt
-cabal install -v1 --force --reinstall
-cabal clean
-REM then again for real, because otherwise it won't work with embed_data_files:
cabal install -v1 --force --reinstall --flags="embed_data_files" . pandoc-citeproc
if %errorlevel% neq 0 exit /b %errorlevel%
strip .\.cabal-sandbox\bin\pandoc.exe