[svn r37608] Added some code to make sure 'inline' elements aren't indented (gotta love
'ignorable' whitespace). --HG-- branch : trunk
This commit is contained in:
parent
2f8325e277
commit
1ac5c69420
|
@ -10,6 +10,10 @@ class HtmlVisitor(SimpleUnicodeVisitor):
|
|||
single = dict([(x, 1) for x in
|
||||
('br,img,area,param,col,hr,meta,link,base,'
|
||||
'input,frame').split(',')])
|
||||
inline = dict([(x, 1) for x in
|
||||
('a abbr acronym b basefont bdo big br cite code dfn em font '
|
||||
'i img input kbd label q s samp select small span strike '
|
||||
'strong sub sup textarea tt u var'.split(' '))])
|
||||
|
||||
def repr_attribute(self, attrs, name):
|
||||
if name == 'class_':
|
||||
|
@ -21,6 +25,9 @@ class HtmlVisitor(SimpleUnicodeVisitor):
|
|||
def _issingleton(self, tagname):
|
||||
return tagname in self.single
|
||||
|
||||
def _isinline(self, tagname):
|
||||
return tagname in self.inline
|
||||
|
||||
class HtmlTag(Tag):
|
||||
def unicode(self, indent=2):
|
||||
l = []
|
||||
|
|
|
@ -46,3 +46,9 @@ def test_singleton():
|
|||
|
||||
h = html.head(html.script(src="foo"))
|
||||
assert unicode(h) == '<head><script src="foo"></script></head>'
|
||||
|
||||
def test_inline():
|
||||
h = html.div(html.span('foo'), html.span('bar'))
|
||||
assert (h.unicode(indent=2) ==
|
||||
'<div><span>foo</span><span>bar</span></div>')
|
||||
|
||||
|
|
|
@ -55,3 +55,4 @@ def test_raw():
|
|||
x = ns.some(py.xml.raw("<p>literal</p>"))
|
||||
u = unicode(x)
|
||||
assert u == "<some><p>literal</p></some>"
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class SimpleUnicodeVisitor(object):
|
|||
tag.parent = None
|
||||
self.visited[id(tag)] = 1
|
||||
tagname = getattr(tag, 'xmlname', tag.__class__.__name__)
|
||||
if self.curindent:
|
||||
if self.curindent and not self._isinline(tagname):
|
||||
self.write("\n" + u' ' * self.curindent)
|
||||
if tag:
|
||||
self.curindent += self.indent
|
||||
|
@ -100,3 +100,7 @@ class SimpleUnicodeVisitor(object):
|
|||
"""can (and will) be overridden in subclasses"""
|
||||
return self.shortempty
|
||||
|
||||
def _isinline(self, tagname):
|
||||
"""can (and will) be overridden in subclasses"""
|
||||
return False
|
||||
|
||||
|
|
Loading…
Reference in New Issue