diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-01-18 16:59:13 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-01-18 16:59:13 -0500 |
commit | da041426917b25347c5b8620698989ee17539144 (patch) | |
tree | d503036b4fade31f016c25cd74be0ee0e337612c | |
parent | 78d223ab680b1c2a2e2a915e71ea48bfb3fa7842 (diff) |
Bug fixes on use of formalpara elements.
-rw-r--r-- | source/docbook.py | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/source/docbook.py b/source/docbook.py index f442253..fa21b23 100644 --- a/source/docbook.py +++ b/source/docbook.py @@ -128,9 +128,9 @@ class DocBookConverter: self.embeds = embeds self.root = node.Root() self.exthelps = {} # texts for extended helps. - self.headingLevel = None - self.lastLevel = None - self.__currentFileName = None + self.__headingCount = 0 + self.__headingParent = None + self.__currentFileNameStack = [] def convert (self): book = self.root.appendElement('book') @@ -161,8 +161,16 @@ class DocBookConverter: else: sect.appendElement('warning').appendContent('get content from ' + src.getAttr('path')) + def __pushFileName (self, name): + if len(name) > 0 and name[0] == '/': + name = name[1:] + self.__currentFileNameStack.append(name) + + def __popFileName (self): + self.__currentFileNameStack.pop() + def __getFileName (self, xhproot): - self.__currentFileName = None + self.__currentFileNameStack = [] helpdoc = xhproot.firstChild() if helpdoc == None: return @@ -173,21 +181,19 @@ class DocBookConverter: filename = topic.firstChildByName('filename') if filename == None: return - self.__currentFileName = filename.getContent() - if len(self.__currentFileName) > 0 and self.__currentFileName[0] == '/': - self.__currentFileName = self.__currentFileName[1:] + self.__pushFileName(filename.getContent()) def __getContentFromXHP (self, xhppath, dest): + print ("get content from %s"%xhppath) xhproot = self.xhproots[xhppath] helpdoc = xhproot.firstChild() self.__getFileName(xhproot) xhpbody = helpdoc.firstChildByName('body') # parent element for the xhp 'heading' paragraphs which should start a # new sub-section when converting to docbook. - self.headingLevel = None - self.lastLevel = None - self.firstHeading = True - encodedID = globals.encodeID(self.__currentFileName) + self.__headingCount = 0 + self.__headingParent = None + encodedID = globals.encodeID(self.__currentFileNameStack[-1]) if len(encodedID) > 0: dest.setAttr('id', encodedID) for xhpelem in xhpbody.getChildNodes(): @@ -244,14 +250,14 @@ class DocBookConverter: if dest == None: return - if self.__currentFileName == None: + if len(self.__currentFileNameStack) == 0: return id = src.getAttr('id') if id == None: return - idstr = globals.encodeID(self.__currentFileName + "_" + id) + idstr = globals.encodeID(self.__currentFileNameStack[-1] + "_" + id) if dest.hasAttr('id'): dest.appendElement('anchor').setAttr('id', idstr) else: @@ -278,10 +284,14 @@ class DocBookConverter: if embed == None: dest.appendElement('warning').appendContent('take embedded content from ' + href) elif paraEmbed: + self.__pushFileName(href) para = dest.appendElement('para') self.__walkXHP(embed, para) + self.__popFileName() else: + self.__pushFileName(href) self.__walkXHP(embed, dest) + self.__popFileName() elif src.name == 'switchinline': # For now, always select the <defaultinline> child element. @@ -322,12 +332,11 @@ class DocBookConverter: elif src.name == 'link': href = src.getAttr('href') - if href.startswith('text/scalc'): - link = dest.appendElement('link') - link.setAttr('linkend', globals.encodeID(href)) - self.__walkAllChildNodes(src, link) - else: - self.__walkAllChildNodes(src, dest) + link = dest.appendElement('link') + if not href.startswith('http'): + href = globals.encodeID(href) + link.setAttr('linkend', href) + self.__walkAllChildNodes(src, link) elif src.name == 'ahelp': # this tag is used for extended tips from the application. Let's @@ -366,20 +375,23 @@ class DocBookConverter: if role == None: role = '' if role == 'heading': - level = string.atoi(src.getAttr('level')) - if self.headingLevel == None: - self.headingLevel = level + # We can't reliably use the heading levels to structure the + # document, since the levels are used inconsistently in the + # original xhp files. + if self.__headingCount == 0: + # Ignore the very first heading. + self.__headingParent = None else: - lv = level - self.headingLevel - delta = 0 - if self.lastLevel != None: - delta = self.lastLevel - level - if dest.name == 'formalpara': - dest = dest.parent + if self.__headingParent == None: + self.__headingParent = dest + else: + dest = self.__headingParent dest = dest.appendElement('formalpara') self.__maybeAddElementID(src, dest) - dest.appendElement('title').appendContent("(Level %d) %s (lv = %d; d = %d)"%(level, src.getContent(), lv, delta)) - self.lastLevel = level + title = dest.appendElement('title') + self.__walkAllChildNodes(src, title) + + self.__headingCount += 1 elif role == 'code': proglisting = dest.appendElement('programlisting') |