summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-01-17 02:23:25 -0500
committerKohei Yoshida <kyoshida@novell.com>2010-01-17 02:23:25 -0500
commit27132676fa298e4d89386d97f1a5c61365ca5357 (patch)
treebb16ed57c5a70e149e8278f26a66f9657045411a
parent6ae5bf9b676df24f417c4e29385d6b54376c3475 (diff)
Convert table structure the proper way.
Docbook's table structure must specify the number of columns, or a conversion to html fails.
-rw-r--r--source/docbook.py47
1 files changed, 36 insertions, 11 deletions
diff --git a/source/docbook.py b/source/docbook.py
index 51c69ca..c73e2bf 100644
--- a/source/docbook.py
+++ b/source/docbook.py
@@ -1,4 +1,4 @@
-import sys
+import sys, string
import globals, node
class FilePathSorter:
@@ -180,6 +180,40 @@ class DocBookConverter:
for child in src.getChildNodes():
dest = self.__walkXHP(child, dest)
+ def __walkTable (self, src, dest):
+ tgrp = dest.appendElement('informaltable').appendElement('tgroup')
+ # <tgroup> element needs 'cols' attribute to specify column size.
+ tbody = tgrp.appendElement('tbody')
+ totalColSize = 0
+ for trow in src.getChildNodes():
+ if trow.nodeType != node.NodeType.Element or trow.name != 'tablerow':
+ continue
+
+ row = tbody.appendElement('row')
+ colSize = 0
+ for tcell in trow.getChildNodes():
+ if tcell.nodeType != node.NodeType.Element or tcell.name != 'tablecell':
+ continue
+ entry = row.appendElement('entry')
+ colspan = tcell.getAttr('colspan')
+ colspanNum = 1
+ if colspan != None:
+ try:
+ colspanNum = string.atoi(colspan)
+ if colspanNum < 1:
+ colspanNum = 1
+ except ValueError:
+ pass
+
+ colSize += colspanNum
+ self.__walkAllChildNodes(tcell, entry)
+
+ if colSize > totalColSize:
+ totalColSize = colSize
+
+ tgrp.setAttr('cols', totalColSize)
+
+
def __walkXHP (self, src, dest):
if src.nodeType == node.NodeType.Content:
@@ -323,16 +357,7 @@ class DocBookConverter:
self.__walkAllChildNodes(src, dest)
elif src.name == 'table':
- tab = dest.appendElement('table').appendElement('tgroup').appendElement('tbody')
- self.__walkAllChildNodes(src, tab)
-
- elif src.name == 'tablerow':
- tab = dest.appendElement('row')
- self.__walkAllChildNodes(src, tab)
-
- elif src.name == 'tablecell':
- tab = dest.appendElement('entry')
- self.__walkAllChildNodes(src, tab)
+ self.__walkTable(src, dest)
elif src.name == 'br':
# if this occurs inside a <para> element, end the current paragraph,