Skip to content

Commit 273d90b

Browse files
committed
Added --list-* options.
Added `--list-input-formats`, `--list-output-formats`, `--list-extensions`, `--list-highlight-languages`, `--list-highlight-styles`. Removed list of highlighting languages from `--version` output. Removed list of input and output formats from default `--help` output. Closes #3173.
1 parent 3f93ca5 commit 273d90b

File tree

2 files changed

+91
-29
lines changed

2 files changed

+91
-29
lines changed

MANUAL.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ General options
262262
`markdown-pipe_tables+hard_line_breaks` is pandoc's Markdown
263263
without pipe tables and with hard line breaks. See [Pandoc's
264264
Markdown], below, for a list of extensions and
265-
their names.
265+
their names. See `--list-input-formats` and `--list-extensions`,
266+
below.
266267

267268
`-t` *FORMAT*, `-w` *FORMAT*, `--to=`*FORMAT*, `--write=`*FORMAT*
268269

@@ -297,6 +298,7 @@ General options
297298
below. Markdown syntax extensions can be individually
298299
enabled or disabled by appending `+EXTENSION` or
299300
`-EXTENSION` to the format name, as described above under `-f`.
301+
See `--list-output-formats` and `--list-extensions`, below.
300302

301303
`-o` *FILE*, `--output=`*FILE*
302304

@@ -338,6 +340,30 @@ General options
338340
: Give verbose debugging output. Currently this only has an effect
339341
with PDF output.
340342

343+
`--list-input-formats`
344+
345+
: List supported input formats, one per line.
346+
347+
`--list-output-formats`
348+
349+
: List supported output formats, one per line.
350+
351+
`--list-extensions`
352+
353+
: List supported Markdown extensions, one per line, followed
354+
by a `+` or `-` indicating whether it is enabled by default
355+
in pandoc's Markdown.
356+
357+
`--list-highlight-languages`
358+
359+
: List supported languages for syntax highlighting, one per
360+
line.
361+
362+
`--list-highlight-styles`
363+
364+
: List supported styles for syntax highlighting, one per line.
365+
See `--highlight-style`.
366+
341367
`-v`, `--version`
342368

343369
: Print version.
@@ -583,6 +609,7 @@ General writer options
583609
Options are `pygments` (the default), `kate`, `monochrome`,
584610
`espresso`, `zenburn`, `haddock`, and `tango`. For more information
585611
on syntax highlighting in pandoc, see [Syntax highlighting], below.
612+
See also `--list-highlight-styles`.
586613

587614
`-H` *FILE*, `--include-in-header=`*FILE*
588615

pandoc.hs

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ import System.Environment ( getArgs, getProgName )
4848
import System.Exit ( ExitCode (..), exitSuccess )
4949
import System.FilePath
5050
import System.Console.GetOpt
51+
import qualified Data.Set as Set
5152
import Data.Char ( toLower, toUpper )
52-
import Data.List ( delete, intercalate, isPrefixOf, isSuffixOf, sort )
53+
import Data.List ( intercalate, isPrefixOf, isSuffixOf, sort )
5354
import System.Directory ( getAppUserDataDirectory, findExecutable,
5455
doesFileExist, Permissions(..), getPermissions )
5556
import System.IO ( stdout, stderr )
@@ -88,10 +89,7 @@ copyrightMessage = intercalate "\n" [
8889
compileInfo :: String
8990
compileInfo =
9091
"\nCompiled with texmath " ++
91-
VERSION_texmath ++ ", highlighting-kate " ++ VERSION_highlighting_kate ++
92-
".\nSyntax highlighting is supported for the following languages:\n " ++
93-
wrapWords 4 78
94-
[map toLower l | l <- languages, l /= "Alert" && l /= "Alert_indent"]
92+
VERSION_texmath ++ ", highlighting-kate " ++ VERSION_highlighting_kate
9593

9694
-- | Converts a list of strings into a single string with the items printed as
9795
-- comma separated words in lines with a maximum line length.
@@ -158,6 +156,16 @@ externalFilter f args' d = do
158156
filterException e = err 83 $ "Error running filter " ++ f ++ "\n" ++
159157
show e
160158

159+
highlightingStyles :: [(String, Style)]
160+
highlightingStyles =
161+
[("pygments", pygments),
162+
("tango", tango),
163+
("espresso", espresso),
164+
("zenburn", zenburn),
165+
("kate", kate),
166+
("monochrome", monochrome),
167+
("haddock", haddock)]
168+
161169
-- | Data structure for command line options.
162170
data Opt = Opt
163171
{ optTabStop :: Int -- ^ Number of spaces per tab
@@ -517,17 +525,9 @@ options =
517525
, Option "" ["highlight-style"]
518526
(ReqArg
519527
(\arg opt -> do
520-
newStyle <- case map toLower arg of
521-
"pygments" -> return pygments
522-
"tango" -> return tango
523-
"espresso" -> return espresso
524-
"zenburn" -> return zenburn
525-
"kate" -> return kate
526-
"monochrome" -> return monochrome
527-
"haddock" -> return haddock
528-
_ -> err 39 $
529-
"Unknown style :" ++ arg
530-
return opt{ optHighlightStyle = newStyle })
528+
case lookup (map toLower arg) highlightingStyles of
529+
Just s -> return opt{ optHighlightStyle = s }
530+
Nothing -> err 39 $ "Unknown style: " ++ arg)
531531
"STYLE")
532532
"" -- "Style for highlighted code"
533533

@@ -918,11 +918,56 @@ options =
918918
let allopts = unwords (concatMap optnames options)
919919
UTF8.hPutStrLn stdout $ printf tpl allopts
920920
(unwords (map fst readers))
921-
(unwords ("pdf": map fst writers))
921+
(unwords (map fst writers))
922922
ddir
923923
exitSuccess ))
924924
"" -- "Print bash completion script"
925925

