From 7d3702e807abbb1c987157b47135bf9efdcaff98 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 4 Feb 2017 10:09:20 +0100 Subject: Simplified Opt structure in cli option parsing. We should make this closer to the actual options, and do processing outside. --- pandoc.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'pandoc.hs') diff --git a/pandoc.hs b/pandoc.hs index b88e847f6..900322dcb 100644 --- a/pandoc.hs +++ b/pandoc.hs @@ -124,7 +124,7 @@ convertWithOpts opts args = do , optVariables = variables , optMetadata = metadata , optTableOfContents = toc - , optTransforms = transforms + , optBaseHeaderLevel = baseHeaderLevel , optTemplate = templatePath , optOutputFile = outputFile , optNumberSections = numberSections @@ -354,6 +354,10 @@ convertWithOpts opts args = do "Specify an output file using the -o option." + let transforms = if baseHeaderLevel > 1 + then [headerShift (baseHeaderLevel - 1)] + else [] + let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t" then 0 else tabStop) @@ -526,7 +530,7 @@ data Opt = Opt , optWriter :: String -- ^ Writer format , optParseRaw :: Bool -- ^ Parse unconvertable HTML and TeX , optTableOfContents :: Bool -- ^ Include table of contents - , optTransforms :: [Transform] -- ^ Doc transforms to apply + , optBaseHeaderLevel :: Int -- ^ Base header level , optTemplate :: Maybe FilePath -- ^ Custom template , optVariables :: [(String,String)] -- ^ Template variables to set , optMetadata :: M.Map String MetaValue -- ^ Metadata fields to set @@ -585,7 +589,7 @@ defaultOpts = Opt , optWriter = "" -- null for default writer , optParseRaw = False , optTableOfContents = False - , optTransforms = [] + , optBaseHeaderLevel = 1 , optTemplate = Nothing , optVariables = [] , optMetadata = M.empty @@ -671,13 +675,10 @@ options = (ReqArg (\arg opt -> case safeRead arg of - Just t | t > 0 -> do - let oldTransforms = optTransforms opt - let shift = t - 1 - return opt{ optTransforms = - headerShift shift : oldTransforms } + Just t | t > 0 && t < 6 -> do + return opt{ optBaseHeaderLevel = t } _ -> err 19 - "base-header-level must be a number > 0") + "base-header-level must be 1-5") "NUMBER") "" -- "Headers base level" -- cgit v1.2.3