diff options
-rw-r--r-- | wikitrans/wikimarkup.py | 48 |
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 @@ -181,39 +181,18 @@ class WikiMarkupParser(object): according to format. """ if self.debug_level >= lev: for l in (fmt % argv).split('\n'): print("[DEBUG] %s" % l) inline_delims = [ "''", "'''", "[", "]", "[[", "]]", "{{", "}}", "|" ] - token_class = { - 'NIL': WikiNode, - 'NL': WikiNode, - 'OTAG': WikiTagNode, - 'CTAG': WikiTagNode, - 'TAG': WikiTagNode, - 'DELIM': WikiDelimNode, - 'TEXT': WikiTextNode, - 'PRE': WikiContentNode, - 'PARA': WikiSeqNode, - 'BAR': WikiNode, - 'SEQ': WikiSeqNode, - 'IND': WikiIndNode, - 'REF': WikiRefNode, - 'TMPL': WikiSeqNode, - 'IT': WikiSeqNode, - 'BOLD': WikiSeqNode, - 'ELT': WikiEltNode, - 'ENV': WikiEnvNode, - 'LINK': WikiSeqNode, - 'HDR': WikiHdrNode - } - + token_class = {} + def _new_node(self, **kwarg): return self.token_class[kwarg['type']](self, **kwarg) def tokread(self): """Read next token from the input. Return it as a subclass of WikiNode.""" line = None pos = 0 while 1: @@ -987,16 +966,39 @@ class WikiMarkup(WikiMarkupParser): 'http://%(lang)s.wikipedia.org/wiki/' image_base=URL Base URL for images. Default is 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf' media_base=URL Base URL for media files. Default is 'http://www.mediawiki.org/xml/export-0.3' """ + self.token_class = { + 'NIL': WikiNode, + 'NL': WikiNode, + 'OTAG': WikiTagNode, + 'CTAG': WikiTagNode, + 'TAG': WikiTagNode, + 'DELIM': WikiDelimNode, + 'TEXT': WikiTextNode, + 'PRE': WikiContentNode, + 'PARA': WikiSeqNode, + 'BAR': WikiNode, + 'SEQ': WikiSeqNode, + 'IND': WikiIndNode, + 'REF': WikiRefNode, + 'TMPL': WikiSeqNode, + 'IT': WikiSeqNode, + 'BOLD': WikiSeqNode, + 'ELT': WikiEltNode, + 'ENV': WikiEnvNode, + 'LINK': WikiSeqNode, + 'HDR': WikiHdrNode + } + for kw in keywords: if kw == 'file': self.file = keywords[kw] elif kw == 'filename': self.file = open(keywords[kw]) elif kw == 'text': self.text = keywords[kw].split("\n") elif kw == 'lang': |