git.iko.soy/typeable/pandoc
on master help sign in
Use XDG data directory for user data directory.
0bed0abJohn MacFarlane
MANUAL.txt+7−12
@@ -349,18 +349,13 @@ General options {.options}
349
349
350: Specify the user data directory to search for pandoc data files.
350: Specify the user data directory to search for pandoc data files.
351 If this option is not specified, the default user data directory
351 If this option is not specified, the default user data directory
352− will be used. This is, in UNIX:
352+ will be used. On \*nix and macOS systems this will be the `pandoc`
353−
353+ subdirectory of the XDG data directory (by default,
354− $HOME/.pandoc
354+ `$HOME/.local/share`, overridable by setting the `XDG_DATA_HOME`
355−
355+ environment variable). If that directory does not exist,
356− in Windows XP:
356+ `$HOME/.pandoc` will be used (for backwards compatibility).
357−
357+ In Windows the default user data directory is
358− C:\Documents And Settings\USERNAME\Application Data\pandoc
359−
360− and in Windows Vista or later:
361−
362− C:\Users\USERNAME\AppData\Roaming\pandoc
358+ `C:\Users\USERNAME\AppData\Roaming\pandoc`.
363−
364 You can find the default user data directory on your system by
359 You can find the default user data directory on your system by
365 looking at the output of `pandoc --version`.
360 looking at the output of `pandoc --version`.
366 A `reference.odt`, `reference.docx`, `epub.css`, `templates`,
361 A `reference.odt`, `reference.docx`, `epub.css`, `templates`,
pandoc.cabal+2−2
@@ -363,7 +363,7 @@ library
363 exceptions >= 0.8 && < 0.11,
363 exceptions >= 0.8 && < 0.11,
364 filepath >= 1.1 && < 1.5,
364 filepath >= 1.1 && < 1.5,
365 process >= 1.2.3 && < 1.7,
365 process >= 1.2.3 && < 1.7,
366− directory >= 1 && < 1.4,
366+ directory >= 1.2.3 && < 1.4,
367 bytestring >= 0.9 && < 0.11,
367 bytestring >= 0.9 && < 0.11,
368 text >= 1.1.1.0 && < 1.3,
368 text >= 1.1.1.0 && < 1.3,
369 time >= 1.5 && < 1.10,
369 time >= 1.5 && < 1.10,
@@ -661,7 +661,7 @@ test-suite test-pandoc
661 base64-bytestring >= 0.1 && < 1.1,
661 base64-bytestring >= 0.1 && < 1.1,
662 text >= 1.1.1.0 && < 1.3,
662 text >= 1.1.1.0 && < 1.3,
663 time >= 1.5 && < 1.10,
663 time >= 1.5 && < 1.10,
664− directory >= 1 && < 1.4,
664+ directory >= 1.2.3 && < 1.4,
665 filepath >= 1.1 && < 1.5,
665 filepath >= 1.1 && < 1.5,
666 hslua >= 1.0 && < 1.1,
666 hslua >= 1.0 && < 1.1,
667 process >= 1.2.3 && < 1.7,
667 process >= 1.2.3 && < 1.7,
src/Text/Pandoc/App.hs+12−6
@@ -38,7 +38,7 @@ import qualified Data.Text.Lazy.Encoding as TE
38import qualified Data.Text.Encoding.Error as TE
38import qualified Data.Text.Encoding.Error as TE
39import qualified Data.Text.Encoding.Error as TSE
39import qualified Data.Text.Encoding.Error as TSE
40import Network.URI (URI (..), parseURI)
40import Network.URI (URI (..), parseURI)
41−import System.Directory (getAppUserDataDirectory)
41+import System.Directory (doesDirectoryExist)
42import System.Exit (exitSuccess)
42import System.Exit (exitSuccess)
43import System.FilePath
43import System.FilePath
44import System.IO (nativeNewline, stdout)
44import System.IO (nativeNewline, stdout)
@@ -55,7 +55,8 @@ import Text.Pandoc.PDF (makePDF)
55import Text.Pandoc.Readers.Markdown (yamlToMeta)
55import Text.Pandoc.Readers.Markdown (yamlToMeta)
56import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
56import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
57import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
57import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
58− headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput)
58+ headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput,
59+ defaultUserDataDirs)
59import qualified Text.Pandoc.UTF8 as UTF8
60import qualified Text.Pandoc.UTF8 as UTF8
60#ifndef _WINDOWS
61#ifndef _WINDOWS
61import System.Posix.IO (stdOutput)
62import System.Posix.IO (stdOutput)
@@ -89,10 +90,15 @@ convertWithOpts opts = do
89 | otherwise -> xs
90 | otherwise -> xs
90
91
91 datadir <- case optDataDir opts of
92 datadir <- case optDataDir opts of
92− Nothing -> E.catch
93+ Nothing -> do
93− (Just <$> getAppUserDataDirectory "pandoc")
94+ ds <- defaultUserDataDirs
94− (\e -> let _ = (e :: E.SomeException)
95+ let selectUserDataDir [] = return Nothing
95− in return Nothing)
96+ selectUserDataDir (dir:dirs) = do
97+ exists <- doesDirectoryExist dir
98+ if exists
99+ then return (Just dir)
100+ else selectUserDataDir dirs
101+ selectUserDataDir ds
96 Just _ -> return $ optDataDir opts
102 Just _ -> return $ optDataDir opts
97
103
98 -- assign reader and writer based on options and filenames
104 -- assign reader and writer based on options and filenames
src/Text/Pandoc/App/CommandLineOptions.hs+5−9
@@ -46,15 +46,14 @@ import Text.Pandoc.App.Opt (Opt (..), LineEnding (..))
46import Text.Pandoc.Filter (Filter (..))
46import Text.Pandoc.Filter (Filter (..))
47import Text.Pandoc.Highlighting (highlightingStyles)
47import Text.Pandoc.Highlighting (highlightingStyles)
48import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
48import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
49−import Text.Pandoc.Shared (ordNub, safeRead)
49+import Text.Pandoc.Shared (ordNub, safeRead, defaultUserDataDirs)
50import Text.Printf
50import Text.Printf
51
51
52#ifdef EMBED_DATA_FILES
52#ifdef EMBED_DATA_FILES
53import Text.Pandoc.Data (dataFiles)
53import Text.Pandoc.Data (dataFiles)
54−import System.Directory (getAppUserDataDirectory)
55#else
54#else
56import Paths_pandoc (getDataDir)
55import Paths_pandoc (getDataDir)
57−import System.Directory (getAppUserDataDirectory, getDirectoryContents)
56+import System.Directory (getDirectoryContents)
58#endif
57#endif
59
58
60import qualified Control.Exception as E
59import qualified Control.Exception as E
@@ -837,13 +836,11 @@ options =
837 (NoArg
836 (NoArg
838 (\_ -> do
837 (\_ -> do
839 prg <- getProgName
838 prg <- getProgName
840− defaultDatadir <- E.catch
839+ defaultDatadirs <- defaultUserDataDirs
841− (getAppUserDataDirectory "pandoc")
842− (\e -> let _ = (e :: E.SomeException)
843− in return "")
844 UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++
840 UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++
845 compileInfo ++ "\nDefault user data directory: " ++
841 compileInfo ++ "\nDefault user data directory: " ++
842+ intercalate " or " defaultDatadirs ++
846− defaultDatadir ++ copyrightMessage)
843+ ('\n':copyrightMessage))
847 exitSuccess ))
844 exitSuccess ))
848 "" -- "Print version"
845 "" -- "Print version"
849
846
@@ -872,7 +869,6 @@ usageMessage programName = usageInfo (programName ++ " [OPTIONS] [FILES]")
872
869
873copyrightMessage :: String
870copyrightMessage :: String
874copyrightMessage = intercalate "\n" [
871copyrightMessage = intercalate "\n" [
875− "",
876 "Copyright (C) 2006-2019 John MacFarlane",
872 "Copyright (C) 2006-2019 John MacFarlane",
877 "Web: http://pandoc.org",
873 "Web: http://pandoc.org",
878 "This is free software; see the source for copying conditions.",
874 "This is free software; see the source for copying conditions.",
test/command/lua-pandoc-state.md+1−1
@@ -1,5 +1,5 @@
1```
1```
2−% pandoc --lua-filter=command/lua-pandoc-state.lua
2+% pandoc --lua-filter=command/lua-pandoc-state.lua --data-dir=foo
3Hello
3Hello
4^D
4^D
5 # input files: 0
5 # input files: 0