Permalink
Browse files

Table converter: first column is bold when "vertical" class is used. #6

  • Loading branch information...
1 parent 9e488f9 commit f9e526f7cb6d02fb40ab2b8fa7c4569695f05b0c @jone jone committed May 2, 2012
View
10 ftw/pdfgenerator/html2latex/subconverters/table.py
@@ -387,6 +387,10 @@ def is_last_column(self):
columns = self.table_converter.columns
return columns[-1] == self
+ def is_first_column(self):
+ columns = self.table_converter.columns
+ return columns[0] == self
+
class LatexRow(object):
"""
@@ -602,6 +606,12 @@ def is_head_cell(self):
elif self.dom_cell.tagName.lower() == 'th':
# cell is a <th>
return True
+
+ elif 'vertical' in self.table_converter.get_css_classes() \
+ and self.columns[0].is_first_column():
+ # "vertical" class makes first column to be "head" cells.
+ return True
+
else:
# not a head cell
return False
View
48 ftw/pdfgenerator/tests/test_html2latex_table_subconverter.py
@@ -767,6 +767,54 @@ def test_listing_css_class(self):
self.assertEqual(self.convert(html), latex)
+ def test_vertical_css_class_makes_first_column_bold(self):
+ html = '\n'.join((
+ r'<table class="no-page-break vertical">',
+ r' <colgroup>',
+ r' <col width="50%" />'
+ r' <col width="25%" />'
+ r' <col width="25%" />'
+ r' </colgroup>',
+ r' <thead>',
+ r' <tr>',
+ r' <th colspan="3">heading</th>',
+ r' </tr>',
+ r' </thead>',
+ r' <tbody>',
+ r' <tr>',
+ r' <td>content 1A</td>',
+ r' <td rowspan="2">content 1/2 B</td>',
+ r' <td>content 1C</td>',
+ r' </tr>',
+ r' <tr>',
+ r' <td>content 2A</td>',
+ r' <td>content 2C</td>',
+ r' </tr>',
+ r' </tbody>',
+ r'</table>'))
+
+ latex = '\n'.join((
+ r'\begin{tabular}{p{0.5\linewidth}p{0.25\linewidth}' + \
+ 'p{0.25\linewidth}}',
+
+ r'\multicolumn{3}{p{1.0\linewidth}}{\textbf{heading}} \\',
+
+ r'\multicolumn{1}{p{0.5\linewidth}}' + \
+ r'{\textbf{content 1A}} & ' + \
+ r'\multirow{2}{0.25\textwidth}{content 1/2 B} & ' + \
+ r'\multicolumn{1}{p{0.25\linewidth}}{content 1C} \\',
+
+ r'\multicolumn{1}{p{0.5\linewidth}}' + \
+ r'{\textbf{content 2A}} & ' + \
+ r' & ' + \
+ r'\multicolumn{1}{p{0.25\linewidth}}{content 2C} \\',
+
+ r'\end{tabular}',
+ r''
+ ))
+
+ self.assertEqual(self.convert(html), latex)
+
def test_border_classes(self):
html = '\n'.join((
r'<table class="no-page-break">',

0 comments on commit f9e526f

Please sign in to comment.