From 78cd41c5975bdc69830ea4dfb127b50f19778adb Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 13 Feb 2011 08:28:59 -0800 Subject: markdown2pdf: Fixed filename encoding issues. With help from Paulo Tanimoto. Resolves Issue #286. --- src/markdown2pdf.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/markdown2pdf.hs b/src/markdown2pdf.hs index c61aaa8cb..8dc5f273c 100644 --- a/src/markdown2pdf.hs +++ b/src/markdown2pdf.hs @@ -14,11 +14,13 @@ import System.Exit (ExitCode (..), exitWith) import System.FilePath import System.Directory import System.Process (readProcessWithExitCode) - +import Codec.Binary.UTF8.String (decodeString, encodeString) +import Control.Monad (liftM) run :: FilePath -> [String] -> IO (Either String String) run file opts = do - (code, out, err) <- readProcessWithExitCode file opts "" + (code, out, err) <- readProcessWithExitCode (encodeString file) + (map encodeString opts) "" let msg = out ++ err case code of ExitFailure _ -> return $ Left $! msg @@ -122,30 +124,30 @@ saveStdin :: FilePath -> IO (Either String FilePath) saveStdin file = do text <- UTF8.getContents UTF8.writeFile file text - fileExist <- doesFileExist file + fileExist <- doesFileExist (encodeString file) case fileExist of False -> return $ Left $! "Could not create " ++ file True -> return $ Right file saveOutput :: FilePath -> FilePath -> IO () saveOutput input output = do - copyFile input output + copyFile (encodeString input) (encodeString output) UTF8.hPutStrLn stderr $! "Created " ++ output main :: IO () main = bracket -- acquire resource - (do dir <- getTemporaryDirectory + (do dir <- return "testtmp" -- TODO -- getTemporaryDirectory let tmp = dir "pandoc" createDirectoryIfMissing True tmp return tmp) -- release resource - ( \tmp -> removeDirectoryRecursive tmp) + ( \tmp -> return () )-- TODO -- removeDirectoryRecursive tmp) -- run computation $ \tmp -> do - args <- getArgs + args <- liftM (map decodeString) getArgs -- check for invalid arguments and print help message if needed let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"] let goodoptslong = ["--from","--read","--strict", -- cgit v1.2.3