| @@ -42,21 +42,21 @@ class Node(StringMixIn): | |||||
| :py:meth:`__unicode__` must be overridden. It should return a ``unicode`` | :py:meth:`__unicode__` must be overridden. It should return a ``unicode`` | ||||
| or (``str`` in py3k) representation of the node. If the node contains | or (``str`` in py3k) representation of the node. If the node contains | ||||
| :py:class:`~.Wikicode` objects inside of it, :py:meth:`__iternodes__` | |||||
| should be overridden to yield tuples of (``wikicode``, | |||||
| ``node_in_wikicode``) for each node in each wikicode, as well as the node | |||||
| itself (``None``, ``self``). If the node is printable, :py:meth:`__strip__` | |||||
| should be overridden to return the printable version of the node - it does | |||||
| not have to be a string, but something that can be converted to a string | |||||
| with ``str()``. Finally, :py:meth:`__showtree__` can be overridden to build | |||||
| a nice tree representation of the node, if desired, for | |||||
| :py:class:`~.Wikicode` objects inside of it, :py:meth:`__children__` | |||||
| should be a generator that iterates over them. If the node is printable | |||||
| (shown when the page is rendered), :py:meth:`__strip__` should return its | |||||
| printable version, stripping out any formatting marks. It does not have to | |||||
| return a string, but something that can be converted to a string with | |||||
| ``str()``. Finally, :py:meth:`__showtree__` can be overridden to build a | |||||
| nice tree representation of the node, if desired, for | |||||
| :py:meth:`~.Wikicode.get_tree`. | :py:meth:`~.Wikicode.get_tree`. | ||||
| """ | """ | ||||
| def __unicode__(self): | def __unicode__(self): | ||||
| raise NotImplementedError() | raise NotImplementedError() | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| def __children__(self): | |||||
| return # Funny generator-that-yields-nothing syntax | |||||
| yield | |||||
| def __strip__(self, normalize, collapse): | def __strip__(self, normalize, collapse): | ||||
| return None | return None | ||||
| @@ -42,13 +42,10 @@ class Argument(Node): | |||||
| return start + "|" + str(self.default) + "}}}" | return start + "|" + str(self.default) + "}}}" | ||||
| return start + "}}}" | return start + "}}}" | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| for child in getter(self.name): | |||||
| yield self.name, child | |||||
| def __children__(self): | |||||
| yield self.name | |||||
| if self.default is not None: | if self.default is not None: | ||||
| for child in getter(self.default): | |||||
| yield self.default, child | |||||
| yield self.default | |||||
| def __strip__(self, normalize, collapse): | def __strip__(self, normalize, collapse): | ||||
| if self.default is not None: | if self.default is not None: | ||||
| @@ -44,13 +44,10 @@ class ExternalLink(Node): | |||||
| return "[" + str(self.url) + "]" | return "[" + str(self.url) + "]" | ||||
| return str(self.url) | return str(self.url) | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| for child in getter(self.url): | |||||
| yield self.url, child | |||||
| def __children__(self): | |||||
| yield self.url | |||||
| if self.title is not None: | if self.title is not None: | ||||
| for child in getter(self.title): | |||||
| yield self.title, child | |||||
| yield self.title | |||||
| def __strip__(self, normalize, collapse): | def __strip__(self, normalize, collapse): | ||||
| if self.brackets: | if self.brackets: | ||||
| @@ -39,10 +39,8 @@ class Heading(Node): | |||||
| def __unicode__(self): | def __unicode__(self): | ||||
| return ("=" * self.level) + str(self.title) + ("=" * self.level) | return ("=" * self.level) + str(self.title) + ("=" * self.level) | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| for child in getter(self.title): | |||||
| yield self.title, child | |||||
| def __children__(self): | |||||
| yield self.title | |||||
| def __strip__(self, normalize, collapse): | def __strip__(self, normalize, collapse): | ||||
| return self.title.strip_code(normalize, collapse) | return self.title.strip_code(normalize, collapse) | ||||
| @@ -70,23 +70,17 @@ class Tag(Node): | |||||
| result += "</" + str(self.closing_tag) + ">" | result += "</" + str(self.closing_tag) + ">" | ||||
| return result | return result | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| def __children__(self): | |||||
| if not self.wiki_markup: | if not self.wiki_markup: | ||||
| for child in getter(self.tag): | |||||
| yield self.tag, child | |||||
| yield self.tag | |||||
| for attr in self.attributes: | for attr in self.attributes: | ||||
| for child in getter(attr.name): | |||||
| yield attr.name, child | |||||
| if attr.value: | |||||
| for child in getter(attr.value): | |||||
| yield attr.value, child | |||||
| yield attr.name | |||||
| if attr.value is not None: | |||||
| yield attr.value | |||||
| if self.contents: | if self.contents: | ||||
| for child in getter(self.contents): | |||||
| yield self.contents, child | |||||
| yield self.contents | |||||
| if not self.self_closing and not self.wiki_markup and self.closing_tag: | if not self.self_closing and not self.wiki_markup and self.closing_tag: | ||||
| for child in getter(self.closing_tag): | |||||
| yield self.closing_tag, child | |||||
| yield self.closing_tag | |||||
| def __strip__(self, normalize, collapse): | def __strip__(self, normalize, collapse): | ||||
| if self.contents and is_visible(self.tag): | if self.contents and is_visible(self.tag): | ||||
| @@ -51,16 +51,12 @@ class Template(Node): | |||||
| else: | else: | ||||
| return "{{" + str(self.name) + "}}" | return "{{" + str(self.name) + "}}" | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| for child in getter(self.name): | |||||
| yield self.name, child | |||||
| def __children__(self): | |||||
| yield self.name | |||||
| for param in self.params: | for param in self.params: | ||||
| if param.showkey: | if param.showkey: | ||||
| for child in getter(param.name): | |||||
| yield param.name, child | |||||
| for child in getter(param.value): | |||||
| yield param.value, child | |||||
| yield param.name | |||||
| yield param.value | |||||
| def __showtree__(self, write, get, mark): | def __showtree__(self, write, get, mark): | ||||
| write("{{") | write("{{") | ||||
| @@ -41,13 +41,10 @@ class Wikilink(Node): | |||||
| return "[[" + str(self.title) + "|" + str(self.text) + "]]" | return "[[" + str(self.title) + "|" + str(self.text) + "]]" | ||||
| return "[[" + str(self.title) + "]]" | return "[[" + str(self.title) + "]]" | ||||
| def __iternodes__(self, getter): | |||||
| yield None, self | |||||
| for child in getter(self.title): | |||||
| yield self.title, child | |||||
| def __children__(self): | |||||
| yield self.title | |||||
| if self.text is not None: | if self.text is not None: | ||||
| for child in getter(self.text): | |||||
| yield self.text, child | |||||
| yield self.text | |||||
| def __strip__(self, normalize, collapse): | def __strip__(self, normalize, collapse): | ||||
| if self.text is not None: | if self.text is not None: | ||||