Commits

"Lui...@gmail.com>"  committed dfbe654

inserting {{MyWikiPage}} in middle of paragraph now makes valid html. inclusion of one-line page is shown inline. fixes #28

  • Participants
  • Parent commits d966ee4

Comments (0)

Files changed (2)

File MoinMoin/converter/_tests/test_include.py

         page1 = MoinWiki.create(u'page1')
 
         page1._render_data()
+
+    def test_IncludeOfSingleLinePage(self):
+        # issue #28
+        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"')
+
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Single line')
+        rendered = MoinWiki.create(u'page1')._render_data()
+        assert 'Content of page2 is "Single line"' in rendered
+
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Two\n\nParagraphs')
+        rendered = MoinWiki.create(u'page1')._render_data()
+        assert '<p>Two</p>' in rendered
+        assert '<p>Paragraphs</p>' in rendered
+
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"this text contains ''italic'' string")
+        rendered = MoinWiki.create(u'page1')._render_data()
+        assert 'Content of page2 is "this text contains' in rendered
+        assert '<em>italic</em>' in rendered
+
+        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is\n\n{{page2}}')
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Single Line")
+        rendered = MoinWiki.create(u'page1')._render_data()
+        assert 'Content of page2 is</p>' in rendered
+        assert '<p>Single Line</p>' in rendered
+
+        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"')
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| table || cell ||")
+        rendered = MoinWiki.create(u'page1')._render_data()
+        assert 'Content of page2 is "</p>' in rendered
+        assert '<table>' in rendered
+        assert rendered.count('<table>') == 1
+
+        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"')
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| this || has ||\n|| two || rows ||")
+        rendered = MoinWiki.create(u'page1')._render_data()
+        assert 'Content of page2 is "</p>' in rendered
+        assert '<table>' in rendered
+        assert rendered.count('<table>') == 1

File MoinMoin/converter/include.py

 from __future__ import absolute_import, division
 
 from emeraldtree import ElementTree as ET
-import re
+import re, types
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
                 return result
 
-            for i in xrange(len(elem)):
+            container = [elem]
+
+            i = 0
+            while i < len(elem):
                 child = elem[i]
                 if isinstance(child, ET.Node):
                     ret = self.recurse(child, page_href)
                     if ret:
-                        elem[i] = ret
+                        if type(ret) == types.ListType:
+                            elem[i:i+1] = ret
+                        elif elem.tag.name == 'p':
+                            try:
+                                body = ret[0][0]
+                                if len(body) == 1 and body[0].tag.name == 'p':
+                                    single = True
+                                else:
+                                    single = False
+                            except AttributeError:
+                                single = False
+
+                            if single:
+                                # content inside P is inserted directly into this P
+                                p = ret[0][0][0]
+                                elem[i:i+1] = [p[k] for k in xrange(len(p))]
+                            else:
+                                # P is closed and element is inserted after
+                                pa = ET.Element(html.p)
+                                pa[0:i] = elem[0:i]
+                                ret[0:1] = elem[i:i+1]
+                                elem[0:i+1] = []
+                                container[0:0] = [pa, ret]
+                                i = 0
+                        else:
+                            elem[i] = ret
+                i += 1
+            if len(container) > 1:
+                return container
+
         finally:
             self.stack.pop()