summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wikitrans/wikimarkup.py48
1 files changed, 25 insertions, 23 deletions
diff --git a/wikitrans/wikimarkup.py b/wikitrans/wikimarkup.py
index d199335..0ce0e15 100644
--- a/wikitrans/wikimarkup.py
+++ b/wikitrans/wikimarkup.py
@@ -177,47 +177,26 @@ class WikiMarkupParser(object):
177 debug_level = 0 177 debug_level = 0
178 178
179 def dprint(self, lev, fmt, *argv): 179 def dprint(self, lev, fmt, *argv):
180 """If current debug level is greater than or equal to lev, print *argv 180 """If current debug level is greater than or equal to lev, print *argv
181 according to format. 181 according to format.
182 """ 182 """
183 if self.debug_level >= lev: 183 if self.debug_level >= lev:
184 for l in (fmt % argv).split('\n'): 184 for l in (fmt % argv).split('\n'):
185 print("[DEBUG] %s" % l) 185 print("[DEBUG] %s" % l)
186 186
187 inline_delims = [ "''", "'''", "[", "]", "[[", "]]", "{{", "}}", "|" ] 187 inline_delims = [ "''", "'''", "[", "]", "[[", "]]", "{{", "}}", "|" ]
188 188
189 token_class = { 189 token_class = {}
190 'NIL': WikiNode, 190
191 'NL': WikiNode,
192 'OTAG': WikiTagNode,
193 'CTAG': WikiTagNode,
194 'TAG': WikiTagNode,
195 'DELIM': WikiDelimNode,
196 'TEXT': WikiTextNode,
197 'PRE': WikiContentNode,
198 'PARA': WikiSeqNode,
199 'BAR': WikiNode,
200 'SEQ': WikiSeqNode,
201 'IND': WikiIndNode,
202 'REF': WikiRefNode,
203 'TMPL': WikiSeqNode,
204 'IT': WikiSeqNode,
205 'BOLD': WikiSeqNode,
206 'ELT': WikiEltNode,
207 'ENV': WikiEnvNode,
208 'LINK': WikiSeqNode,
209 'HDR': WikiHdrNode
210 }
211
212 def _new_node(self, **kwarg): 191 def _new_node(self, **kwarg):
213 return self.token_class[kwarg['type']](self, **kwarg) 192 return self.token_class[kwarg['type']](self, **kwarg)
214 193
215 def tokread(self): 194 def tokread(self):
216 """Read next token from the input. Return it as a subclass of WikiNode.""" 195 """Read next token from the input. Return it as a subclass of WikiNode."""
217 line = None 196 line = None
218 pos = 0 197 pos = 0
219 while 1: 198 while 1:
220 if (not line or pos == len(line)): 199 if (not line or pos == len(line)):
221 try: 200 try:
222 line = self.input() 201 line = self.input()
223 pos = 0 202 pos = 0
@@ -983,24 +962,47 @@ class WikiMarkup(WikiMarkupParser):
983 Specifies source language. Default is 'en'. This variable can be 962 Specifies source language. Default is 'en'. This variable can be
984 referred to as '%(lang)s' in the keyword arguments below. 963 referred to as '%(lang)s' in the keyword arguments below.
985 html_base=URL 964 html_base=URL
986 Base URL for cross-references. Default is 965 Base URL for cross-references. Default is
987 'http://%(lang)s.wikipedia.org/wiki/' 966 'http://%(lang)s.wikipedia.org/wiki/'
988 image_base=URL 967 image_base=URL
989 Base URL for images. Default is 968 Base URL for images. Default is
990 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf' 969 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf'
991 media_base=URL 970 media_base=URL
992 Base URL for media files. Default is 971 Base URL for media files. Default is
993 'http://www.mediawiki.org/xml/export-0.3' 972 'http://www.mediawiki.org/xml/export-0.3'
994 """ 973 """
974 self.token_class = {
975 'NIL': WikiNode,
976 'NL': WikiNode,
977 'OTAG': WikiTagNode,
978 'CTAG': WikiTagNode,
979 'TAG': WikiTagNode,
980 'DELIM': WikiDelimNode,
981 'TEXT': WikiTextNode,
982 'PRE': WikiContentNode,
983 'PARA': WikiSeqNode,
984 'BAR': WikiNode,
985 'SEQ': WikiSeqNode,
986 'IND': WikiIndNode,
987 'REF': WikiRefNode,
988 'TMPL': WikiSeqNode,
989 'IT': WikiSeqNode,
990 'BOLD': WikiSeqNode,
991 'ELT': WikiEltNode,
992 'ENV': WikiEnvNode,
993 'LINK': WikiSeqNode,
994 'HDR': WikiHdrNode
995 }
996
995 for kw in keywords: 997 for kw in keywords:
996 if kw == 'file': 998 if kw == 'file':
997 self.file = keywords[kw] 999 self.file = keywords[kw]
998 elif kw == 'filename': 1000 elif kw == 'filename':
999 self.file = open(keywords[kw]) 1001 self.file = open(keywords[kw])
1000 elif kw == 'text': 1002 elif kw == 'text':
1001 self.text = keywords[kw].split("\n") 1003 self.text = keywords[kw].split("\n")
1002 elif kw == 'lang': 1004 elif kw == 'lang':
1003 self.lang = keywords[kw] 1005 self.lang = keywords[kw]
1004 elif kw == 'html_base': 1006 elif kw == 'html_base':
1005 self.html_base = keywords[kw] 1007 self.html_base = keywords[kw]
1006 elif kw == 'image_base': 1008 elif kw == 'image_base':

Return to:

Send suggestions and report system problems to the System administrator.