diff --git a/src/pandoc.hs b/src/pandoc.hs index d60f9ec12..549378ef0 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -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,