Repository: collective/zpretty

Issue:
empty lines in tag lead to invalid attributes
when test.html is
```
<select id="workflow_action"
        name="workflow_action"
        
></select>
```
then ``$ zpretty test.html`` produces this output:
```
<select id="workflow_action"
        =""
        name="workflow_action"
></select>
```

Or general test.html:
```
<tag attr="ok"

></tag>
```

leads to:
```
<tag =""
     attr="ok"
></tag>
```

Discussion:

Patch:
diff --git a/HISTORY.md b/HISTORY.md
index b796720..b7935f6 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -3,6 +3,7 @@
 2.1.0 (unreleased)
 ------------------
 
+- Do not render a spurious `=""` when new lines appear inside a tag (Refs. #35) [ale-rt]
 - The attributes renderer knows about the element indentation
   and for indents the attributes consequently [ale-rt]
 - The ZCML element has now its custom tag templates, this simplifies the code [ale-rt]
diff --git a/zpretty/prettifier.py b/zpretty/prettifier.py
index 3e6cf5a..4468653 100644
--- a/zpretty/prettifier.py
+++ b/zpretty/prettifier.py
@@ -33,6 +33,11 @@ class ZPrettifier(object):
             for line in text.splitlines()
         )
         self.soup = self.get_soup(self.text)
+
+        # Cleanup all spurious self._newlines_marker attributes, see #35
+        for el in self.soup.find_all(attrs={self._newlines_marker: ""}):
+            el.attrs.pop(self._newlines_marker, None)
+
         self.root = self.pretty_element(self.soup, -1)
 
     def get_soup(self, text):


Test patch:
diff --git a/zpretty/tests/test_zpretty.py b/zpretty/tests/test_zpretty.py
index 0db7440..17eb548 100644
--- a/zpretty/tests/test_zpretty.py
+++ b/zpretty/tests/test_zpretty.py
@@ -152,6 +152,17 @@ class TestZpretty(TestCase):
             "<root>\n (<a></a>)\n</root>", "<root>\n  (<a></a>)\n</root>\n"
         )
 
+    def test_elements_with_new_lines(self):
+        self.assertPrettified("<root\n></root>", "<root></root>\n")
+        self.assertPrettified(
+            '<root\na="b"\n\n></root>',
+            ('<root a="b"></root>\n'),
+        )
+        self.assertPrettified(
+            '<root\na="b"\n\nc="d"></root>',
+            ('<root a="b"\n      c="d"\n></root>\n'),
+        )
+
     def test_entities(self):
         self.assertPrettified("<root>&nbsp;</root>", "<root>&nbsp;</root>\n")