Skip to content

Commit

Permalink
Fix multiline tal:replace statements
Browse files Browse the repository at this point in the history
  • Loading branch information
iksteen committed Jun 10, 2014
1 parent 48ee37f commit c50fc1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lingua/extractors/xml.py
Expand Up @@ -22,7 +22,7 @@ def _open(filename):


ENGINE_PREFIX = re.compile(r'^\s*([a-z\-_]+):\s*')
STRUCTURE_PREFIX = re.compile(r'\s*(structure|text)\s+(.*)')
STRUCTURE_PREFIX = re.compile(r'\s*(structure|text)\s+(.*)', re.DOTALL)
WHITESPACE = re.compile(u"\s+")
EXPRESSION = re.compile(u"\s*\${(.*?)}\s*")
UNDERSCORE_CALL = re.compile("_\(.*\)")
Expand Down Expand Up @@ -169,6 +169,7 @@ def get_code_for_attribute(self, attribute, value):
m = STRUCTURE_PREFIX.match(value)
if m is not None:
value = m.group(2)
value = '(%s)' % value
self._assert_valid_python(value)
yield value
if attribute[1] == 'define':
Expand Down
28 changes: 28 additions & 0 deletions tests/extractors/test_xml.py
Expand Up @@ -461,3 +461,31 @@ def test_ignore_structure_in_replace():
'''
messages = list(extract_xml('filename', _options()))
assert messages[0].msgid == u'foo'


@pytest.mark.usefixtures('fake_source')
def test_multiline_replace():
global source
source = b'''\
<html xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="lingua">
<dummy tal:replace="True or
_('foo')">Dummy</dummy>
</html>
'''
messages = list(extract_xml('filename', _options()))
assert messages[0].msgid == u'foo'


@pytest.mark.usefixtures('fake_source')
def test_multiline_replace_with_structure():
global source
source = b'''\
<html xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="lingua">
<dummy tal:replace="structure True or
_('foo')">Dummy</dummy>
</html>
'''
messages = list(extract_xml('filename', _options()))
assert messages[0].msgid == u'foo'

0 comments on commit c50fc1d

Please sign in to comment.