git.iko.soy/typeable/pandoc
on master help sign in
Removed need for TH in ODT module.
9551e36fiddlosopher
src/Text/Pandoc/ODT.hs+5−3
@@ -1,4 +1,3 @@
1−{-# LANGUAGE TemplateHaskell #-}
2{-
1{-
3Copyright (C) 2008 John MacFarlane <jgm@berkeley.edu>
2Copyright (C) 2008 John MacFarlane <jgm@berkeley.edu>
4
3
@@ -29,7 +28,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29Functions for producing an ODT file from OpenDocument XML.
28Functions for producing an ODT file from OpenDocument XML.
30-}
29-}
31module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
30module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
32−import Text.Pandoc.TH ( makeZip )
33import Data.List ( find )
31import Data.List ( find )
34import System.FilePath ( (</>), takeFileName )
32import System.FilePath ( (</>), takeFileName )
35import qualified Data.ByteString.Lazy as B
33import qualified Data.ByteString.Lazy as B
@@ -39,6 +37,8 @@ import Codec.Archive.Zip
39import Control.Applicative ( (<$>) )
37import Control.Applicative ( (<$>) )
40import Text.ParserCombinators.Parsec
38import Text.ParserCombinators.Parsec
41import System.Time
39import System.Time
40+import Text.Pandoc.Shared ( inDirectory )
41+import Paths_pandoc ( getDataFileName )
42
42
43-- | Produce an ODT file from OpenDocument XML.
43-- | Produce an ODT file from OpenDocument XML.
44saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
44saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
@@ -46,7 +46,9 @@ saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
46 -> String -- ^ OpenDocument XML contents.
46 -> String -- ^ OpenDocument XML contents.
47 -> IO ()
47 -> IO ()
48saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
48saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
49− let refArchive = read $(makeZip $ "data" </> "odt-styles")
49+ refArchivePath <- getDataFileName $ "data" </> "odt-styles"
50+ refArchive <- inDirectory refArchivePath $
51+ addFilesToArchive [OptRecursive] emptyArchive ["."]
50 -- handle pictures
52 -- handle pictures
51 let (newContents, pics) =
53 let (newContents, pics) =
52 case runParser pPictures [] "OpenDocument XML contents" xml of
54 case runParser pPictures [] "OpenDocument XML contents" xml of
src/Text/Pandoc/TH.hs+1−13
@@ -30,8 +30,7 @@ Template haskell functions used by Pandoc modules.
30-}
30-}
31module Text.Pandoc.TH (
31module Text.Pandoc.TH (
32 contentsOf,
32 contentsOf,
33− binaryContentsOf,
33+ binaryContentsOf
34− makeZip
35 ) where
34 ) where
36
35
37import Language.Haskell.TH
36import Language.Haskell.TH
@@ -40,8 +39,6 @@ import qualified Data.ByteString as B
40import Data.ByteString.Internal ( w2c )
39import Data.ByteString.Internal ( w2c )
41import Prelude hiding ( readFile )
40import Prelude hiding ( readFile )
42import System.IO.UTF8
41import System.IO.UTF8
43−import Codec.Archive.Zip
44−import Text.Pandoc.Shared ( inDirectory )
45
42
46-- | Insert contents of text file into a template.
43-- | Insert contents of text file into a template.
47contentsOf :: FilePath -> ExpQ
44contentsOf :: FilePath -> ExpQ
@@ -54,12 +51,3 @@ binaryContentsOf p = lift =<< (runIO $ B.readFile p)
54
51
55instance Lift B.ByteString where
52instance Lift B.ByteString where
56 lift x = return (LitE (StringL $ map w2c $ B.unpack x))
53 lift x = return (LitE (StringL $ map w2c $ B.unpack x))
57−
58−instance Lift Archive where
59− lift x = return (LitE (StringL $ show x ))
60−
61−-- | Construct zip file from files in a directory, and
62−-- insert into a template.
63−makeZip :: FilePath -> ExpQ
64−makeZip path = lift =<< (runIO $ inDirectory path $ addFilesToArchive [OptRecursive] emptyArchive ["."])
65−