From fd6e65b00ffc628488c27171f7dd9ab833c436c6 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 20 May 2017 21:43:53 +0200 Subject: [PATCH] Added `--resource-path=SEARCHPATH` command line option. SEARCHPATH is separated by the usual character, depending on OS (: on unix, ; on windows). Note: This does not yet work for PDF output, because the routine that creates PDFs runs outside PandocMonad. (This has to do with its use of inTemporaryDirectory and its interaction with our exceptions.) The best solution would be to figure out how to move the PDF creation routines into PandocMonad. Second-best, just pass an extra parameter in? See #852. --- MANUAL.txt | 6 ++++++ src/Text/Pandoc/App.hs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/MANUAL.txt b/MANUAL.txt index 51b324817..8c65789b9 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -690,6 +690,12 @@ General writer options repeatedly to include multiple files. They will be included in the order specified. Implies `--standalone`. +`--resource-path=`*SEARCHPATH* + +: List of paths to search for images and other resources. + The paths should be separated by `:` on linux, unix, and + MacOS systems, and by `;` on Windows. + Options affecting specific writers ---------------------------------- diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index 9c8e1bde4..a4967e5d1 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -70,7 +70,7 @@ import System.IO.Error (isDoesNotExistError) import Text.Pandoc import Text.Pandoc.Builder (setMeta) import Text.Pandoc.Class (PandocIO, getLog, withMediaBag, - extractMedia, fillMediaBag) + extractMedia, fillMediaBag, setResourcePath) import Text.Pandoc.Highlighting (highlightingStyles) import Text.Pandoc.Lua ( runLuaFilter ) import Text.Pandoc.PDF (makePDF) @@ -414,6 +414,7 @@ convertWithOpts opts = do let eol = fromMaybe nativeNewline $ optEol opts runIO' $ do + setResourcePath $ "." : (optResourcePath opts) (doc, media) <- withMediaBag $ sourceToDoc sources >>= ( (if isJust (optExtractMedia opts) then fillMediaBag (writerSourceURL writerOptions) @@ -569,6 +570,7 @@ data Opt = Opt , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body , optIncludeInHeader :: [FilePath] -- ^ Files to include in header + , optResourcePath :: [FilePath] -- ^ Path to search for images etc , optEol :: Maybe Newline -- ^ Enforce line-endings } @@ -638,6 +640,7 @@ defaultOpts = Opt , optIncludeBeforeBody = [] , optIncludeAfterBody = [] , optIncludeInHeader = [] + , optResourcePath = [] , optEol = Nothing } @@ -1052,6 +1055,14 @@ options = "FILE") "" -- "File to include after document body" + , Option "" ["resource-path"] + (ReqArg + (\arg opt -> return opt { optResourcePath = + splitSearchPath arg }) + "SEARCHPATH") + "" -- "Paths to search for images and other resources" + + , Option "" ["self-contained"] (NoArg (\opt -> return opt { optSelfContained = True,