diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-12 23:11:40 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-12 23:11:40 +0300 |
commit | 28072898f1bd9a925d73ac187d560198d6345524 (patch) | |
tree | a46d781fb85d9dda61fc8f68e0ba6ec43d60ce55 /wikicvt.py | |
parent | 75672b57a2d63f01d00795fe8d661d1efe7b6e8d (diff) | |
download | wit-28072898f1bd9a925d73ac187d560198d6345524.tar.gz wit-28072898f1bd9a925d73ac187d560198d6345524.tar.bz2 |
Improve tag handling and debugging
* wikimarkup.py: Rewrite tag recognition.
Implement dump method.
* wikicvt.py: New options -D (--dump), and -t dump
* wiki2html.py (input_tag): Remove method
(str_tag): Change handling of tags
* wiki2texi.py: Likewise.
* wiki2text.py: Likewise.
Diffstat (limited to 'wikicvt.py')
-rwxr-xr-x | wikicvt.py | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -14,24 +14,37 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. 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] [--input-type=INTYPE] [--type=OUTTYPE] [--help] [--verbose] file """ % (sys.argv[0]) sys.exit(code) handlers = { + 'dump': { + 'default': DumpWikiMarkup + }, 'html': { 'default': HtmlWikiMarkup, 'wiktionary': HtmlWiktionaryMarkup }, 'text': { 'default': TextWikiMarkup, @@ -48,15 +61,16 @@ def main(): otype = 'html' lang = "pl" kwdict = {} 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) for o, a in opts: if o in ("-h", "--help"): @@ -74,25 +88,27 @@ def main(): if val != '': kwdict[kw] = val elif o == "--input-text": 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] == '-': kwdict['file'] = sys.stdin else: kwdict['filename'] = args[0] else: usage(1) 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() print str(markup) exit(0) else: |