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): ...@@ -139,7 +139,7 @@ class StructuredTextSection(ST.StructuredTextParagraph):
kw) kw)
# a StructuredTextTable holds StructuredTextRows # a StructuredTextTable holds StructuredTextRows
class StructuredTextTable(ST.StructuredTextDocument): class StructuredTextTable(ST.StructuredTextParagraph):
""" """
rows is a list of lists containing tuples, which rows is a list of lists containing tuples, which
represent the columns/cells in each rows. represent the columns/cells in each rows.
...@@ -148,7 +148,7 @@ class StructuredTextTable(ST.StructuredTextDocument): ...@@ -148,7 +148,7 @@ class StructuredTextTable(ST.StructuredTextDocument):
""" """
def __init__(self, rows, src, subs, **kw): def __init__(self, rows, src, subs, **kw):
apply(ST.StructuredTextDocument.__init__,(self,subs),kw) apply(ST.StructuredTextParagraph.__init__,(self,subs),kw)
self._rows = [] self._rows = []
for row in rows: for row in rows:
if row: if row:
...@@ -208,7 +208,7 @@ class StructuredTextTable(ST.StructuredTextDocument): ...@@ -208,7 +208,7 @@ class StructuredTextTable(ST.StructuredTextDocument):
return self.setColorizableTexts() return self.setColorizableTexts()
# StructuredTextRow holds StructuredTextColumns # StructuredTextRow holds StructuredTextColumns
class StructuredTextRow(ST.StructuredTextDocument): class StructuredTextRow(ST.StructuredTextParagraph):
def __init__(self,row,kw): def __init__(self,row,kw):
""" """
...@@ -219,13 +219,15 @@ class StructuredTextRow(ST.StructuredTextDocument): ...@@ -219,13 +219,15 @@ class StructuredTextRow(ST.StructuredTextDocument):
[('this is column one',1), ('this is column two',1)] [('this is column one',1), ('this is column two',1)]
""" """
apply(ST.StructuredTextDocument.__init__,(self,[]),kw) apply(ST.StructuredTextParagraph.__init__,(self,[]),kw)
self._columns = [] self._columns = []
for column in row: for column in row:
self._columns.append(StructuredTextColumn(column[0], self._columns.append(StructuredTextColumn(column[0],
column[1], column[1],
column[2], column[2],
column[3], column[3],
column[4],
kw)) kw))
def getColumns(self): def getColumns(self):
...@@ -249,11 +251,12 @@ class StructuredTextColumn(ST.StructuredTextParagraph): ...@@ -249,11 +251,12 @@ class StructuredTextColumn(ST.StructuredTextParagraph):
or StructuredTextTableData. 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) apply(ST.StructuredTextParagraph.__init__,(self,text,[]),kw)
self._span = span self._span = span
self._align = align self._align = align
self._valign = valign self._valign = valign
self._type = typ
def getSpan(self): def getSpan(self):
return self._span return self._span
...@@ -273,9 +276,15 @@ class StructuredTextColumn(ST.StructuredTextParagraph): ...@@ -273,9 +276,15 @@ class StructuredTextColumn(ST.StructuredTextParagraph):
def _getValign(self): def _getValign(self):
return self.getValign() 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): class StructuredTextMarkup(STDOM.Element):
...@@ -473,8 +482,8 @@ class DocumentClass: ...@@ -473,8 +482,8 @@ class DocumentClass:
text = paragraph.getColorizableTexts() text = paragraph.getColorizableTexts()
text = map(ST.StructuredText,text) text = map(ST.StructuredText,text)
text = map(self.__call__,text) text = map(self.__call__,text)
#for index in range(len(text)): for t in range(len(text)):
# text[index].setColorizableTexts(map(self.color_text,text[index].getColorizableTexts())) text[t] = text[t].getSubparagraphs()
paragraph.setColorizableTexts(text) paragraph.setColorizableTexts(text)
paragraph.setColorizableTexts( paragraph.setColorizableTexts(
...@@ -517,13 +526,15 @@ class DocumentClass: ...@@ -517,13 +526,15 @@ class DocumentClass:
# or a cell part # or a cell part
for index in range(len(rows)): for index in range(len(rows)):
tmpstr = rows[index][1:len(rows[index])-1] tmpstr = rows[index][1:len(rows[index])-1]
if TDdivider(tmpstr) or THdivider(tmpstr): if TDdivider(tmpstr):
indexes.append("divider") indexes.append("TDdivider")
elif THdivider(tmpstr):
indexes.append("THdivider")
else: else:
indexes.append("cell") indexes.append("cell")
for index in range(len(indexes)): for index in range(len(indexes)):
if indexes[index] is "divider": if indexes[index] is "TDdivider" or indexes[index] is THdivider:
ignore = [] # reset ignore ignore = [] # reset ignore
#continue # skip dividers #continue # skip dividers
...@@ -603,6 +614,40 @@ class DocumentClass: ...@@ -603,6 +614,40 @@ class DocumentClass:
ROWS[index][i] = (ROWS[index][i][0],C[index][i]) ROWS[index][i] = (ROWS[index][i][0],C[index][i])
rows = ROWS 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 # now munge the multi-line cells together
# as paragraphs # as paragraphs
ROWS = [] ROWS = []
...@@ -612,14 +657,14 @@ class DocumentClass: ...@@ -612,14 +657,14 @@ class DocumentClass:
if not COLS: if not COLS:
COLS = range(len(row)) COLS = range(len(row))
for i in range(len(COLS)): for i in range(len(COLS)):
COLS[i] = ["",1] COLS[i] = ["",1,""]
if TDdivider(row[index][0]) or THdivider(row[index][0]): if TDdivider(row[index][0]) or THdivider(row[index][0]):
ROWS.append(COLS) ROWS.append(COLS)
COLS = [] COLS = []
else: else:
#COLS[index][0] = COLS[index][0] + strip(row[index][0]) + "\n"
COLS[index][0] = COLS[index][0] + (row[index][0]) + "\n" COLS[index][0] = COLS[index][0] + (row[index][0]) + "\n"
COLS[index][1] = row[index][1] COLS[index][1] = row[index][1]
COLS[index][2] = row[index][2]
# now that each cell has been munged together, # now that each cell has been munged together,
# determine the cell's alignment. # determine the cell's alignment.
...@@ -688,23 +733,19 @@ class DocumentClass: ...@@ -688,23 +733,19 @@ class DocumentClass:
else: else:
valign="middle" valign="middle"
if left[0] == right[0]: if left[0] < 1:
align="center" align = "left"
elif left[0] < 1:
align="left"
elif right[0] < 1: elif right[0] < 1:
align="right" align = "right"
elif left[0] > 1 and right[0] > 1:
align="center"
else: else:
align="left" align="left"
cols.append(row[index][0],row[index][1],align,valign) cols.append(row[index][0],row[index][1],align,valign,row[index][2])
#print text, align, valign
#print text, topindent, bottomindent, left[0], right[0]
rows.append(cols) rows.append(cols)
cols = [] cols = []
return StructuredTextTable(rows,text,subs,indent=paragraph.indent) 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): def doc_bullet(self, paragraph, expr = re.compile('\s*[-*o]\s+').match):
top=paragraph.getColorizableTexts()[0] 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