@@ -37,13 +37,13 @@ import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8, safeRead,
3737 headerShift, normalize, err, warn )
3838import Text.Pandoc.XML ( toEntities, fromEntities )
3939import Text.Pandoc.SelfContained ( makeSelfContained )
40+import Text.Pandoc.Process (pipeProcess)
4041import Text.Highlighting.Kate ( languages, Style, tango, pygments,
4142 espresso, zenburn, kate, haddock, monochrome )
4243import System.Environment ( getArgs, getProgName )
4344import System.Exit ( exitWith, ExitCode (..) )
4445import System.FilePath
4546import System.Console.GetOpt
46−import System.Process (readProcess)
4747import Data.Char ( toLower )
4848import Data.List ( intercalate, isPrefixOf, sort )
4949import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
@@ -59,6 +59,7 @@ import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
5959import Network.URI (parseURI, isURI, URI(..))
6060import qualified Data.ByteString.Lazy as B
6161import Text.CSL.Reference (Reference(..))
62+import Data.Aeson (eitherDecode', encode)
6263
6364copyrightMessage :: String
6465copyrightMessage = "\nCopyright (C) 2006-2013 John MacFarlane\n" ++
@@ -88,9 +89,13 @@ wrapWords indent c = wrap' (c - indent) (c - indent)
8889isTextFormat :: String -> Bool
8990isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub","epub3"]
9091
91−externalFilter :: FilePath -> Pandoc -> IO Pandoc
92−externalFilter f d = E.catch
93− (readJSON def `fmap` readProcess f [] (writeJSON def d))
92+externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
93+externalFilter f args' d = E.catch
94+ (do (exitcode, outbs, errbs) <- pipeProcess Nothing f args' $ encode d
95+ case exitcode of
96+ ExitSuccess -> return $ either error id $ eitherDecode' outbs
97+ ExitFailure _ -> err 83 $ "Error running filter `" ++ UTF8.toStringLazy outbs ++
98+ UTF8.toStringLazy errbs ++ "'")
9499 (\e -> let _ = (e :: E.SomeException)
95100 in err 83 $ "Error running filter `" ++ f ++ "'")
96101
@@ -132,7 +137,7 @@ data Opt = Opt
132137 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
133138 , optWrapText :: Bool -- ^ Wrap text
134139 , optColumns :: Int -- ^ Line length in characters
135− , optPlugins :: [Pandoc -> IO Pandoc] -- ^ Plugins to apply
140+ , optPlugins :: [[String] -> Pandoc -> IO Pandoc] -- ^ Plugins to apply
136141 , optEmailObfuscation :: ObfuscationMethod
137142 , optIdentifierPrefix :: String
138143 , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
@@ -1115,7 +1120,7 @@ main = do
11151120 reader readerOpts
11161121
11171122 let doc0 = foldr ($) doc transforms
1118− doc1 <- foldrM ($) doc0 plugins
1123+ doc1 <- foldrM ($) doc0 $ map ($ [writerName']) plugins
11191124
11201125 let writeBinary :: B.ByteString -> IO ()
11211126 writeBinary = B.writeFile (UTF8.encodePath outputFile)