# global lexing rules
self.rules = {
'root': [
- # raw directive
- (c('((?:\s*%s\-|%s)\s*raw\s*(?:\-%s\s*|%s%s))' % (
- e(environment.block_start_string),
- e(environment.block_start_string),
- e(environment.block_end_string),
- e(environment.block_end_string),
- block_suffix_re
- )), (None,), 'raw'),
- # normal directives
- (c('(.*?)(?:%s)' % '|'.join([
- '(?P<%s_begin>\s*%s\-|%s)' % (n, e(r), e(r))
- for n, r in root_tag_rules
- ])), ('data', '#bygroup'), '#bygroup'),
+ # directives
+ (c('(.*?)(?:%s)' % '|'.join(
+ ['(?P<raw_begin>(?:\s*%s\-|%s)\s*raw\s*%s)' % (
+ e(environment.block_start_string),
+ e(environment.block_start_string),
+ e(environment.block_end_string)
+ )] + [
+ '(?P<%s_begin>\s*%s\-|%s)' % (n, e(r), e(r))
+ for n, r in root_tag_rules
+ ])), ('data', '#bygroup'), '#bygroup'),
# data
(c('.+'), 'data', None)
],
)), 'block_end', '#pop'),
] + tag_rules,
# raw block
- 'raw': [
+ 'raw_begin': [
(c('(.*?)((?:\s*%s\-|%s)\s*endraw\s*(?:\-%s\s*|%s%s))' % (
e(environment.block_start_string),
e(environment.block_start_string),
e(environment.block_end_string),
e(environment.block_end_string),
block_suffix_re
- )), ('data', None), '#pop'),
+ )), ('data', 'raw_end'), '#pop'),
(c('(.)'), (Failure('Missing end of raw directive'),), None)
]
}
:license: BSD, see LICENSE for more details.
"""
+RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{% endraw %}'
BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''
COMMENTS = '''\
<ul>
BYTEFALLBACK = u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}'''
+def test_raw(env):
+ tmpl = env.from_string(RAW)
+ assert tmpl.render() == 'foo|{{ bar }}|{% baz %}'
+
+
def test_balancing():
from jinja import Environment
env = Environment('{%', '%}', '${', '}')