Luke Plant avatar Luke Plant committed 8c81bd0

Fixed bug in extract presentation

Comments (0)

Files changed (2)

semanticeditor/tests.py

         pres2, html2 = extract_presentation(html)
         self.assertEqual(pres, pres2)
 
+    def test_extract_3(self):
+        # Tests some other boundary conditions e.g. 1 column row,
+        # multiple sections within the column.
+        html = """
+<div><h1>1</h1><div class="row1col"><div class="col"><div><h2>1.1</h2></div><div><h2>1.2</h2></div></div></div></div>
+"""
+        pres = {'1': set(),
+                '1.1':set([NEWROW]),
+                '1.2': set(),
+                }
+        pres2, html2 = extract_presentation(html)
+        self.assertEqual(pres, pres2)

semanticeditor/utils/presentation.py

         # Parent/grandparent of section - newcol/newrow
         p = get_parent(root, section_node)
         if p is not None and p.tag == 'div':
-            classes = _get_classes_for_node(p)
-            if COLUMNCLASS in classes:
-                pres[name].add(NEWCOL)
-            gp = get_parent(root, p)
-            if gp is not None and gp.tag == 'div':
-                if any(ROWCLASSRE.match(c) is not None for c in _get_classes_for_node(gp)) \
-                        and get_index(gp, p) == 0:
-                    pres[name].add(NEWROW)
-                    pres[name].discard(NEWCOL) # not technically necessary
+            # We only care if section_node is the first child of the div
+            if get_index(p, section_node) == 0:
+                classes = _get_classes_for_node(p)
+                if COLUMNCLASS in classes:
+                    pres[name].add(NEWCOL)
+                gp = get_parent(root, p)
+                if gp is not None and gp.tag == 'div':
+                    if any(ROWCLASSRE.match(c) is not None for c in _get_classes_for_node(gp)) \
+                            and get_index(gp, p) == 0:
+                        pres[name].add(NEWROW)
+                        pres[name].discard(NEWCOL) # for tidiness, not technically necessary
 
     _strip_presentation(root)
     out_html = _html_extract(root)
 
     return (pres, out_html)
-
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.