summaryrefslogtreecommitdiffabout
path: root/wikicvt.py
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-12 20:11:40 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-07-12 20:11:40 (GMT)
commit28072898f1bd9a925d73ac187d560198d6345524 (patch) (side-by-side diff)
treea46d781fb85d9dda61fc8f68e0ba6ec43d60ce55 /wikicvt.py
parent75672b57a2d63f01d00795fe8d661d1efe7b6e8d (diff)
downloadwikitrans-28072898f1bd9a925d73ac187d560198d6345524.tar.gz
wikitrans-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') (more/less context) (ignore whitespace changes)
-rwxr-xr-xwikicvt.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/wikicvt.py b/wikicvt.py
index e61e28b..c8ca887 100755
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -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()

Return to:

Send suggestions and report system problems to the System administrator.