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.
This commit is contained in:
John MacFarlane 2017-05-20 21:43:53 +02:00
parent 93eaf33e6e
commit fd6e65b00f
2 changed files with 18 additions and 1 deletions

View file

@ -690,6 +690,12 @@ General writer options
repeatedly to include multiple files. They will be included in the repeatedly to include multiple files. They will be included in the
order specified. Implies `--standalone`. 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 Options affecting specific writers
---------------------------------- ----------------------------------

View file

@ -70,7 +70,7 @@ import System.IO.Error (isDoesNotExistError)
import Text.Pandoc import Text.Pandoc
import Text.Pandoc.Builder (setMeta) import Text.Pandoc.Builder (setMeta)
import Text.Pandoc.Class (PandocIO, getLog, withMediaBag, import Text.Pandoc.Class (PandocIO, getLog, withMediaBag,
extractMedia, fillMediaBag) extractMedia, fillMediaBag, setResourcePath)
import Text.Pandoc.Highlighting (highlightingStyles) import Text.Pandoc.Highlighting (highlightingStyles)
import Text.Pandoc.Lua ( runLuaFilter ) import Text.Pandoc.Lua ( runLuaFilter )
import Text.Pandoc.PDF (makePDF) import Text.Pandoc.PDF (makePDF)
@ -414,6 +414,7 @@ convertWithOpts opts = do
let eol = fromMaybe nativeNewline $ optEol opts let eol = fromMaybe nativeNewline $ optEol opts
runIO' $ do runIO' $ do
setResourcePath $ "." : (optResourcePath opts)
(doc, media) <- withMediaBag $ sourceToDoc sources >>= (doc, media) <- withMediaBag $ sourceToDoc sources >>=
( (if isJust (optExtractMedia opts) ( (if isJust (optExtractMedia opts)
then fillMediaBag (writerSourceURL writerOptions) then fillMediaBag (writerSourceURL writerOptions)
@ -569,6 +570,7 @@ data Opt = Opt
, optIncludeBeforeBody :: [FilePath] -- ^ Files to include before , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
, optIncludeAfterBody :: [FilePath] -- ^ Files to include after body , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
, optIncludeInHeader :: [FilePath] -- ^ Files to include in header , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
, optResourcePath :: [FilePath] -- ^ Path to search for images etc
, optEol :: Maybe Newline -- ^ Enforce line-endings , optEol :: Maybe Newline -- ^ Enforce line-endings
} }
@ -638,6 +640,7 @@ defaultOpts = Opt
, optIncludeBeforeBody = [] , optIncludeBeforeBody = []
, optIncludeAfterBody = [] , optIncludeAfterBody = []
, optIncludeInHeader = [] , optIncludeInHeader = []
, optResourcePath = []
, optEol = Nothing , optEol = Nothing
} }
@ -1052,6 +1055,14 @@ options =
"FILE") "FILE")
"" -- "File to include after document body" "" -- "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"] , Option "" ["self-contained"]
(NoArg (NoArg
(\opt -> return opt { optSelfContained = True, (\opt -> return opt { optSelfContained = True,