git.iko.soy/typeable/pandoc
on master help sign in
Use XDG data directory for user data directory.

Instead of `$HOME/.pandoc`, the default user data directory is now `$XDG_DATA_HOME/pandoc`, where `XDG_DATA_HOME` defaults to `$HOME/.local/share` but can be overridden by setting the environment variable. If this directory is missing, then `$HOME/.pandoc` is searched instead, for backwards compatibility. However, we recommend moving local pandoc data files from `$HOME/.pandoc` to `$HOME/.local/share/pandoc`. On Windows the default user data directory remains the same. Closes #3582.

commit0bed0ab5a308f5e72a01fa9bee76488556288862 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 2 Mar 2019, 15:03 (8 years ago) parenta99423b
5 files changed+27−30
MANUAL.txt+7−12 pandoc.cabal+2−2 src/Text/Pandoc/App.hs+12−6 src/Text/Pandoc/App/CommandLineOptions.hs+5−9 test/command/lua-pandoc-state.md+1−1
MANUAL.txt+7−12
@@ -349,18 +349,13 @@ General options {.options}
349349
350350: Specify the user data directory to search for pandoc data files.
351351 If this option is not specified, the default user data directory
352− will be used. This is, in UNIX:
353−
354− $HOME/.pandoc
355−
356− in Windows XP:
357−
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
363−
352+ will be used. On \*nix and macOS systems this will be the `pandoc`
353+ subdirectory of the XDG data directory (by default,
354+ `$HOME/.local/share`, overridable by setting the `XDG_DATA_HOME`
355+ environment variable). If that directory does not exist,
356+ `$HOME/.pandoc` will be used (for backwards compatibility).
357+ In Windows the default user data directory is
358+ `C:\Users\USERNAME\AppData\Roaming\pandoc`.
364359 You can find the default user data directory on your system by
365360 looking at the output of `pandoc --version`.
366361 A `reference.odt`, `reference.docx`, `epub.css`, `templates`,
pandoc.cabal+2−2
@@ -363,7 +363,7 @@ library
363363 exceptions >= 0.8 && < 0.11,
364364 filepath >= 1.1 && < 1.5,
365365 process >= 1.2.3 && < 1.7,
366− directory >= 1 && < 1.4,
366+ directory >= 1.2.3 && < 1.4,
367367 bytestring >= 0.9 && < 0.11,
368368 text >= 1.1.1.0 && < 1.3,
369369 time >= 1.5 && < 1.10,
@@ -661,7 +661,7 @@ test-suite test-pandoc
661661 base64-bytestring >= 0.1 && < 1.1,
662662 text >= 1.1.1.0 && < 1.3,
663663 time >= 1.5 && < 1.10,
664− directory >= 1 && < 1.4,
664+ directory >= 1.2.3 && < 1.4,
665665 filepath >= 1.1 && < 1.5,
666666 hslua >= 1.0 && < 1.1,
667667 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
3838import qualified Data.Text.Encoding.Error as TE
3939import qualified Data.Text.Encoding.Error as TSE
4040import Network.URI (URI (..), parseURI)
41−import System.Directory (getAppUserDataDirectory)
41+import System.Directory (doesDirectoryExist)
4242import System.Exit (exitSuccess)
4343import System.FilePath
4444import System.IO (nativeNewline, stdout)
@@ -55,7 +55,8 @@ import Text.Pandoc.PDF (makePDF)
5555import Text.Pandoc.Readers.Markdown (yamlToMeta)
5656import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
5757import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
58− headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput)
58+ headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput,
59+ defaultUserDataDirs)
5960import qualified Text.Pandoc.UTF8 as UTF8
6061#ifndef _WINDOWS
6162import System.Posix.IO (stdOutput)
@@ -89,10 +90,15 @@ convertWithOpts opts = do
8990 | otherwise -> xs
9091
9192 datadir <- case optDataDir opts of
92− Nothing -> E.catch
93− (Just <$> getAppUserDataDirectory "pandoc")
94− (\e -> let _ = (e :: E.SomeException)
95− in return Nothing)
93+ Nothing -> do
94+ ds <- defaultUserDataDirs
95+ let selectUserDataDir [] = 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
96102 Just _ -> return $ optDataDir opts
97103
98104 -- 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 (..))
4646import Text.Pandoc.Filter (Filter (..))
4747import Text.Pandoc.Highlighting (highlightingStyles)
4848import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
49−import Text.Pandoc.Shared (ordNub, safeRead)
49+import Text.Pandoc.Shared (ordNub, safeRead, defaultUserDataDirs)
5050import Text.Printf
5151
5252#ifdef EMBED_DATA_FILES
5353import Text.Pandoc.Data (dataFiles)
54−import System.Directory (getAppUserDataDirectory)
5554#else
5655import Paths_pandoc (getDataDir)
57−import System.Directory (getAppUserDataDirectory, getDirectoryContents)
56+import System.Directory (getDirectoryContents)
5857#endif
5958
6059import qualified Control.Exception as E
@@ -837,13 +836,11 @@ options =
837836 (NoArg
838837 (\_ -> do
839838 prg <- getProgName
840− defaultDatadir <- E.catch
841− (getAppUserDataDirectory "pandoc")
842− (\e -> let _ = (e :: E.SomeException)
843− in return "")
839+ defaultDatadirs <- defaultUserDataDirs
844840 UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++
845841 compileInfo ++ "\nDefault user data directory: " ++
846− defaultDatadir ++ copyrightMessage)
842+ intercalate " or " defaultDatadirs ++
843+ ('\n':copyrightMessage))
847844 exitSuccess ))
848845 "" -- "Print version"
849846
@@ -872,7 +869,6 @@ usageMessage programName = usageInfo (programName ++ " [OPTIONS] [FILES]")
872869
873870copyrightMessage :: String
874871copyrightMessage = intercalate "\n" [
875− "",
876872 "Copyright (C) 2006-2019 John MacFarlane",
877873 "Web: http://pandoc.org",
878874 "This is free software; see the source for copying conditions.",
test/command/lua-pandoc-state.md+1−1
@@ -1,5 +1,5 @@
11```
2−% pandoc --lua-filter=command/lua-pandoc-state.lua
2+% pandoc --lua-filter=command/lua-pandoc-state.lua --data-dir=foo
33Hello
44^D
55 # input files: 0