diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-11-27 13:41:14 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-11-27 13:41:14 +0200 |
commit | cfe445a92d11e206c63a4e73588cced065df104f (patch) | |
tree | 990d914bab3e5ef64b3d88f09c68ac1af1f05d9e | |
parent | 6508bd65f006d7ca1cdaa0d177341ddfe72334a9 (diff) | |
download | wikitrans-cfe445a92d11e206c63a4e73588cced065df104f.tar.gz wikitrans-cfe445a92d11e206c63a4e73588cced065df104f.tar.bz2 |
Minor changes.
* wiki2text.py: The constructor keyword argument markup allows to
inhibit any markup
* wikicvt.py: New command line option -o (--option).
Admit - as input file name.
-rw-r--r-- | wiki2text.py | 18 | ||||
-rw-r--r-- | wikicvt.py | 25 |
2 files changed, 34 insertions, 9 deletions
diff --git a/wiki2text.py b/wiki2text.py index 66563a6..51a7853 100644 --- a/wiki2text.py +++ b/wiki2text.py @@ -24,9 +24,15 @@ class TextWikiMarkup (WikiMarkup): A (general-purpose Wiki->Text translator class. """ + # Output width width = 80 - num = 0 + # Do not show references. references = False + # Provide a minimum markup + markup = True + + # Number of current element in the environment + num = 0 def __init__(self, *args, **keywords): WikiMarkup.__init__(self, *args, **keywords) @@ -34,6 +40,8 @@ class TextWikiMarkup (WikiMarkup): self.width = keywords['width'] if 'refs' in keywords: self.references = keywords['refs'] + if 'markup' in keywords: + self.markup = keywords['markup'] def target(self, t): (qual,sep,tgt) = t.partition(':') @@ -86,10 +94,14 @@ class TextWikiMarkup (WikiMarkup): return self.xref(self.fmtok(tok[2], env), self.fmtok(tok[1], env)) def str_it(self, tok, env): - return "_" + self.fmtok(tok[1], env) + "_" + if self.markup: + return "_" + self.fmtok(tok[1], env) + "_" + return self.fmtok(tok[1], env); def str_bold(self, tok, env): - return self.fmtok(tok[1], env).upper() + if self.markup: + return self.fmtok(tok[1], env).upper() + return self.fmtok(tok[1], env); def str_hdr(self, tok, env): level = tok[1] @@ -21,16 +21,21 @@ from wiki2html import * from wiki2text import * def usage(code=0): - print "usage: " + sys.argv[0] + "[-hvt] [-l lang] [--lang=lang] [--text] [--help] [--verbose] file\n" + print """ +usage: %s [-hvt] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val] + [--text] [--help] [--verbose] file +""" % (sys.argv[0]) sys.exit(code) def main(): verbose_flag = 0 html = 1 lang = "pl" + kwdict = {} try: - opts, args = getopt.getopt(sys.argv[1:], "hl:tv", - ["help", "lang=", "text", "verbose" ]) + opts, args = getopt.getopt(sys.argv[1:], "hl:o:tv", + ["help", "lang=", "option=", + "text", "verbose" ]) except getopt.GetoptError: usage(1) @@ -43,16 +48,24 @@ def main(): html = 0 if o in ("-l", "--lang"): lang = a + if o in ("-o", "--option"): + (kw,sep,val) = a.partition('=') + if val != '': + kwdict[kw] = eval(val) if len(args) == 1: - inputfilename = args[0] + if args[0] == '-': + kwdict['file'] = sys.stdin + else: + kwdict['filename'] = args[0] else: usage(1) + kwdict['lang']=lang if html: - markup = HtmlWiktionaryMarkup(filename=inputfilename, lang=lang) + markup = HtmlWiktionaryMarkup(**kwdict) else: - markup = TextWiktionaryMarkup(filename=inputfilename, lang=lang) + markup = TextWiktionaryMarkup(**kwdict) markup.parse() print str(markup) |