@@ -96,7 +96,7 @@ parseOptions options' defaults = do
97 -- thread option data structure through all supplied option actions
97 -- thread option data structure through all supplied option actions
98 opts <- foldl (>>=) (return defaults) actions
98 opts <- foldl (>>=) (return defaults) actions
99− return (opts{ optInputFiles = args })
99+ return (opts{ optInputFiles = map normalizePath args })
101latexEngines :: [String]
101latexEngines :: [String]
102latexEngines = ["pdflatex", "lualatex", "xelatex"]
102latexEngines = ["pdflatex", "lualatex", "xelatex"]
@@ -149,13 +149,15 @@ options =
150 , Option "o" ["output"]
150 , Option "o" ["output"]
152− (\arg opt -> return opt { optOutputFile = Just arg })
152+ (\arg opt -> return opt { optOutputFile =
153+ Just (normalizePath arg) })
154 "" -- "Name of output file"
155 "" -- "Name of output file"
156 , Option "" ["data-dir"]
157 , Option "" ["data-dir"]
158− (\arg opt -> return opt { optDataDir = Just arg })
159+ (\arg opt -> return opt { optDataDir =
160+ Just (normalizePath arg) })
159 "DIRECTORY") -- "Directory containing pandoc data files."
161 "DIRECTORY") -- "Directory containing pandoc data files."
@@ -188,14 +190,16 @@ options =
188 , Option "F" ["filter"]
190 , Option "F" ["filter"]
190 (\arg opt -> return opt { optFilters =
192 (\arg opt -> return opt { optFilters =
193+ JSONFilter (normalizePath arg) :
191− JSONFilter arg : optFilters opt })
194+ optFilters opt })
192 "PROGRAM")
195 "PROGRAM")
193 "" -- "External JSON filter"
196 "" -- "External JSON filter"
195 , Option "" ["lua-filter"]
198 , Option "" ["lua-filter"]
197 (\arg opt -> return opt { optFilters =
200 (\arg opt -> return opt { optFilters =
201+ LuaFilter (normalizePath arg) :
198− LuaFilter arg : optFilters opt })
202+ optFilters opt })
199 "SCRIPTPATH")
203 "SCRIPTPATH")
200 "" -- "Lua filter"
204 "" -- "Lua filter"
@@ -235,7 +239,8 @@ options =
235 , Option "" ["extract-media"]
239 , Option "" ["extract-media"]
237 (\arg opt ->
241 (\arg opt ->
238− return opt { optExtractMedia = Just arg })
242+ return opt { optExtractMedia =
243+ Just (normalizePath arg) })
240 "" -- "Directory to which to extract embedded media"
245 "" -- "Directory to which to extract embedded media"
@@ -247,7 +252,7 @@ options =
247 , Option "" ["template"]
252 , Option "" ["template"]
249 (\arg opt ->
254 (\arg opt ->
250− return opt{ optTemplate = Just arg,
255+ return opt{ optTemplate = Just (normalizePath arg),
251 optStandalone = True })
256 optStandalone = True })
253 "" -- "Use custom template"
258 "" -- "Use custom template"
@@ -262,7 +267,8 @@ options =
263 , Option "" ["metadata-file"]
268 , Option "" ["metadata-file"]
265− (\arg opt -> return opt{ optMetadataFile = Just arg })
270+ (\arg opt -> return opt{ optMetadataFile =
271+ Just (normalizePath arg) })
@@ -405,7 +411,7 @@ options =
405 -- HXT confuses Windows path with URI
411 -- HXT confuses Windows path with URI
406 _:':':'\\':_ ->
412 _:':':'\\':_ ->
407 "file:///" ++ tr '\\' '/' arg
413 "file:///" ++ tr '\\' '/' arg
408− _ -> arg
414+ _ -> normalizePath arg
409 return opt{ optSyntaxDefinitions = arg' :
415 return opt{ optSyntaxDefinitions = arg' :
410 optSyntaxDefinitions opt })
416 optSyntaxDefinitions opt })
@@ -931,3 +937,19 @@ deprecatedOption o msg =
931 \r -> case r of
937 \r -> case r of
932 Right () -> return ()
938 Right () -> return ()
933 Left e -> E.throwIO e
939 Left e -> E.throwIO e
941+-- On Windows with ghc 8.6+, we need to rewrite paths
942+-- beginning with \\ to \\?\UNC\. -- See #5127.
943+normalizePath :: FilePath -> FilePath
945+#if MIN_VERSION_base(4,12,0)
947+ if "\\\\" `isPrefixOf` fp && not ("\\\\?\\" `isPrefixOf` fp)
948+ then "\\\\?\\UNC\\" ++ drop 2 fp