Browse files

only write slash for autoclose elements if format is xhtml

  • Loading branch information...
1 parent b76c770 commit 52cc7e1c78facfcf2f772aed4b100cd25c6ca462 @braddunbar braddunbar committed Jan 10, 2010
Showing with 12 additions and 14 deletions.
  1. +1 −2 pyhaml/parser.py
  2. +1 −1 test/html/basic.html
  3. +10 −11 test/test.py
View
3 pyhaml/parser.py
@@ -215,8 +215,7 @@ def open(self):
self.push('<' + self.tagname, inner=self.inner, outer=self.outer, literal=True)
self.script('_haml.attrs(%s, %s)' % (self.dict, repr(self.attrs)))
- if self.auto():
- self.no_nesting()
+ if self.auto() and self.parser.op.format == 'xhtml':
self.write('/', literal=True)
self.write('>', literal=True)
View
2 test/html/basic.html
@@ -13,7 +13,7 @@
<div class="foo">
<div id="bar">foobar!</div>
</div>
- <img/><img/><img/>
+ <img><img><img>
<a href="foo" title="bar"></a>
</body>
</html>
View
21 test/test.py
@@ -43,7 +43,7 @@ def testtag(self):
self.assertEqual('<div class="class"></div>\n', to_html(".class"))
self.assertEqual('<div class="foo bar"></div>\n', to_html(".foo.bar"))
self.assertEqual('<div id="foo" class="bar"></div>\n', to_html("#foo.bar"))
- self.assertEqual('<img id="foo" class="bar baz"/>\n', to_html("%img#foo.bar.baz"))
+ self.assertEqual('<img id="foo" class="bar baz">\n', to_html("%img#foo.bar.baz"))
def testattrs(self):
self.assertEqual('<p a="b"></p>\n', to_html("%p{ 'a':'b', 'c':None }"))
@@ -68,13 +68,10 @@ def testmulti(self):
def testhashwithnewline(self):
self.assertEqual('<p a="b" c="d">foo</p>\n', to_html("%p{'a' : 'b',\n 'c':'d'} foo"))
- self.assertEqual('<p a="b" c="d"/>\n', to_html("%p{'a' : 'b',\n 'c' : 'd'}/"))
+ self.assertEqual('<p a="b" c="d">\n', to_html("%p{'a' : 'b',\n 'c' : 'd'}/"))
def testtrim(self):
- self.assertEqual('<img/><img/><img/>\n', to_html('%img\n%img>\n%img'))
-
- def testselfclose(self):
- self.assertEqual('<sandwich/>\n', to_html('%sandwich/'))
+ self.assertEqual('<img><img><img>\n', to_html('%img\n%img>\n%img'))
def testflextabs(self):
html = '<p>\n foo\n</p>\n<q>\n bar\n <a>\n baz\n </a>\n</q>\n'
@@ -105,8 +102,8 @@ def testmultilinescript(self):
self.assertEqual('<p>multiline</p>\n', to_html("%p=('multi'\n'line')"))
def testescapeattrs(self):
- self.assertEqual('<img src="foo.com?bar&baz=&quot;&quot;"/>\n', to_html("%img{'src':'foo.com?bar&baz=\"\"'}"))
- self.assertEqual('<img foo="bar&baz"/>\n', to_html("%img{'foo':'bar&baz'}"))
+ self.assertEqual('<img src="foo.com?bar&baz=&quot;&quot;">\n', to_html("%img{'src':'foo.com?bar&baz=\"\"'}"))
+ self.assertEqual('<img foo="bar&baz">\n', to_html("%img{'foo':'bar&baz'}"))
self.assertEqual('<p foo="&quot;bar&quot;"></p>\n', to_html("%p{'foo':'\"bar\"'}"))
def testsilent(self):
@@ -192,13 +189,15 @@ def testfunc(self):
self.assertEqual('<p>\n <a></a>\n</p>\n', to_html('-def foo():\n %a\n%p\n - foo()'))
self.assertEqual('foo\n', to_html('-foo="foo"\n-def bar():\n =foo\n-bar()'))
- def testselfcloseautoclose(self):
+ def testautoclose(self):
+ self.assertEqual('<sandwich/>\n', to_html('%sandwich/', format='xhtml'))
self.assertEqual('<script src="foo"></script>\n', to_html("%script{'src':'foo'}"))
self.assertEqual('<script src="foo">fallback</script>\n', to_html("%script{'src':'foo'} fallback"))
self.assertEqual('<script src="foo">\n bar\n</script>\n', to_html("%script{'src':'foo'}\n bar"))
- self.assertEqual('<link rel="stylesheet"/>\n', to_html("%link{'rel':'stylesheet'}"))
+ self.assertEqual('<link rel="stylesheet">\n', to_html("%link{'rel':'stylesheet'}"))
self.assertEqual('<link rel="stylesheet">foo</link>\n', to_html("%link{'rel':'stylesheet'} foo"))
- self.assertEqual('<meta content="text/html"/>\n', to_html("%meta{'content':'text/html'}"))
+ self.assertEqual('<meta content="text/html">\n', to_html("%meta{'content':'text/html'}"))
+ self.assertEqual('<input type="text"/>\n', to_html("%input{ 'type':'text' }", format='xhtml'))
def testillegalnesting(self):
self.assertRaises(Exception, partial(to_html, '!!!\n %p'))

0 comments on commit 52cc7e1

Please sign in to comment.