Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

only write slash for autoclose elements if format is xhtml

  • Loading branch information...
commit 52cc7e1c78facfcf2f772aed4b100cd25c6ca462 1 parent b76c770
brad dunbar braddunbar authored

Showing 3 changed files with 12 additions and 14 deletions. Show diff stats Hide diff stats

  1. +1 2  pyhaml/parser.py
  2. +1 1  test/html/basic.html
  3. +10 11 test/test.py
3  pyhaml/parser.py
@@ -215,8 +215,7 @@ def open(self):
215 215 self.push('<' + self.tagname, inner=self.inner, outer=self.outer, literal=True)
216 216 self.script('_haml.attrs(%s, %s)' % (self.dict, repr(self.attrs)))
217 217
218   - if self.auto():
219   - self.no_nesting()
  218 + if self.auto() and self.parser.op.format == 'xhtml':
220 219 self.write('/', literal=True)
221 220
222 221 self.write('>', literal=True)
2  test/html/basic.html
@@ -13,7 +13,7 @@
13 13 <div class="foo">
14 14 <div id="bar">foobar!</div>
15 15 </div>
16   - <img/><img/><img/>
  16 + <img><img><img>
17 17 <a href="foo" title="bar"></a>
18 18 </body>
19 19 </html>
21 test/test.py
@@ -43,7 +43,7 @@ def testtag(self):
43 43 self.assertEqual('<div class="class"></div>\n', to_html(".class"))
44 44 self.assertEqual('<div class="foo bar"></div>\n', to_html(".foo.bar"))
45 45 self.assertEqual('<div id="foo" class="bar"></div>\n', to_html("#foo.bar"))
46   - self.assertEqual('<img id="foo" class="bar baz"/>\n', to_html("%img#foo.bar.baz"))
  46 + self.assertEqual('<img id="foo" class="bar baz">\n', to_html("%img#foo.bar.baz"))
47 47
48 48 def testattrs(self):
49 49 self.assertEqual('<p a="b"></p>\n', to_html("%p{ 'a':'b', 'c':None }"))
@@ -68,13 +68,10 @@ def testmulti(self):
68 68
69 69 def testhashwithnewline(self):
70 70 self.assertEqual('<p a="b" c="d">foo</p>\n', to_html("%p{'a' : 'b',\n 'c':'d'} foo"))
71   - self.assertEqual('<p a="b" c="d"/>\n', to_html("%p{'a' : 'b',\n 'c' : 'd'}/"))
  71 + self.assertEqual('<p a="b" c="d">\n', to_html("%p{'a' : 'b',\n 'c' : 'd'}/"))
72 72
73 73 def testtrim(self):
74   - self.assertEqual('<img/><img/><img/>\n', to_html('%img\n%img>\n%img'))
75   -
76   - def testselfclose(self):
77   - self.assertEqual('<sandwich/>\n', to_html('%sandwich/'))
  74 + self.assertEqual('<img><img><img>\n', to_html('%img\n%img>\n%img'))
78 75
79 76 def testflextabs(self):
80 77 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):
105 102 self.assertEqual('<p>multiline</p>\n', to_html("%p=('multi'\n'line')"))
106 103
107 104 def testescapeattrs(self):
108   - self.assertEqual('<img src="foo.com?bar&baz=&quot;&quot;"/>\n', to_html("%img{'src':'foo.com?bar&baz=\"\"'}"))
109   - self.assertEqual('<img foo="bar&baz"/>\n', to_html("%img{'foo':'bar&baz'}"))
  105 + self.assertEqual('<img src="foo.com?bar&baz=&quot;&quot;">\n', to_html("%img{'src':'foo.com?bar&baz=\"\"'}"))
  106 + self.assertEqual('<img foo="bar&baz">\n', to_html("%img{'foo':'bar&baz'}"))
110 107 self.assertEqual('<p foo="&quot;bar&quot;"></p>\n', to_html("%p{'foo':'\"bar\"'}"))
111 108
112 109 def testsilent(self):
@@ -192,13 +189,15 @@ def testfunc(self):
192 189 self.assertEqual('<p>\n <a></a>\n</p>\n', to_html('-def foo():\n %a\n%p\n - foo()'))
193 190 self.assertEqual('foo\n', to_html('-foo="foo"\n-def bar():\n =foo\n-bar()'))
194 191
195   - def testselfcloseautoclose(self):
  192 + def testautoclose(self):
  193 + self.assertEqual('<sandwich/>\n', to_html('%sandwich/', format='xhtml'))
196 194 self.assertEqual('<script src="foo"></script>\n', to_html("%script{'src':'foo'}"))
197 195 self.assertEqual('<script src="foo">fallback</script>\n', to_html("%script{'src':'foo'} fallback"))
198 196 self.assertEqual('<script src="foo">\n bar\n</script>\n', to_html("%script{'src':'foo'}\n bar"))
199   - self.assertEqual('<link rel="stylesheet"/>\n', to_html("%link{'rel':'stylesheet'}"))
  197 + self.assertEqual('<link rel="stylesheet">\n', to_html("%link{'rel':'stylesheet'}"))
200 198 self.assertEqual('<link rel="stylesheet">foo</link>\n', to_html("%link{'rel':'stylesheet'} foo"))
201   - self.assertEqual('<meta content="text/html"/>\n', to_html("%meta{'content':'text/html'}"))
  199 + self.assertEqual('<meta content="text/html">\n', to_html("%meta{'content':'text/html'}"))
  200 + self.assertEqual('<input type="text"/>\n', to_html("%input{ 'type':'text' }", format='xhtml'))
202 201
203 202 def testillegalnesting(self):
204 203 self.assertRaises(Exception, partial(to_html, '!!!\n %p'))

0 comments on commit 52cc7e1

Please sign in to comment.
Something went wrong with that request. Please try again.