script-publish.py: Drop empty text chunks
authorW. Trevor King <wking@tremily.us>
Sun, 13 Jan 2013 14:42:10 +0000 (09:42 -0500)
committerW. Trevor King <wking@tremily.us>
Sun, 13 Jan 2013 14:42:10 +0000 (09:42 -0500)
Firefox 10.0.11 was having trouble with:

  <span style="..." />

Which, instead of being a no-op, was changing the default styling of
every element after that tag.

posts/script/script-publish.py

index b772e8bae2783c524621350d9508809c57d6cbab..bd64c81425b897aefffbb6fb2c81aa66f2984b78 100755 (executable)
@@ -492,6 +492,15 @@ class ControlParser (object):
                 i += 1
         return chunks
 
+    def _drop_empty_text(self, chunks):
+        i = 0
+        while i < len(chunks):
+            if isinstance(chunks[i], str) and not chunks[i]:
+                chunks.pop(i)
+            else:
+                i += 1
+        return chunks
+
     def _remove_operating_system_commands(self, chunks):
         i = 0
         while i < len(chunks):
@@ -600,6 +609,7 @@ class ControlParser (object):
         chunks = self._drop_clear_line(chunks)
         chunks = self._collapse_adjacent_newlines(chunks)
         chunks = self._merge_adjacent_text(chunks)
+        chunks = self._drop_empty_text(chunks)
         chunks = self._style_chunks(chunks)
         previous = element
         last_chunk = None