Mercurial > genshi > mirror
comparison markup/template.py @ 74:d54b5fd60b52 trunk
Fix expression interpolation where both shorthand notation and full notation are used inside a single text node. Thanks Jonas.
author | cmlenz |
---|---|
date | Wed, 12 Jul 2006 19:45:13 +0000 |
parents | 1da51d718391 |
children | 3722696d0343 |
comparison
equal
deleted
inserted
replaced
73:1da51d718391 | 74:d54b5fd60b52 |
---|---|
763 @param text: the text to parse | 763 @param text: the text to parse |
764 @param lineno: the line number at which the text was found (optional) | 764 @param lineno: the line number at which the text was found (optional) |
765 @param offset: the column number at which the text starts in the source | 765 @param offset: the column number at which the text starts in the source |
766 (optional) | 766 (optional) |
767 """ | 767 """ |
768 patterns = [Template._FULL_EXPR_RE, Template._SHORT_EXPR_RE] | 768 def _interpolate(text, patterns): |
769 def _interpolate(text): | |
770 for idx, group in enumerate(patterns.pop(0).split(text)): | 769 for idx, group in enumerate(patterns.pop(0).split(text)): |
771 if idx % 2: | 770 if idx % 2: |
772 yield EXPR, Expression(group), (lineno, offset) | 771 yield EXPR, Expression(group), (lineno, offset) |
773 elif group: | 772 elif group: |
774 if patterns: | 773 if patterns: |
775 for result in _interpolate(group): | 774 for result in _interpolate(group, patterns[:]): |
776 yield result | 775 yield result |
777 else: | 776 else: |
778 yield TEXT, group.replace('$$', '$'), (filename, lineno, | 777 yield TEXT, group.replace('$$', '$'), (filename, lineno, |
779 offset) | 778 offset) |
780 return _interpolate(text) | 779 return _interpolate(text, [cls._FULL_EXPR_RE, cls._SHORT_EXPR_RE]) |
781 _interpolate = classmethod(_interpolate) | 780 _interpolate = classmethod(_interpolate) |
782 | 781 |
783 def generate(self, ctxt=None): | 782 def generate(self, ctxt=None): |
784 """Apply the template to the given context data. | 783 """Apply the template to the given context data. |
785 | 784 |