git.iko.soy/typeable/pandoc
on master help sign in
PDF: Removed TeXError type, just return a bytestring.
c9c7834John MacFarlane
src/Text/Pandoc/PDF.hs+7−18
@@ -46,19 +46,20 @@ import Text.Pandoc.UTF8 as UTF8
46
46
47tex2pdf :: TeXProgram
47tex2pdf :: TeXProgram
48 -> String -- ^ latex source
48 -> String -- ^ latex source
49− -> IO (Either TeXError ByteString)
49+ -> IO (Either ByteString ByteString)
50tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
50tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
51 tex2pdf' tmpdir program source
51 tex2pdf' tmpdir program source
52
52
53tex2pdf' :: FilePath -- ^ temp directory for output
53tex2pdf' :: FilePath -- ^ temp directory for output
54 -> TeXProgram
54 -> TeXProgram
55 -> String -- ^ tex source
55 -> String -- ^ tex source
56− -> IO (Either TeXError ByteString)
56+ -> IO (Either ByteString ByteString)
57tex2pdf' tmpDir program source = do
57tex2pdf' tmpDir program source = do
58 (exit, log', mbPdf) <- runTeXProgram program 3 tmpDir source
58 (exit, log', mbPdf) <- runTeXProgram program 3 tmpDir source
59 case (exit, mbPdf) of
59 case (exit, mbPdf) of
60− (ExitFailure ec, _) -> return $ Left $ extractTeXError ec log'
60+ (ExitFailure _, _) -> return $ Left $ extractMsg log'
61+ (ExitSuccess, Nothing) -> return $ Left
61− (ExitSuccess, Nothing) -> error "tex2pdf: ExitSuccess but no PDF created!"
62+ "tex2pdf: ExitSuccess but no PDF created!"
62 (ExitSuccess, Just pdf) -> return $ Right pdf
63 (ExitSuccess, Just pdf) -> return $ Right pdf
63
64
64data TeXProgram = PDFLaTeX
65data TeXProgram = PDFLaTeX
@@ -69,18 +70,8 @@ data TeXProgram = PDFLaTeX
69 | PDFTeX
70 | PDFTeX
70 deriving (Show, Read)
71 deriving (Show, Read)
71
72
72−data TeXError = TeXError { exitCode :: Int
73− , message :: ByteString
74− , fullLog :: ByteString
75− } deriving (Show, Read)
76−
77-- parsing output
73-- parsing output
78
74
79−extractTeXError :: Int -> ByteString -> TeXError
80−extractTeXError ec log' = TeXError { exitCode = ec
81− , message = extractMsg log'
82− , fullLog = log' }
83−
84extractMsg :: ByteString -> ByteString
75extractMsg :: ByteString -> ByteString
85extractMsg log' = do
76extractMsg log' = do
86 let msg' = dropWhile (not . ("!" `BC.isPrefixOf`)) $ BC.lines log'
77 let msg' = dropWhile (not . ("!" `BC.isPrefixOf`)) $ BC.lines log'
@@ -134,8 +125,7 @@ runTeXProgram program runsLeft tmpDir source = do
134-- 'readProcessWithExitCode' from 'System.Process'.)
125-- 'readProcessWithExitCode' from 'System.Process'.)
135readCommand :: FilePath -- ^ command to run
126readCommand :: FilePath -- ^ command to run
136 -> [String] -- ^ any arguments
127 -> [String] -- ^ any arguments
137− -> IO (ExitCode,ByteString,ByteString) -- ^ exitcode, stdout, stderr
128+ -> IO (ExitCode,ByteString,ByteString) -- ^ exit, stdout, stderr
138−
139readCommand cmd args = do
129readCommand cmd args = do
140 (Just inh, Just outh, Just errh, pid) <-
130 (Just inh, Just outh, Just errh, pid) <-
141 createProcess (proc cmd args){ std_in = CreatePipe,
131 createProcess (proc cmd args){ std_in = CreatePipe,
@@ -156,5 +146,4 @@ readCommand cmd args = do
156 hClose outh
146 hClose outh
157 -- wait on the process
147 -- wait on the process
158 ex <- waitForProcess pid
148 ex <- waitForProcess pid
159− return (ex, out, err)
149+ return (ex, out, err)
160−
src/pandoc.hs+1
@@ -30,6 +30,7 @@ writers.
30-}
30-}
31module Main where
31module Main where
32import Text.Pandoc
32import Text.Pandoc
33+import Text.Pandoc.PDF (tex2pdf)
33import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
34import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
34 headerShift, findDataFile, normalize )
35 headerShift, findDataFile, normalize )
35import Text.Pandoc.SelfContained ( makeSelfContained )
36import Text.Pandoc.SelfContained ( makeSelfContained )