Mercurial > genshi > mirror
changeset 365:4f431931d64e trunk
Fix for #62: preserve whitespace in front of directives.
author | cmlenz |
---|---|
date | Wed, 22 Nov 2006 20:48:35 +0000 |
parents | 7dabedbb53fb |
children | 37e45862f814 |
files | ChangeLog genshi/template/tests/directives.py genshi/template/tests/text.py genshi/template/text.py |
diffstat | 4 files changed, 46 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -30,8 +30,17 @@ are callable. * Instances of the `genshi.core.Attrs` class are now immutable (they are subclasses of `tuple` instead of `list`). - * Preserve whitespace in HTML `<pre>` elements also when they contained any - child elements. + + +Version 0.3.5 +http://svn.edgewall.org/repos/genshi/tags/0.3.4/ +(Nov 22 2006, from branches/stable/0.3.x) + + * Preserve whitespace in HTML `<pre>` elements also when they contain child + elements. + * Match templates no longer match their own output (ticket #77). + * Blank lines before directives in text templates are now preserved as + expected (ticket #62). Version 0.3.4
--- a/genshi/template/tests/directives.py +++ b/genshi/template/tests/directives.py @@ -380,7 +380,8 @@ #end ${echo('Hi', name='you')} """) - self.assertEqual(""" Hi, you! + self.assertEqual(""" + Hi, you! """, str(tmpl.generate()))
--- a/genshi/template/tests/text.py +++ b/genshi/template/tests/text.py @@ -37,26 +37,42 @@ #if foo bar #end 'if foo'""") - self.assertEqual('', str(tmpl.generate())) + self.assertEqual('\n', str(tmpl.generate())) def test_latin1_encoded(self): text = u'$foo\xf6$bar'.encode('iso-8859-1') tmpl = TextTemplate(text, encoding='iso-8859-1') self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y'))) - # FIXME - #def test_empty_lines(self): - # tmpl = TextTemplate("""Your items: - # - # #for item in items - # * ${item} - # - # #end""") - # self.assertEqual("""Your items: - # * 0 - # * 1 - # * 2 - # """, tmpl.generate(items=range(3)).render('text')) + def test_empty_lines1(self): + tmpl = TextTemplate("""Your items: + + #for item in items + * ${item} + #end""") + self.assertEqual("""Your items: + + * 0 + * 1 + * 2 +""", tmpl.generate(items=range(3)).render('text')) + + def test_empty_lines2(self): + tmpl = TextTemplate("""Your items: + + #for item in items + * ${item} + + #end""") + self.assertEqual("""Your items: + + * 0 + + * 1 + + * 2 + +""", tmpl.generate(items=range(3)).render('text')) def suite():
--- a/genshi/template/text.py +++ b/genshi/template/text.py @@ -50,7 +50,9 @@ ('choose', ChooseDirective), ('with', WithDirective)] - _DIRECTIVE_RE = re.compile(r'^\s*(?<!\\)#((?:\w+|#).*)\n?', re.MULTILINE) + _DIRECTIVE_RE = re.compile(r'(?:^[ \t]*(?<!\\)#(end).*\n?)|' + r'(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)', + re.MULTILINE) def _parse(self, encoding): """Parse the template from text input."""