changeset 2873:04f6ef180588

add === lines to moinwiki tables to indicate thead, tfoot
author RogerHaase <haaserd@gmail.com>
date Tue, 06 Jan 2015 13:18:21 -0700
parents 77705f581c68
children 148240936936
files MoinMoin/converter/_tests/test_moinwiki_in.py MoinMoin/converter/html_out.py MoinMoin/converter/moinwiki_in.py MoinMoin/static/css/common.css
diffstat 4 files changed, 38 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/_tests/test_moinwiki_in.py	Tue Jan 06 11:30:55 2015 -0700
+++ b/MoinMoin/converter/_tests/test_moinwiki_in.py	Tue Jan 06 13:18:21 2015 -0700
@@ -211,6 +211,8 @@
                 '<page><body><table><table-body><table-row><table-cell>Row 1</table-cell></table-row><table-row><table-cell>Row 2</table-cell></table-row></table-body></table></body></page>'),
             (u'||Cell 1.1||Cell 1.2||\n||Cell 2.1||Cell 2.2||\n',
                 '<page><body><table><table-body><table-row><table-cell>Cell 1.1</table-cell><table-cell>Cell 1.2</table-cell></table-row><table-row><table-cell>Cell 2.1</table-cell><table-cell>Cell 2.2</table-cell></table-row></table-body></table></body></page>'),
+            (u'||Header||\n===\n||Body||\n=====\n||Footer||',
+                '<page><body><table><table-body><table-row><table-cell>Header</table-cell></table-row></table-body><table-body><table-row><table-cell>Body</table-cell></table-row></table-body><table-body><table-row><table-cell>Footer</table-cell></table-row></table-body></table></body></page>'),
         ]
         for i in data:
             yield (self.do, ) + i
--- a/MoinMoin/converter/html_out.py	Tue Jan 06 11:30:55 2015 -0700
+++ b/MoinMoin/converter/html_out.py	Tue Jan 06 13:18:21 2015 -0700
@@ -544,10 +544,20 @@
     def visit_moinpage_table(self, elem):
         attrib = Attributes(elem).convert()
         ret = html.table(attrib=attrib)
-        for item in elem:
+        for idx, item in enumerate(elem):
             tag = None
             if item.tag.uri == moin_page:
-                if item.tag.name == 'table-body':
+                if len(elem) > 1 and item.tag.name == 'table-body':
+                    # moinwiki_in converts "||header||\n===\n||body||\n===\n||footer||" into multiple table-body's
+                    if idx == 0:
+                        # make first table-body into header
+                        tag = html.thead
+                    elif len(elem) > 2 and idx == len(elem) - 1:
+                        # make last table-body into footer
+                        tag = html.tfoot
+                    else:
+                        tag = html.tbody
+                elif item.tag.name == 'table-body':
                     tag = html.tbody
                 elif item.tag.name == 'table-header':
                     tag = html.thead
--- a/MoinMoin/converter/moinwiki_in.py	Tue Jan 06 11:30:55 2015 -0700
+++ b/MoinMoin/converter/moinwiki_in.py	Tue Jan 06 13:18:21 2015 -0700
@@ -317,6 +317,16 @@
         $
     """
 
+    header_footer_separator = r"""
+        ^
+        \s*
+        (?P<table_sep>
+            ===+
+        )
+        \s*
+        $
+    """
+
     def block_table_repl(self, iter_content, stack, table):
         stack.clear()
 
@@ -329,10 +339,16 @@
         for line in iter_content:
             match = self.table_re.match(line)
             if not match:
-                # Allow the mainloop to take care of the line after a list.
-                iter_content.push(line)
-                break
-
+                match = self.header_footer_re.match(line)
+                if match:
+                    # this is a header/body/footer separator: create multiple table_body's, html_out will convert to thead, tbody or tfoot
+                    stack.pop()
+                    stack.push(moin_page.table_body())
+                    continue
+                else:
+                    # Allow the mainloop to take care of the line after table end.
+                    iter_content.push(line)
+                    break
             self.block_table_row(match.group('table'), stack, element)
 
     def block_table_row(self, content, stack, table):
@@ -960,6 +976,8 @@
 
         stack.pop_name('table-cell')
 
+    header_footer_re = re.compile(header_footer_separator, re.X)
+
     # Block elements
     block = (
         block_line,
--- a/MoinMoin/static/css/common.css	Tue Jan 06 11:30:55 2015 -0700
+++ b/MoinMoin/static/css/common.css	Tue Jan 06 13:18:21 2015 -0700
@@ -191,6 +191,8 @@
 tr > th { border: 1px solid #4e7da9; background-color: #81bbf2; text-align: left; color: #000; }
 tr > td { border: 1px solid #4e7da9; }
 td p { margin: 0; padding: 0; }
+#moin-content table > thead { background-color: #81bbf2; }
+#moin-content table > tfoot { background-color: #81bbf2; }
 
 /* zebra table styling */
 table.zebra { width: 98%; }