git.iko.soy/typeable/pandoc
on master help sign in
Initial implementation of --defaults option.

Need documentation.

commit83702404af948ca7b36d2e0f11eb912997fa5800 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 9 Oct 2019, 12:44 (7 years ago) parent5419988
2 files changed+24−3
src/Text/Pandoc/App/CommandLineOptions.hs+23−2 src/Text/Pandoc/App/Opt.hs+1−1
src/Text/Pandoc/App/CommandLineOptions.hs+23−2
@@ -42,7 +42,7 @@ import System.FilePath
4242import System.IO (stdout)
4343import Text.Pandoc
4444import Text.Pandoc.Builder (setMeta)
45−import Text.Pandoc.App.Opt (Opt (..), LineEnding (..))
45+import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), defaultOpts)
4646import Text.Pandoc.Filter (Filter (..))
4747import Text.Pandoc.Highlighting (highlightingStyles)
4848import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
@@ -64,6 +64,8 @@ import qualified Data.Text as T
6464import Data.Text (Text)
6565import Text.DocTemplates (ToContext(toVal), Context(..))
6666import qualified Text.Pandoc.UTF8 as UTF8
67+import qualified Data.YAML.Aeson as YA
68+import qualified Data.YAML as Y
6769
6870parseOptions :: [OptDescr (Opt -> IO Opt)] -> Opt -> IO Opt
6971parseOptions options' defaults = do
@@ -108,7 +110,26 @@ pdfEngines = ordNub $ map snd engines
108110-- in response to a command-line option.
109111options :: [OptDescr (Opt -> IO Opt)]
110112options =
111− [ Option "fr" ["from","read"]
113+ [ Option "" ["defaults"]
114+ (ReqArg
115+ (\arg _opt -> do
116+ let defaults = YA.encode1 defaultOpts
117+ inp <- E.catch (B.readFile arg)
118+ (\e -> E.throwIO $ PandocIOError
119+ "Error reading defaults file" e)
120+ case YA.decode1 (defaults <> inp) of
121+ Right (newopts :: Opt) -> do
122+ return newopts
123+ Left (errpos, errmsg) -> E.throwIO $
124+ PandocParseError $ "Error parsing " ++ arg ++
125+ " (line " ++ show (Y.posLine errpos) ++
126+ " column " ++ show (Y.posColumn errpos) ++ ")\n"
127+ ++ errmsg
128+ )
129+ "FILE")
130+ ""
131+
132+ , Option "fr" ["from","read"]
112133 (ReqArg
113134 (\arg opt -> return opt { optReader =
114135 Just (map toLower arg) })
src/Text/Pandoc/App/Opt.hs+1−1
@@ -184,7 +184,7 @@ defaultOpts = Opt
184184 , optResourcePath = ["."]
185185 , optRequestHeaders = []
186186 , optEol = Native
187− , optStripComments = False
187+ , optStripComments = False
188188 }
189189
190190-- see https://github.com/jgm/pandoc/pull/4083