git.iko.soy/typeable/pandoc
on master help sign in
Improved template handling:
1e2f2bcfiddlosopher
Text/Pandoc/ASCIIMathML.hs+1−1
@@ -2,7 +2,7 @@
2-- | Definitions for use of ASCIIMathML in HTML.
2-- | Definitions for use of ASCIIMathML in HTML.
3-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
3-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
4module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
4module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
5−import Text.Pandoc.Shared ( contentsOf )
5+import Text.Pandoc.TH ( contentsOf )
6import System.FilePath ( (</>) )
6import System.FilePath ( (</>) )
7
7
8-- | String containing ASCIIMathML javascript.
8-- | String containing ASCIIMathML javascript.
Text/Pandoc/DefaultHeaders.hs+1−1
@@ -38,7 +38,7 @@ module Text.Pandoc.DefaultHeaders (
38 ) where
38 ) where
39import Text.Pandoc.Writers.S5
39import Text.Pandoc.Writers.S5
40import System.FilePath ( (</>) )
40import System.FilePath ( (</>) )
41−import Text.Pandoc.Shared ( contentsOf )
41+import Text.Pandoc.TH ( contentsOf )
42
42
43defaultLaTeXHeader :: String
43defaultLaTeXHeader :: String
44#ifndef __HADDOCK__
44#ifndef __HADDOCK__
Text/Pandoc/ODT.hs+2−2
@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29Functions for producing an ODT file from OpenDocument XML.
29Functions for producing an ODT file from OpenDocument XML.
30-}
30-}
31module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
31module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
32−import Text.Pandoc.Shared ( contentsOf )
32+import Text.Pandoc.TH ( binaryContentsOf )
33import Data.Maybe ( fromJust, isJust )
33import Data.Maybe ( fromJust, isJust )
34import Data.List ( partition, intersperse )
34import Data.List ( partition, intersperse )
35import Prelude hiding ( writeFile, readFile )
35import Prelude hiding ( writeFile, readFile )
@@ -61,7 +61,7 @@ saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
61 "Windows: See http://gnuwin32.sourceforge.net/packages/zip.htm"
61 "Windows: See http://gnuwin32.sourceforge.net/packages/zip.htm"
62 withTempDir "pandoc-odt" $ \tempDir -> do
62 withTempDir "pandoc-odt" $ \tempDir -> do
63 let tempODT = tempDir </> "reference.odt"
63 let tempODT = tempDir </> "reference.odt"
64− B.writeFile tempODT $ B.pack $(contentsOf $ "odt-styles" </> "reference.odt")
64+ B.writeFile tempODT $ B.pack $(binaryContentsOf $ "odt-styles" </> "reference.odt")
65 createDirectory $ tempDir </> "Pictures"
65 createDirectory $ tempDir </> "Pictures"
66 xml' <- handlePictures tempODT sourceDirRelative xml
66 xml' <- handlePictures tempODT sourceDirRelative xml
67 writeFile (tempDir </> "content.xml") xml'
67 writeFile (tempDir </> "content.xml") xml'
Text/Pandoc/Shared.hs+5−15
@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-
1{-
3Copyright (C) 2006-8 John MacFarlane <jgm@berkeley.edu>
2Copyright (C) 2006-8 John MacFarlane <jgm@berkeley.edu>
4
3
@@ -101,9 +100,7 @@ module Text.Pandoc.Shared (
101 WriterOptions (..),
100 WriterOptions (..),
102 defaultWriterOptions,
101 defaultWriterOptions,
103 -- * File handling
102 -- * File handling
104− withTempDir,
103+ withTempDir
105− -- * Template haskell
106− contentsOf
107 ) where
104 ) where
108
105
109import Text.Pandoc.Definition
106import Text.Pandoc.Definition
@@ -118,9 +115,6 @@ import Network.URI ( parseURI, URI (..), isAllowedInURI )
118import System.FilePath ( (</>), (<.>) )
115import System.FilePath ( (</>), (<.>) )
119import System.IO.Error ( catch, ioError, isAlreadyExistsError )
116import System.IO.Error ( catch, ioError, isAlreadyExistsError )
120import System.Directory
117import System.Directory
121−import Language.Haskell.TH
122−import Language.Haskell.TH.Syntax (Lift (..))
123−import qualified Data.ByteString.Char8 as B
124
118
125--
119--
126-- List processing
120-- List processing
@@ -912,6 +906,10 @@ defaultWriterOptions =
912 , writerWrapText = True
906 , writerWrapText = True
913 }
907 }
914
908
909+--
910+-- File handling
911+--
912+
915-- | Perform a function in a temporary directory and clean up.
913-- | Perform a function in a temporary directory and clean up.
916withTempDir :: FilePath -> (FilePath -> IO a) -> IO a
914withTempDir :: FilePath -> (FilePath -> IO a) -> IO a
917withTempDir baseName func = do
915withTempDir baseName func = do
@@ -929,11 +927,3 @@ createTempDir num baseName = do
929 \e -> if isAlreadyExistsError e
927 \e -> if isAlreadyExistsError e
930 then createTempDir (num + 1) baseName
928 then createTempDir (num + 1) baseName
931 else ioError e
929 else ioError e
932−
933−-- | Template haskell function to insert bytestring contents of file into a template.
934−contentsOf :: FilePath -> ExpQ
935−contentsOf p = lift =<< runIO (B.readFile p)
936−
937−instance Lift B.ByteString where
938− lift x = return (LitE (StringL $ B.unpack x))
939−
Text/Pandoc/TH.hsnew file+51
@@ -0,0 +1,51 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+{-
3+Copyright (C) 2008 John MacFarlane <jgm@berkeley.edu>
4+
5+This program is free software; you can redistribute it and/or modify
6+it under the terms of the GNU General Public License as published by
7+the Free Software Foundation; either version 2 of the License, or
8+(at your option) any later version.
9+
10+This program is distributed in the hope that it will be useful,
11+but WITHOUT ANY WARRANTY; without even the implied warranty of
12+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+GNU General Public License for more details.
14+
15+You should have received a copy of the GNU General Public License
16+along with this program; if not, write to the Free Software
17+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+-}
19+
20+{- |
21+ Module : Text.Pandoc.TH
22+ Copyright : Copyright (C) 2006-8 John MacFarlane
23+ License : GNU GPL, version 2 or above
24+
25+ Maintainer : John MacFarlane <jgm@berkeley.edu>
26+ Stability : alpha
27+ Portability : portable
28+
29+Template haskell functions used by Pandoc modules.
30+-}
31+module Text.Pandoc.TH (
32+ contentsOf,
33+ binaryContentsOf
34+ ) where
35+
36+import Language.Haskell.TH
37+import Language.Haskell.TH.Syntax (Lift (..))
38+import qualified Data.ByteString as B
39+import Data.ByteString.Internal ( w2c )
40+
41+-- | Insert contents of text file into a template.
42+contentsOf :: FilePath -> ExpQ
43+contentsOf p = lift =<< (runIO $ readFile p)
44+
45+-- | Insert contents of binary file into a template.
46+-- Note that @Data.ByteString.readFile@ uses binary mode on windows.
47+binaryContentsOf :: FilePath -> ExpQ
48+binaryContentsOf p = lift =<< (runIO $ B.readFile p)
49+
50+instance Lift B.ByteString where
51+ lift x = return (LitE (StringL $ map w2c $ B.unpack x))
Text/Pandoc/Writers/S5.hs+2−1
@@ -40,7 +40,8 @@ module Text.Pandoc.Writers.S5 (
40 writeS5String,
40 writeS5String,
41 insertS5Structure
41 insertS5Structure
42 ) where
42 ) where
43−import Text.Pandoc.Shared ( joinWithSep, WriterOptions, contentsOf )
43+import Text.Pandoc.Shared ( joinWithSep, WriterOptions )
44+import Text.Pandoc.TH ( contentsOf )
44import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString )
45import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString )
45import Text.Pandoc.Definition
46import Text.Pandoc.Definition
46import Text.XHtml.Strict
47import Text.XHtml.Strict
pandoc.cabal+1
@@ -103,6 +103,7 @@ Library
103 Text.Pandoc.Writers.RTF,
103 Text.Pandoc.Writers.RTF,
104 Text.Pandoc.Writers.S5
104 Text.Pandoc.Writers.S5
105 Other-Modules: Text.Pandoc.XML,
105 Other-Modules: Text.Pandoc.XML,
106+ Text.Pandoc.TH,
106 Text.XML.Light,
107 Text.XML.Light,
107 Text.XML.Light.Types,
108 Text.XML.Light.Types,
108 Text.XML.Light.Output,
109 Text.XML.Light.Output,