diff options
Diffstat (limited to 'wikicvt.py')
-rwxr-xr-x | wikicvt.py | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -17,10 +17,20 @@ import sys import getopt +import StringIO from wiki2html import * from wiki2text import * from wiki2texi import * +class DumpWikiMarkup (WikiMarkup): + def __str__(self): + if self.tree: + s = StringIO.StringIO() + self.dump(self.tree, 0, s) + return s.getvalue() + else: + return "" + def usage(code=0): print """ usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val] @@ -29,6 +39,9 @@ usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=va sys.exit(code) handlers = { + 'dump': { + 'default': DumpWikiMarkup + }, 'html': { 'default': HtmlWikiMarkup, 'wiktionary': HtmlWiktionaryMarkup @@ -51,9 +64,10 @@ def main(): debug = 0 try: - opts, args = getopt.getopt(sys.argv[1:], "d:I:hl:o:t:v", - ["debug=", "help", "lang=", "option=", - "to", "type", "input-text", "input-type", + opts, args = getopt.getopt(sys.argv[1:], "Dd:I:hl:o:t:v", + ["dump", + "debug=", "help", "lang=", "option=", + "to=", "type=", "input-text", "input-type=", "verbose" ]) except getopt.GetoptError: usage(1) @@ -77,6 +91,8 @@ def main(): input_text = True elif o in ("-d", "--debug"): debug = eval(a) + elif o in ("-D", "--dump"): + otype = 'dump' if len(args) == 1: if args[0] == '-': @@ -88,8 +104,8 @@ def main(): kwdict['lang']=lang - if handlers.has_key(otype): - if handlers[otype].has_key(itype): + if otype in handlers: + if itype in handlers[otype]: markup = handlers[otype][itype](**kwdict) markup.debug_level = debug markup.parse() |