Commit 3bbcb3e3 authored by john's avatar john

added support for recognizing td and th cells. Removed the habit of

cells redering <html> and <body> tags due to their being documents.
Removed annoying test print statements.
parent 453b0d45
......@@ -139,7 +139,7 @@ class StructuredTextSection(ST.StructuredTextParagraph):
kw)
# a StructuredTextTable holds StructuredTextRows
class StructuredTextTable(ST.StructuredTextDocument):
class StructuredTextTable(ST.StructuredTextParagraph):
"""
rows is a list of lists containing tuples, which
represent the columns/cells in each rows.
......@@ -148,7 +148,7 @@ class StructuredTextTable(ST.StructuredTextDocument):
"""
def __init__(self, rows, src, subs, **kw):
apply(ST.StructuredTextDocument.__init__,(self,subs),kw)
apply(ST.StructuredTextParagraph.__init__,(self,subs),kw)
self._rows = []
for row in rows:
if row:
......@@ -208,7 +208,7 @@ class StructuredTextTable(ST.StructuredTextDocument):
return self.setColorizableTexts()
# StructuredTextRow holds StructuredTextColumns
class StructuredTextRow(ST.StructuredTextDocument):
class StructuredTextRow(ST.StructuredTextParagraph):
def __init__(self,row,kw):
"""
......@@ -219,13 +219,15 @@ class StructuredTextRow(ST.StructuredTextDocument):
[('this is column one',1), ('this is column two',1)]
"""
apply(ST.StructuredTextDocument.__init__,(self,[]),kw)
apply(ST.StructuredTextParagraph.__init__,(self,[]),kw)
self._columns = []
for column in row:
self._columns.append(StructuredTextColumn(column[0],
column[1],
column[2],
column[3],
column[4],
kw))
def getColumns(self):
......@@ -249,11 +251,12 @@ class StructuredTextColumn(ST.StructuredTextParagraph):
or StructuredTextTableData.
"""
def __init__(self,text,span,align,valign,kw):
def __init__(self,text,span,align,valign,typ,kw):
apply(ST.StructuredTextParagraph.__init__,(self,text,[]),kw)
self._span = span
self._align = align
self._valign = valign
self._type = typ
def getSpan(self):
return self._span
......@@ -273,9 +276,15 @@ class StructuredTextColumn(ST.StructuredTextParagraph):
def _getValign(self):
return self.getValign()
class StructuredTextTableHeader(ST.StructuredTextDocument): pass
def getType(self):
return self._type
def _getType(self):
return self.getType()
class StructuredTextTableHeader(ST.StructuredTextParagraph): pass
class StructuredTextTableData(ST.StructuredTextDocument): pass
class StructuredTextTableData(ST.StructuredTextParagraph): pass
class StructuredTextMarkup(STDOM.Element):
......@@ -473,8 +482,8 @@ class DocumentClass:
text = paragraph.getColorizableTexts()
text = map(ST.StructuredText,text)
text = map(self.__call__,text)
#for index in range(len(text)):
# text[index].setColorizableTexts(map(self.color_text,text[index].getColorizableTexts()))
for t in range(len(text)):
text[t] = text[t].getSubparagraphs()
paragraph.setColorizableTexts(text)
paragraph.setColorizableTexts(
......@@ -517,13 +526,15 @@ class DocumentClass:
# or a cell part
for index in range(len(rows)):
tmpstr = rows[index][1:len(rows[index])-1]
if TDdivider(tmpstr) or THdivider(tmpstr):
indexes.append("divider")
if TDdivider(tmpstr):
indexes.append("TDdivider")
elif THdivider(tmpstr):
indexes.append("THdivider")
else:
indexes.append("cell")
for index in range(len(indexes)):
if indexes[index] is "divider":
if indexes[index] is "TDdivider" or indexes[index] is THdivider:
ignore = [] # reset ignore
#continue # skip dividers
......@@ -603,6 +614,40 @@ class DocumentClass:
ROWS[index][i] = (ROWS[index][i][0],C[index][i])
rows = ROWS
# label things as either TableData or
# Table header
TD = []
TH = []
all = []
for index in range(len(indexes)):
if indexes[index] is "TDdivider":
TD.append(index)
all.append(index)
if indexes[index] is "THdivider":
TH.append(index)
all.append(index)
TD = TD[1:]
dividers = all[1:]
#print "TD => ", TD
#print "TH => ", TH
#print "all => ", all, "\n"
for div in dividers:
if div in TD:
index = all.index(div)
for rowindex in range(all[index-1],all[index]):
for i in range(len(rows[rowindex])):
rows[rowindex][i] = (rows[rowindex][i][0],
rows[rowindex][i][1],
"td")
else:
index = all.index(div)
for rowindex in range(all[index-1],all[index]):
for i in range(len(rows[rowindex])):
rows[rowindex][i] = (rows[rowindex][i][0],
rows[rowindex][i][1],
"th")
# now munge the multi-line cells together
# as paragraphs
ROWS = []
......@@ -612,14 +657,14 @@ class DocumentClass:
if not COLS:
COLS = range(len(row))
for i in range(len(COLS)):
COLS[i] = ["",1]
COLS[i] = ["",1,""]
if TDdivider(row[index][0]) or THdivider(row[index][0]):
ROWS.append(COLS)
COLS = []
else:
#COLS[index][0] = COLS[index][0] + strip(row[index][0]) + "\n"
COLS[index][0] = COLS[index][0] + (row[index][0]) + "\n"
COLS[index][1] = row[index][1]
COLS[index][2] = row[index][2]
# now that each cell has been munged together,
# determine the cell's alignment.
......@@ -688,23 +733,19 @@ class DocumentClass:
else:
valign="middle"
if left[0] == right[0]:
align="center"
elif left[0] < 1:
align="left"
if left[0] < 1:
align = "left"
elif right[0] < 1:
align="right"
align = "right"
elif left[0] > 1 and right[0] > 1:
align="center"
else:
align="left"
cols.append(row[index][0],row[index][1],align,valign)
#print text, align, valign
#print text, topindent, bottomindent, left[0], right[0]
cols.append(row[index][0],row[index][1],align,valign,row[index][2])
rows.append(cols)
cols = []
return StructuredTextTable(rows,text,subs,indent=paragraph.indent)
#return StructuredTextTable(ROWS,text,subs,indent=paragraph.indent)
def doc_bullet(self, paragraph, expr = re.compile('\s*[-*o]\s+').match):
top=paragraph.getColorizableTexts()[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment