markdown: nitmd have a --to option (`html` and `md` for now)
authorJean Privat <jean@pryen.org>
Mon, 17 Aug 2015 19:12:07 +0000 (15:12 -0400)
committerJean Privat <jean@pryen.org>
Mon, 17 Aug 2015 19:12:07 +0000 (15:12 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/markdown/nitmd.nit

index 0e1cd00..0a1002f 100644 (file)
 module nitmd
 
 import markdown
+import decorators
 
 import opts
 
 var options = new OptionContext
 var opt_help = new OptionBool("Show this help.", "-h", "-?", "--help")
 options.add_option(opt_help)
+var opt_to = new OptionString("Specify output format (html, md, man)", "-t", "--to")
+options.add_option(opt_to)
 
 options.parse(args)
 if options.rest.length != 1 then
@@ -41,4 +44,13 @@ var md = ifs.read_all
 ifs.close
 
 var processor = new MarkdownProcessor
+var to = opt_to.value
+if to == null or to == "html" then
+       # Noop
+else if to == "md" then
+       processor.emitter.decorator = new MdDecorator
+else
+       print "Unknown output format: {to}"
+       exit 1
+end
 print processor.process(md)