926+
, Option "" ["list-input-formats"]
927+
(NoArg
928+
(\_ -> do
929+
let readers'names = sort (map fst readers)
930+
mapM_ (UTF8.hPutStrLn stdout) readers'names
931+
exitSuccess ))
932+
""
933+
934+
, Option "" ["list-output-formats"]
935+
(NoArg
936+
(\_ -> do
937+
let writers'names = sort (map fst writers)
938+
mapM_ (UTF8.hPutStrLn stdout) writers'names
939+
exitSuccess ))
940+
""
941+
942+
, Option "" ["list-extensions"]
943+
(NoArg
944+
(\_ -> do
945+
let showExt x = drop 4 (show x) ++
946+
if x `Set.member` pandocExtensions
947+
then " +"
948+
else " -"
949+
mapM_ (UTF8.hPutStrLn stdout . showExt)
950+
([minBound..maxBound] :: [Extension])
951+
exitSuccess ))
952+
""
953+
954+
, Option "" ["list-highlight-languages"]
955+
(NoArg
956+
(\_ -> do
957+
let langs = [map toLower l | l <- languages,
958+
l /= "Alert" && l /= "Alert_indent"]
959+
mapM_ (UTF8.hPutStrLn stdout) langs
960+
exitSuccess ))
961+
""
962+
963+
, Option "" ["list-highlight-styles"]
964+
(NoArg
965+
(\_ -> do
966+
mapM_ (UTF8.hPutStrLn stdout) $
967+
map fst highlightingStyles
968+
exitSuccess ))
969+
""
970+
926971
, Option "v" ["version"]
927972
(NoArg
928973
(\_ -> do
@@ -961,17 +1006,7 @@ readMetaValue s = case decode (UTF8.fromString s) of
9611006

9621007
-- Returns usage message
9631008
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
964-
usageMessage programName = usageInfo
965-
(programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
966-
wrapWords 16 78 readers'names ++
967-
'\n' : replicate 16 ' ' ++
968-
"[* only Pandoc's JSON version of native AST]" ++ "\nOutput formats: " ++
969-
wrapWords 16 78 writers'names ++
970-
'\n' : replicate 16 ' ' ++
971-
"[** for pdf output, use latex or beamer and -o FILENAME.pdf]\nOptions:")
972-
where
973-
writers'names = sort $ "json*" : "pdf**" : delete "json" (map fst writers)
974-
readers'names = sort $ "json*" : delete "json" (map fst readers)
1009+
usageMessage programName = usageInfo (programName ++ " [OPTIONS] [FILES]")
9751010

9761011
-- Determine default reader based on source file extensions
9771012
defaultReaderName :: String -> [FilePath] -> String

0 commit comments

Comments
 (0)