git.iko.soy/typeable/pandoc
on master help sign in
PDF: Removed TeXError type, just return a bytestring.
commitc9c78344b1d798abd77a4ec65a5b7d1c0ec4c6e9 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 20 Jan 2012, 19:11 (15 years ago) parent50e16e6
2 files changed+8−18
src/Text/Pandoc/PDF.hs+7−18 src/pandoc.hs+1
src/Text/Pandoc/PDF.hs+7−18
@@ -46,19 +46,20 @@ import Text.Pandoc.UTF8 as UTF8
4646
4747tex2pdf :: TeXProgram
4848 -> String -- ^ latex source
49− -> IO (Either TeXError ByteString)
49+ -> IO (Either ByteString ByteString)
5050tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
5151 tex2pdf' tmpdir program source
5252
5353tex2pdf' :: FilePath -- ^ temp directory for output
5454 -> TeXProgram
5555 -> String -- ^ tex source
56− -> IO (Either TeXError ByteString)
56+ -> IO (Either ByteString ByteString)
5757tex2pdf' tmpDir program source = do
5858 (exit, log', mbPdf) <- runTeXProgram program 3 tmpDir source
5959 case (exit, mbPdf) of
60− (ExitFailure ec, _) -> return $ Left $ extractTeXError ec log'
61− (ExitSuccess, Nothing) -> error "tex2pdf: ExitSuccess but no PDF created!"
60+ (ExitFailure _, _) -> return $ Left $ extractMsg log'
61+ (ExitSuccess, Nothing) -> return $ Left
62+ "tex2pdf: ExitSuccess but no PDF created!"
6263 (ExitSuccess, Just pdf) -> return $ Right pdf
6364
6465data TeXProgram = PDFLaTeX
@@ -69,18 +70,8 @@ data TeXProgram = PDFLaTeX
6970 | PDFTeX
7071 deriving (Show, Read)
7172
72−data TeXError = TeXError { exitCode :: Int
73− , message :: ByteString
74− , fullLog :: ByteString
75− } deriving (Show, Read)
76−
7773-- parsing output
7874
79−extractTeXError :: Int -> ByteString -> TeXError
80−extractTeXError ec log' = TeXError { exitCode = ec
81− , message = extractMsg log'
82− , fullLog = log' }
83−
8475extractMsg :: ByteString -> ByteString
8576extractMsg log' = do
8677 let msg' = dropWhile (not . ("!" `BC.isPrefixOf`)) $ BC.lines log'
@@ -134,8 +125,7 @@ runTeXProgram program runsLeft tmpDir source = do
134125-- 'readProcessWithExitCode' from 'System.Process'.)
135126readCommand :: FilePath -- ^ command to run
136127 -> [String] -- ^ any arguments
137− -> IO (ExitCode,ByteString,ByteString) -- ^ exitcode, stdout, stderr
138−
128+ -> IO (ExitCode,ByteString,ByteString) -- ^ exit, stdout, stderr
139129readCommand cmd args = do
140130 (Just inh, Just outh, Just errh, pid) <-
141131 createProcess (proc cmd args){ std_in = CreatePipe,
@@ -156,5 +146,4 @@ readCommand cmd args = do
156146 hClose outh
157147 -- wait on the process
158148 ex <- waitForProcess pid
159− return (ex, out, err)
160−
149+ return (ex, out, err)
src/pandoc.hs+1
@@ -30,6 +30,7 @@ writers.
3030-}
3131module Main where
3232import Text.Pandoc
33+import Text.Pandoc.PDF (tex2pdf)
3334import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
3435 headerShift, findDataFile, normalize )
3536import Text.Pandoc.SelfContained ( makeSelfContained )