@@ -48,7 +48,8 @@ import System.FilePath
4848import System.Console.GetOpt
4949import Data.Char ( toLower )
5050import Data.List ( intercalate, isPrefixOf, sort )
51−import System.Directory ( getAppUserDataDirectory, findExecutable )
51+import System.Directory ( getAppUserDataDirectory, findExecutable,
52+ doesFileExist )
5253import System.IO ( stdout, stderr )
5354import System.IO.Error ( isDoesNotExistError )
5455import qualified Control.Exception as E
@@ -97,8 +98,23 @@ isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub","ep
9798
9899externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
99100externalFilter f args' d = do
101+ mbexe <- findExecutable f
102+ (f', args'') <- case mbexe of
103+ Just x -> return (x, args')
104+ Nothing -> do
105+ exists <- doesFileExist f
106+ if exists
107+ then return $
108+ case map toLower $ takeExtension f of
109+ ".py" -> ("python", f:args')
110+ ".hs" -> ("runhaskell", f:args')
111+ ".pl" -> ("perl", f:args')
112+ ".rb" -> ("ruby", f:args')
113+ ".php" -> ("php", f:args')
114+ _ -> (f, args')
115+ else err 85 $ "Filter " ++ f ++ " not found"
100116 (exitcode, outbs, errbs) <- E.handle filterException $
101− pipeProcess Nothing f args' $ encode d
117+ pipeProcess Nothing f' args'' $ encode d
102118 when (not $ B.null errbs) $ B.hPutStr stderr errbs
103119 case exitcode of
104120 ExitSuccess -> return $ either error id $ eitherDecode' outbs