Georg Brandl avatar Georg Brandl committed c1ba2d6

#259: HTML table rows now have even/odd CSS classes to enable "Zebra styling".

Comments (0)

Files changed (2)

 
 * Added :confval:`man_show_urls` config value.
 
+* #259: HTML table rows now have even/odd CSS classes to enable
+  "Zebra styling".
+
 
 Release 1.0.7 (in development)
 ==============================

sphinx/writers/html.py

 
         BaseTranslator.depart_title(self, node)
 
+    # overwritten to add even/odd classes
+
+    def visit_table(self, node):
+        self._table_row_index = 0
+        return BaseTranslator.visit_table(self, node)
+
+    def visit_row(self, node):
+        self._table_row_index += 1
+        if self._table_row_index % 2 == 0:
+            node['classes'].append('row-even')
+        else:
+            node['classes'].append('row-odd')
+        self.body.append(self.starttag(node, 'tr', ''))
+        node.column = 0
+
+    def visit_field_list(self, node):
+        self._fieldlist_row_index = 0
+        return BaseTranslator.visit_field_list(self, node)
+
+    def visit_field(self, node):
+        self._fieldlist_row_index += 1
+        if self._fieldlist_row_index % 2 == 0:
+            node['classes'].append('field-even')
+        else:
+            node['classes'].append('field-odd')
+        self.body.append(self.starttag(node, 'tr', '', CLASS='field'))
+
     def unknown_visit(self, node):
         raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.