diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2009-12-24 18:59:54 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2009-12-24 18:59:54 -0500 |
commit | b332db0cae43eaf3b8b7c0a2d78597f909732e8d (patch) | |
tree | 06733ae58b3f3526690bab8c4b4036282dad4f07 | |
parent | 293dcc2cd2bad26920319d290ffa1b2013d6163c (diff) |
More coverage of xhp to docbook conversion.
-rw-r--r-- | source/docbook.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/source/docbook.py b/source/docbook.py index 0bbad6c..7da564d 100644 --- a/source/docbook.py +++ b/source/docbook.py @@ -102,6 +102,19 @@ class DocBookConverter: 'sect4': 'sect5' } + elemIgnored = { + 'comment': 1, + 'history': 1 + } + + itemTypeTable = { + 'keycode': 'keycode', + 'productname': 'productname', + 'input': 'userinput', + 'literal': 'literal', + 'menuitem': 'guimenuitem' + } + @staticmethod def startSubSection (src): if DocBookConverter.elemRelTable.has_key(src.name): @@ -174,7 +187,7 @@ class DocBookConverter: if len(content) > 0: dest.appendContent(content) - elif src.name == 'comment' or src.name == 'history': + elif DocBookConverter.elemIgnored.has_key(src.name): # we can ignore these elements. pass elif src.name == 'embed': @@ -195,7 +208,11 @@ class DocBookConverter: elif src.name == 'item': # an <item> element has a 'type' attribute that specifies how this # text span should be formatted. - dest.appendContent(src.getContent() + " (%s)"%src.getAttr('type')) + itemType = src.getAttr('type') + if DocBookConverter.itemTypeTable.has_key(itemType): + dest.appendElement(DocBookConverter.itemTypeTable[itemType]).appendContent(src.getContent()) + else: + dest.appendElement('emphasis').appendContent("{%s: %s}"%(itemType, src.getContent())) elif src.name == 'list': # type may be 'unordered' (bulleted) or 'ordered' (numbered). @@ -228,7 +245,9 @@ class DocBookConverter: elif src.name == 'paragraph': # normal paragraph content. role = src.getAttr('role') - if role != None and role == 'heading': + if role == None: + role = '' + if role == 'heading': # finish the current sub-section, adn start a new one. if self.headingParent == None: self.headingParent = dest @@ -236,13 +255,16 @@ class DocBookConverter: title = elem.appendElement('title') self.__walkAllChildNodes(src, title) return elem + elif role == 'code': + proglisting = dest.appendElement('programlisting') + self.__walkAllChildNodes(src, proglisting) else: paraName = 'para' if role != None: if role == 'note': paraName = 'note' elif role == 'warning': - paraName = 'warning' + paraName = 'caution' elif role == 'tip': paraName = 'tip' para = dest.appendElement(paraName) @@ -269,6 +291,11 @@ class DocBookConverter: tab = dest.appendElement('entry') self.__walkAllChildNodes(src, tab) + elif src.name == 'br': + # if this occurs inside a <para> element, end the current paragraph, + # and start a new one at the same level. + if dest.name == 'para': + dest = dest.parent.appendElement('para') else: # unhandled element. My work is done when these elements go away. dest.appendElement('warning').appendContent("unhandled element '%s'"%src.name) |