diff options
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/Powerpoint.hs | 101 |
1 files changed, 30 insertions, 71 deletions
diff --git a/src/Text/Pandoc/Writers/Powerpoint.hs b/src/Text/Pandoc/Writers/Powerpoint.hs index 7fa327668..2a46e40fe 100644 --- a/src/Text/Pandoc/Writers/Powerpoint.hs +++ b/src/Text/Pandoc/Writers/Powerpoint.hs @@ -784,22 +784,6 @@ copyFileToArchive arch fp = do Nothing -> fail $ fp ++ " missing in reference file" Just e -> return $ addEntryToArchive e arch --- getMediaFiles :: PandocMonad m => P m [FilePath] --- getMediaFiles = do --- refArchive <- asks envRefArchive --- distArchive <- asks envDistArchive --- let allEntries = nub $ filesInArchive refArchive ++ filesInArchive distArchive --- return $ filter (isPrefixOf "ppt/media") allEntries - - --- copyFileToArchiveIfExists :: PandocMonad m => Archive -> FilePath -> P m Archive --- copyFileToArchiveIfExists arch fp = do --- refArchive <- asks envRefArchive --- distArchive <- asks envDistArchive --- case findEntryByPath fp refArchive `mplus` findEntryByPath fp distArchive of --- Nothing -> return $ arch --- Just e -> return $ addEntryToArchive e arch - inheritedPatterns :: [Pattern] inheritedPatterns = map compile [ "_rels/.rels" , "docProps/app.xml" @@ -827,68 +811,43 @@ patternToFilePaths pat = do patternsToFilePaths :: PandocMonad m => [Pattern] -> P m [FilePath] patternsToFilePaths pats = concat <$> mapM patternToFilePaths pats --- requiredFiles :: [FilePath] --- requiredFiles = inheritedFiles - --- inheritedFiles :: [FilePath] --- inheritedFiles = [ "_rels/.rels" --- , "docProps/app.xml" --- , "docProps/core.xml" --- , "ppt/slideLayouts/slideLayout4.xml" --- , "ppt/slideLayouts/_rels/slideLayout9.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout2.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout10.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout1.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout3.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout5.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout7.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout8.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout11.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout4.xml.rels" --- , "ppt/slideLayouts/_rels/slideLayout6.xml.rels" --- , "ppt/slideLayouts/slideLayout2.xml" --- , "ppt/slideLayouts/slideLayout8.xml" --- , "ppt/slideLayouts/slideLayout11.xml" --- , "ppt/slideLayouts/slideLayout3.xml" --- , "ppt/slideLayouts/slideLayout6.xml" --- , "ppt/slideLayouts/slideLayout9.xml" --- , "ppt/slideLayouts/slideLayout5.xml" --- , "ppt/slideLayouts/slideLayout7.xml" --- , "ppt/slideLayouts/slideLayout1.xml" --- , "ppt/slideLayouts/slideLayout10.xml" --- -- , "ppt/_rels/presentation.xml.rels" --- , "ppt/theme/theme1.xml" --- , "ppt/presProps.xml" --- -- , "ppt/slides/_rels/slide1.xml.rels" --- -- , "ppt/slides/_rels/slide2.xml.rels" --- -- This is the one we're --- -- going to build --- -- , "ppt/slides/slide2.xml" --- -- , "ppt/slides/slide1.xml" --- , "ppt/viewProps.xml" --- , "ppt/tableStyles.xml" --- , "ppt/slideMasters/_rels/slideMaster1.xml.rels" --- , "ppt/slideMasters/slideMaster1.xml" --- -- , "ppt/presentation.xml" --- -- , "[Content_Types].xml" --- ] - --- -- Here are some that might not be there. We won't fail if they're not --- possibleInheritedFiles :: [FilePath] --- possibleInheritedFiles = [ "ppt/theme/_rels/theme1.xml.rels" ] +-- Here are the files we'll require to make a Powerpoint document. If +-- any of these are missing, we should error out of our build. +requiredFiles :: [FilePath] +requiredFiles = [ "_rels/.rels" + , "docProps/app.xml" + , "docProps/core.xml" + , "ppt/presProps.xml" + , "ppt/slideLayouts/slideLayout1.xml" + , "ppt/slideLayouts/_rels/slideLayout1.xml.rels" + , "ppt/slideLayouts/slideLayout2.xml" + , "ppt/slideLayouts/_rels/slideLayout2.xml.rels" + , "ppt/slideLayouts/slideLayout3.xml" + , "ppt/slideLayouts/_rels/slideLayout3.xml.rels" + , "ppt/slideLayouts/slideLayout4.xml" + , "ppt/slideLayouts/_rels/slideLayout4.xml.rels" + , "ppt/slideMasters/slideMaster1.xml" + , "ppt/slideMasters/_rels/slideMaster1.xml.rels" + , "ppt/theme/theme1.xml" + , "ppt/viewProps.xml" + , "ppt/tableStyles.xml" + ] presentationToArchive :: PandocMonad m => Presentation -> P m Archive presentationToArchive p@(Presentation _ slides) = do filePaths <- patternsToFilePaths inheritedPatterns - newArch' <- foldM copyFileToArchive emptyArchive filePaths - -- set the template media to the relevant fps: + -- make sure all required files are available: + let missingFiles = filter (\fp -> not (fp `elem` filePaths)) requiredFiles + unless (null missingFiles) + (throwError $ + PandocSomeError $ + "The following required files are missing:\n" ++ + (unlines $ map (" " ++) missingFiles) + ) - -- we register any media fp in the filepaths - -- mediaDir <- getMediaFiles - -- newArch' <- foldM copyFileToArchiveIfExists newArch $ - -- possibleInheritedFiles ++ mediaDir + newArch' <- foldM copyFileToArchive emptyArchive filePaths -- presentation entry and rels. We have to do the rels first to make -- sure we know the correct offset for the rIds. presEntry <- presentationToPresEntry p |