Commits

Luke Plant committed d352d8f

Implemented 'row clearing' div

Comments (0)

Files changed (2)

semanticeditor/tests.py

 
     def test_columns_1(self):
         html = "<h1>1</h1><p>para 1</p><h1>2</h1><h1>3</h1>"
-        outh = "<div class=\"row2col\"><div class=\"col\"><div><h1>1</h1><div><p>para 1</p></div></div></div><div class=\"col\"><div><h1>2</h1></div><div><h1>3</h1></div></div></div>"
+        outh = "<div class=\"row2col\"><div class=\"col\"><div><h1>1</h1><div><p>para 1</p></div></div></div><div class=\"col\"><div><h1>2</h1></div><div><h1>3</h1></div></div><div class=\"rowclear\" /></div>"
         self.assertEqual(outh, format_html(html, {'1':[NEWROW],
                                                   '2':[NEWCOL]}))
 
             "<div class=\"col\">" \
             "<div><h2>2.2</h2></div>" \
             "</div>" \
-            "</div>" \
+            "<div class=\"rowclear\" /></div>" \
             "<div class=\"row2col\">" \
             "<div class=\"col\">" \
             "<div><h2>2.3</h2></div>" \
             "<div class=\"col\">" \
             "<div><h2>2.4</h2></div>" \
             "</div>" \
-            "</div>" \
+            "<div class=\"rowclear\" /></div>" \
             "</div>" \
             "<div class=\"row2col\">" \
             "<div class=\"col\">" \
             "<div class=\"col\">" \
             "<div><h1>4</h1></div>" \
             "</div>" \
-            "</div>"
+            "<div class=\"rowclear\" /></div>"
         self.assertEqual(outh, format_html(html, {'2.1':[NEWROW],
                                                   '2.2':[NEWCOL],
                                                   '2.3':[NEWROW],
               "<div class=\"col\">" \
                 "<div><h1>2</h1></div>" \
               "</div>" \
-            "</div>" \
+            "<div class=\"rowclear\" /></div>" \
             "<div class=\"row1col\">" \
               "<div class=\"col\">" \
                 "<div><h1>3</h1>" \
                     "<div class=\"col\">" \
                       "<div><p>P3</p></div>" \
                     "</div>" \
-                  "</div>" \
+                  "<div class=\"rowclear\" /></div>" \
                 "</div>" \
               "</div>" \
-            "</div>" \
+            "<div class=\"rowclear\" /></div>" \
             "<div class=\"row1col\">" \
               "<div class=\"col\">" \
                 "<div><h1>4</h1></div>" \
               "</div>" \
-            "</div>"
+            "<div class=\"rowclear\" /></div>"
 
         actualhtml = format_html(html, pres)
 

semanticeditor/utils/presentation.py

 COLUMNCLASS = 'col'
 ROWCLASSRE = re.compile('^row(\d+)col$')
 ROWCLASS = 'row%dcol'
+ROWCLEARCLASS = 'rowclear'
 
 # The number of chars we trim block level elements to.
 BLOCK_LEVEL_TRIM_LENGTH = 20
             styleinfo[name].add(NEWCOL)
 
     _add_rows_and_columns(root, known_nodes, styleinfo)
-    # TODO: due to HTML/CSS quirks, we may need to add an empty <div
+    # Due to HTML/CSS quirks, we add an empty <div
     # class="rowclear"> after every <div class="row">
+    for n in root.getiterator():
+        if n.tag == 'div' and ROWCLASSRE.match(n.get('class','')) is not None:
+            newdiv = ET.Element('div')
+            newdiv.set('class', ROWCLEARCLASS)
+            n.append(newdiv)
 
 def _find_child_with_column_structure(node, known_nodes, styleinfo):
     for n in node.getiterator():
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.