summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2008-11-27 13:41:14 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2008-11-27 13:41:14 +0200
commitcfe445a92d11e206c63a4e73588cced065df104f (patch)
tree990d914bab3e5ef64b3d88f09c68ac1af1f05d9e
parent6508bd65f006d7ca1cdaa0d177341ddfe72334a9 (diff)
downloadwikitrans-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.py18
-rw-r--r--wikicvt.py25
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):
24 A (general-purpose Wiki->Text translator class. 24 A (general-purpose Wiki->Text translator class.
25 """ 25 """
26 26
27 # Output width
27 width = 80 28 width = 80
28 num = 0 29 # Do not show references.
29 references = False 30 references = False
31 # Provide a minimum markup
32 markup = True
33
34 # Number of current element in the environment
35 num = 0
30 36
31 def __init__(self, *args, **keywords): 37 def __init__(self, *args, **keywords):
32 WikiMarkup.__init__(self, *args, **keywords) 38 WikiMarkup.__init__(self, *args, **keywords)
@@ -34,6 +40,8 @@ class TextWikiMarkup (WikiMarkup):
34 self.width = keywords['width'] 40 self.width = keywords['width']
35 if 'refs' in keywords: 41 if 'refs' in keywords:
36 self.references = keywords['refs'] 42 self.references = keywords['refs']
43 if 'markup' in keywords:
44 self.markup = keywords['markup']
37 45
38 def target(self, t): 46 def target(self, t):
39 (qual,sep,tgt) = t.partition(':') 47 (qual,sep,tgt) = t.partition(':')
@@ -86,10 +94,14 @@ class TextWikiMarkup (WikiMarkup):
86 return self.xref(self.fmtok(tok[2], env), self.fmtok(tok[1], env)) 94 return self.xref(self.fmtok(tok[2], env), self.fmtok(tok[1], env))
87 95
88 def str_it(self, tok, env): 96 def str_it(self, tok, env):
89 return "_" + self.fmtok(tok[1], env) + "_" 97 if self.markup:
98 return "_" + self.fmtok(tok[1], env) + "_"
99 return self.fmtok(tok[1], env);
90 100
91 def str_bold(self, tok, env): 101 def str_bold(self, tok, env):
92 return self.fmtok(tok[1], env).upper() 102 if self.markup:
103 return self.fmtok(tok[1], env).upper()
104 return self.fmtok(tok[1], env);
93 105
94 def str_hdr(self, tok, env): 106 def str_hdr(self, tok, env):
95 level = tok[1] 107 level = tok[1]
diff --git a/wikicvt.py b/wikicvt.py
index 418ec26..d45a61f 100644
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -21,16 +21,21 @@ from wiki2html import *
21from wiki2text import * 21from wiki2text import *
22 22
23def usage(code=0): 23def usage(code=0):
24 print "usage: " + sys.argv[0] + "[-hvt] [-l lang] [--lang=lang] [--text] [--help] [--verbose] file\n" 24 print """
25usage: %s [-hvt] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val]
26 [--text] [--help] [--verbose] file
27""" % (sys.argv[0])
25 sys.exit(code) 28 sys.exit(code)
26 29
27def main(): 30def main():
28 verbose_flag = 0 31 verbose_flag = 0
29 html = 1 32 html = 1
30 lang = "pl" 33 lang = "pl"
34 kwdict = {}
31 try: 35 try:
32 opts, args = getopt.getopt(sys.argv[1:], "hl:tv", 36 opts, args = getopt.getopt(sys.argv[1:], "hl:o:tv",
33 ["help", "lang=", "text", "verbose" ]) 37 ["help", "lang=", "option=",
38 "text", "verbose" ])
34 except getopt.GetoptError: 39 except getopt.GetoptError:
35 usage(1) 40 usage(1)
36 41
@@ -43,16 +48,24 @@ def main():
43 html = 0 48 html = 0
44 if o in ("-l", "--lang"): 49 if o in ("-l", "--lang"):
45 lang = a 50 lang = a
51 if o in ("-o", "--option"):
52 (kw,sep,val) = a.partition('=')
53 if val != '':
54 kwdict[kw] = eval(val)
46 55
47 if len(args) == 1: 56 if len(args) == 1:
48 inputfilename = args[0] 57 if args[0] == '-':
58 kwdict['file'] = sys.stdin
59 else:
60 kwdict['filename'] = args[0]
49 else: 61 else:
50 usage(1) 62 usage(1)
51 63
64 kwdict['lang']=lang
52 if html: 65 if html:
53 markup = HtmlWiktionaryMarkup(filename=inputfilename, lang=lang) 66 markup = HtmlWiktionaryMarkup(**kwdict)
54 else: 67 else:
55 markup = TextWiktionaryMarkup(filename=inputfilename, lang=lang) 68 markup = TextWiktionaryMarkup(**kwdict)
56 69
57 markup.parse() 70 markup.parse()
58 print str(markup) 71 print str(markup)

Return to:

Send suggestions and report system problems to the System administrator.