changeset 2954:c246300616f1

html content before div is not rendered, fixes #157
author RogerHaase <haaserd@gmail.com>
date Wed, 17 Jun 2015 14:12:08 -0700
parents 395ac7691975
children 5ef8b1cd2a7e
files MoinMoin/converter/_tests/test_html_in.py MoinMoin/converter/_tests/test_html_in_out.py MoinMoin/converter/html_in.py
diffstat 3 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/_tests/test_html_in.py	Wed Jun 17 13:51:48 2015 -0700
+++ b/MoinMoin/converter/_tests/test_html_in.py	Wed Jun 17 14:12:08 2015 -0700
@@ -69,16 +69,24 @@
              # <page><body><div><p>First Paragraph</p><hr /><p>Second Paragraph</p></div></html>
              '/page/body/div/separator'),
             ('<div><p>Test</p></div>',
-             # <page><body><p>Test</p></page></body>
-             '/page/body[p="Test"]'),
+             # <page><body><div><p>Test</p></div></body></page>
+             '/page/body/div[p="Test"]'),
             # Test attributes conversion
             ('<div><p class="class text" style="style text" title="title text">Test</p></div>',
-             # <page><body><p html:class="class text" html:style="style text" html:title="title text">Test</p></body></page>
-             '/page/body/p[@html:class="class text"][@html:style="style text"][@html:title="title text"][text()="Test"]'),
+             # <page><body><div><p html:class="class text" html:style="style text" html:title="title text">Test</p></div></body></page>
+             '/page/body/div/p[@html:class="class text"][@html:style="style text"][@html:title="title text"][text()="Test"]'),
             # Test id
             ('<div><p id="first">Text<strong id="second">strong</strong></p></div>',
-             # <page><body><p xml:id="first">Text<strong xml:id="second">strong</strong></p></div>
-             '/page/body/p[@xml:id="first"][text()="Text"]/strong[@xml:id="second"][text()="strong"]'),
+             # <page><body><div><p xml:id="first">Text<strong xml:id="second">strong</strong></p></div></body></page>
+             '/page/body/div/p[@xml:id="first"][text()="Text"]/strong[@xml:id="second"][text()="strong"]'),
+            # test trailing div part 1
+            ('<p>Paragraph</p><div>Div</div>',
+             # <page><body><p>paragraph</p><div>div</div></body></page>
+             '/page/body[p="Paragraph"]'),
+            # test trailing div part 2
+            ('<p>Paragraph</p><div>Div</div>',
+             # <page><body><p>paragraph</p><div>div</div></body></page>
+             '/page/body/div/text()="Div"'),
         ]
         for i in data:
             yield (self.do, ) + i
@@ -240,7 +248,7 @@
                 '/page/body/div/list[@item-label-generate="unordered"]/list-item[list-item-body="Item"]'),
             ('<div><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul></div>',
                 # <page><body><div><list item-label-generate="unordered"><list-item><list-item-body>Item 1</list-item-body></list-item><list-item><list-item-body>Item 2</list-item-body></list-item><list-item><list-item-body>Item 3</list-item-body></list-item></list></div></page></body></page>
-                '/page/body/list[@item-label-generate="unordered"][list-item[1]/list-item-body[text()="Item 1"]][list-item[2]/list-item-body[text()="Item 2"]][list-item[3]/list-item-body[text()="Item 3"]]'),
+                '/page/body/div/list[@item-label-generate="unordered"][list-item[1]/list-item-body[text()="Item 1"]][list-item[2]/list-item-body[text()="Item 2"]][list-item[3]/list-item-body[text()="Item 3"]]'),
         ]
         for i in data:
             yield (self.do, ) + i
--- a/MoinMoin/converter/_tests/test_html_in_out.py	Wed Jun 17 13:51:48 2015 -0700
+++ b/MoinMoin/converter/_tests/test_html_in_out.py	Wed Jun 17 14:12:08 2015 -0700
@@ -65,9 +65,9 @@
             ('<html><div><p>First Line<br />Second line</p></div></html>',
              '/div/div/p[1]/br'),
             ('<div><p>Test</p></div>',
-             '/div[p="Test"]'),
+             '/div/div[p="Test"]'),
             ('<div><p class="class" title="title">Test</p></div>',
-             '/div/p[@class="class"][@title="title"][text()="Test"]'),
+             '/div/div/p[@class="class"][@title="title"][text()="Test"]'),
         ]
         for i in data:
             yield(self.do, ) + i
@@ -177,12 +177,12 @@
             ('<html><div><dir><li>Item</li></dir></div></html>',
                 '/div/div/ul[li="Item"]'),
             ('<div><ul><li>Item 1</li><p>Pouet</p><li>Item 2</li><li>Item 3</li></ul></div>',
-                '/div/ul[li[1]="Item 1"][li[2]="Item 2"][li[3]="Item 3"]'),
+                '/div/div/ul[li[1]="Item 1"][li[2]="Item 2"][li[3]="Item 3"]'),
             # Test for bug with line return and spaces
             ('<div><ul><li>\n Item 1</li>\n<li>\n Item 2</li>\n<li>\n Item 3</li>\n</ul></div>',
-                '/div/ul[li[1]="\n Item 1"][li[2]="\n Item 2"][li[3]="\n Item 3"]'),
+                '/div/div/ul[li[1]="\n Item 1"][li[2]="\n Item 2"][li[3]="\n Item 3"]'),
             ('<div><ol><li>\n Item 1</li>\n<li>\n Item 2</li>\n<li>\n Item 3</li>\n</ol></div>',
-                '/div/ol[li[1]="\n Item 1"][li[2]="\n Item 2"][li[3]="\n Item 3"]'),
+                '/div/div/ol[li[1]="\n Item 1"][li[2]="\n Item 2"][li[3]="\n Item 3"]'),
         ]
         for i in data:
             yield (self.do, ) + i
@@ -207,7 +207,7 @@
                 '/div/div/table/tbody/tr/td[text()="Cell"][@rowspan="2"]'),
             # Test for bug with newline between cell
             ('<div><table>\n<tbody>\n<tr>\n<td>\n Cell 1:1</td>\n<td>\n Cell 1:2</td>\n</tr>\n<tr>\n<td>\n Cell 2:1</td>\n<td>\n Cell 2:2</td>\n</tr>\n</tbody>\n</table></div>',
-                '/div/table/tbody[tr[1][td[1]="\n Cell 1:1"][td[2]="\n Cell 1:2"]][tr[2][td[1]="\n Cell 2:1"][td[2]="\n Cell 2:2"]]'),
+                '/div/div/table/tbody[tr[1][td[1]="\n Cell 1:1"][td[2]="\n Cell 1:2"]][tr[2][td[1]="\n Cell 2:1"][td[2]="\n Cell 2:2"]]'),
         ]
         for i in data:
             yield (self.do, ) + i
--- a/MoinMoin/converter/html_in.py	Wed Jun 17 13:51:48 2015 -0700
+++ b/MoinMoin/converter/html_in.py	Wed Jun 17 14:12:08 2015 -0700
@@ -100,10 +100,10 @@
         html_tree = HTML(html_str)
 
         # We should have a root element, which will be converted as <page>
-        # for the DOM Tree. It can be <html> or <div>.
+        # for the DOM Tree.
         # NB : If <html> used, it will be converted back to <div> after
         # one roundtrip
-        if html_tree.tag.name != 'html' and html_tree.tag.name != 'div':
+        if html_tree.tag.name != 'html':
             html_str = ''.join(['<div>', html_str, '</div>'])
             html_tree = HTML(html_str)