Added --disable and --enable options for markdown extensions.

This commit is contained in:
John MacFarlane 2012-07-27 10:49:53 -07:00
parent b98219773b
commit 38c452b342

View file

@ -134,6 +134,7 @@ data Opt = Opt
, optDumpArgs :: Bool -- ^ Output command-line arguments
, optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
, optStrict :: Bool -- ^ Use strict markdown syntax
, optExtensions :: [(Bool, Extension)]-- ^ Extensions to enable/disable
, optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
, optWrapText :: Bool -- ^ Wrap text
, optColumns :: Int -- ^ Line length in characters
@ -187,6 +188,7 @@ defaultOpts = Opt
, optDumpArgs = False
, optIgnoreArgs = False
, optStrict = False
, optExtensions = []
, optReferenceLinks = False
, optWrapText = True
, optColumns = 72
@ -240,6 +242,24 @@ options =
(\opt -> return opt { optStrict = True } ))
"" -- "Disable markdown syntax extensions"
, Option "e" ["enable"]
(ReqArg
(\arg opt -> do
ext <- readExtension arg
return opt { optExtensions =
(True,ext) : optExtensions opt } )
"EXTENSION")
"" -- "Enable specific markdown syntax extensions"
, Option "d" ["disable"]
(ReqArg
(\arg opt -> do
ext <- readExtension arg
return opt { optExtensions =
(False,ext) : optExtensions opt } )
"EXTENSION")
"" -- "Disable specific markdown syntax extensions"
, Option "R" ["parse-raw"]
(NoArg
(\opt -> return opt { optParseRaw = True }))
@ -692,6 +712,11 @@ options =
]
readExtension :: String -> IO Extension
readExtension s = case reads ('E':'x':'t':'_':map toLower s) of
((ext,""):_) -> return ext
_ -> err 59 $ "Unknown extension: " ++ s
-- Returns usage message
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
usageMessage programName = usageInfo
@ -815,6 +840,7 @@ main = do
, optDumpArgs = dumpArgs
, optIgnoreArgs = ignoreArgs
, optStrict = strict
, optExtensions = exts
, optReferenceLinks = referenceLinks
, optWrapText = wrap
, optColumns = columns
@ -937,10 +963,16 @@ main = do
then "."
else takeDirectory (head sources)
let readerOpts = def{ readerExtensions =
if strict
then Set.empty
else Set.fromList [minBound..maxBound]
let defaultExts = if strict
then Set.empty
else Set.fromList [minBound..maxBound]
let extensions = foldl (\acc (inc,ext) -> if inc
then Set.insert ext acc
else Set.delete ext acc)
defaultExts exts
let readerOpts = def{ readerExtensions = extensions
, readerSmart = smart || (texLigatures &&
(laTeXOutput || writerName' == "context"))
, readerStandalone = standalone'
@ -969,10 +1001,7 @@ main = do
writerIgnoreNotes = False,
writerNumberSections = numberSections,
writerSectionDivs = sectionDivs,
writerExtensions = if strict
then Set.empty
else Set.fromList
[minBound..maxBound],
writerExtensions = extensions,
writerReferenceLinks = referenceLinks,
writerWrapText = wrap,
writerColumns = columns,