git.iko.soy/typeable/pandoc
on master help sign in
Added --disable and --enable options for markdown extensions.
commit38c452b3426404e322c005f35ab02ff543ad1717 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 27 Jul 2012, 10:49 (14 years ago) parentb982197
1 file changed+37−8
src/pandoc.hs+37−8
src/pandoc.hs+37−8
@@ -134,6 +134,7 @@ data Opt = Opt
134134 , optDumpArgs :: Bool -- ^ Output command-line arguments
135135 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
136136 , optStrict :: Bool -- ^ Use strict markdown syntax
137+ , optExtensions :: [(Bool, Extension)]-- ^ Extensions to enable/disable
137138 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
138139 , optWrapText :: Bool -- ^ Wrap text
139140 , optColumns :: Int -- ^ Line length in characters
@@ -187,6 +188,7 @@ defaultOpts = Opt
187188 , optDumpArgs = False
188189 , optIgnoreArgs = False
189190 , optStrict = False
191+ , optExtensions = []
190192 , optReferenceLinks = False
191193 , optWrapText = True
192194 , optColumns = 72
@@ -240,6 +242,24 @@ options =
240242 (\opt -> return opt { optStrict = True } ))
241243 "" -- "Disable markdown syntax extensions"
242244
245+ , Option "e" ["enable"]
246+ (ReqArg
247+ (\arg opt -> do
248+ ext <- readExtension arg
249+ return opt { optExtensions =
250+ (True,ext) : optExtensions opt } )
251+ "EXTENSION")
252+ "" -- "Enable specific markdown syntax extensions"
253+
254+ , Option "d" ["disable"]
255+ (ReqArg
256+ (\arg opt -> do
257+ ext <- readExtension arg
258+ return opt { optExtensions =
259+ (False,ext) : optExtensions opt } )
260+ "EXTENSION")
261+ "" -- "Disable specific markdown syntax extensions"
262+
243263 , Option "R" ["parse-raw"]
244264 (NoArg
245265 (\opt -> return opt { optParseRaw = True }))
@@ -692,6 +712,11 @@ options =
692712
693713 ]
694714
715+readExtension :: String -> IO Extension
716+readExtension s = case reads ('E':'x':'t':'_':map toLower s) of
717+ ((ext,""):_) -> return ext
718+ _ -> err 59 $ "Unknown extension: " ++ s
719+
695720-- Returns usage message
696721usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
697722usageMessage programName = usageInfo
@@ -815,6 +840,7 @@ main = do
815840 , optDumpArgs = dumpArgs
816841 , optIgnoreArgs = ignoreArgs
817842 , optStrict = strict
843+ , optExtensions = exts
818844 , optReferenceLinks = referenceLinks
819845 , optWrapText = wrap
820846 , optColumns = columns
@@ -937,10 +963,16 @@ main = do
937963 then "."
938964 else takeDirectory (head sources)
939965
940− let readerOpts = def{ readerExtensions =
941− if strict
942− then Set.empty
943− else Set.fromList [minBound..maxBound]
966+ let defaultExts = if strict
967+ then Set.empty
968+ else Set.fromList [minBound..maxBound]
969+
970+ let extensions = foldl (\acc (inc,ext) -> if inc
971+ then Set.insert ext acc
972+ else Set.delete ext acc)
973+ defaultExts exts
974+
975+ let readerOpts = def{ readerExtensions = extensions
944976 , readerSmart = smart || (texLigatures &&
945977 (laTeXOutput || writerName' == "context"))
946978 , readerStandalone = standalone'
@@ -969,10 +1001,7 @@ main = do
9691001 writerIgnoreNotes = False,
9701002 writerNumberSections = numberSections,
9711003 writerSectionDivs = sectionDivs,
972− writerExtensions = if strict
973− then Set.empty
974− else Set.fromList
975− [minBound..maxBound],
1004+ writerExtensions = extensions,
9761005 writerReferenceLinks = referenceLinks,
9771006 writerWrapText = wrap,
9781007 writerColumns = columns,