script-publish.py: More newlines in the output HTML source
authorW. Trevor King <wking@tremily.us>
Sun, 13 Jan 2013 14:52:32 +0000 (09:52 -0500)
committerW. Trevor King <wking@tremily.us>
Sun, 13 Jan 2013 14:52:32 +0000 (09:52 -0500)
These newlines don't affect the rendered HTML, but they make the HTML
source more readable.  The `previous_tail` bit keeps unstyled text
from clobbering newlines that were attached to a preceding <br />.

posts/script/script-publish.py

index d1c74ba8a69db50d3276365fde8f6c30fa461943..622098d18436cb1de0148bd462f5fa2e416cd650 100755 (executable)
@@ -639,8 +639,9 @@ class ControlParser (object):
                     except ValueError as e:
                         raise ValueError(repr(chunk.text)) from e
                 else:
+                    previous_tail = previous.tail or ''
                     try:
-                        previous.tail = chunk.text
+                        previous.tail = previous_tail + chunk.text
                     except ValueError as e:
                         raise ValueError(repr(chunk.text)) from e
             elif isinstance(chunk, ControlCodeMatch):
@@ -677,7 +678,7 @@ class ScriptParser (object):
         body.append(pre)
         tree = _etree.ElementTree(element=html)
         html.text = html.tail = head.text = head.tail = '\n'
-        body.text = body.tail = '\n'
+        body.text = body.tail = pre.tail = '\n'
         return tree
 
     def process(self, source, output=None):