diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2009-12-24 01:53:01 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2009-12-24 01:53:01 -0500 |
commit | af4f5ef75456be351a811c88337a6a1489978a24 (patch) | |
tree | 12efa74ebd86afab7e64b36fb5bbfa7f40618075 | |
parent | 51bc548ec8c73dd22bfa020e3173da287fe5257a (diff) |
Turned common code block into a method.
-rw-r--r-- | source/docbook.py | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/source/docbook.py b/source/docbook.py index a9edad6..4a94bca 100644 --- a/source/docbook.py +++ b/source/docbook.py @@ -161,6 +161,10 @@ class DocBookConverter: return self.embeds[filename][id] return None + def __walkAllChildNodes (self, src, dest): + for child in src.getChildNodes(): + dest = self.__walkXHP(child, dest) + def __walkXHP (self, src, dest): if src.nodeType == node.NodeType.Content: @@ -201,31 +205,28 @@ class DocBookConverter: lnode = dest.appendElement('orderedlist') if lnode != None: - for child in src.getChildNodes(): - self.__walkXHP(child, lnode) + self.__walkAllChildNodes(src, lnode) else: dest.appendElement('warning').appendContent('unknown list type: ' + listType) elif src.name == 'listitem': # This one needs no translation. li = dest.appendElement('listitem') - for child in src.getChildNodes(): - self.__walkXHP(child, li) + self.__walkAllChildNodes(src, li) elif src.name == 'link': - for child in src.getChildNodes(): - self.__walkXHP(child, dest) + self.__walkAllChildNodes(src, dest) elif src.name == 'paragraph': # normal paragraph content. role = src.getAttr('role') if role != None and role == 'heading': # finish the current sub-section, adn start a new one. - title = src.getContent() if self.headingParent == None: self.headingParent = dest elem = DocBookConverter.startSubSection(self.headingParent) - elem.appendElement('title').appendContent(title) + title = elem.appendElement('title') + self.__walkAllChildNodes(src, title) return elem else: paraName = 'para' @@ -237,8 +238,7 @@ class DocBookConverter: elif role == 'tip': paraName = 'tip' para = dest.appendElement(paraName) - for child in src.getChildNodes(): - self.__walkXHP(child, para) + self.__walkAllChildNodes(src, para) elif src.name == 'emph': dest.appendElement('emphasis').appendContent(src.getContent()) @@ -247,23 +247,19 @@ class DocBookConverter: # we can probably just ignore this element for now. Section elements # are used only to group multiple elements together. Same with # the variable elements. - for child in src.getChildNodes(): - dest = self.__walkXHP(child, dest) + self.__walkAllChildNodes(src, dest) elif src.name == 'table': tab = dest.appendElement('table').appendElement('tgroup').appendElement('tbody') - for child in src.getChildNodes(): - self.__walkXHP(child, tab) + self.__walkAllChildNodes(src, tab) elif src.name == 'tablerow': tab = dest.appendElement('row') - for child in src.getChildNodes(): - self.__walkXHP(child, tab) + self.__walkAllChildNodes(src, tab) elif src.name == 'tablecell': tab = dest.appendElement('entry') - for child in src.getChildNodes(): - self.__walkXHP(child, tab) + self.__walkAllChildNodes(src, tab) else: # unhandled element. My work is done when these elements go away. |