Apply lstrip_blocks to comments (match trim_blocks behavior)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kristi Tsukida · committed by Kristi Tsukida · parent 01d8986 · Browse files · 1 file·+22 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+22 added−11 removed
- other:+22 added−11 removed
Provenance
- Commit
54f7d2e- Tree
c27faaa- Author
Kristi Tsukida <kristi.dev@gmail.com>- Committer
Kristi Tsukida <kristi.dev@gmail.com>- Parent
01d8986
1 file changed+22 added−11 removed
modified:jinja2/lexer.py+22 added-11 removed
424 unmodified lines425 426 # block suffix if trimming is enabled427 block_suffix_re = environment.trim_blocks and '\\n?' or ''428 429- # use '{%+' to manually disable lstrip_blocks behavior430- no_lstrip_re = e('+')431- # detect overlap between block and variable or comment strings432- block_diff_re = c(r'^%s(.*)' % e(environment.block_start_string))433- # make sure we don't mistake a block for a variable or a comment434- m = block_diff_re.match(environment.comment_start_string)435- no_lstrip_re += m and r'|%s' % e(m.group(1)) or ''436- m = block_diff_re.match(environment.variable_start_string)437- no_lstrip_re += m and r'|%s' % e(m.group(1)) or ''438- no_variable_re = m and r'(?!%s)' % e(m.group(1)) or ''439-429 # strip leading spaces if lstrip_blocks is enabled430 prefix_re = {}431 if environment.lstrip_blocks:432+ # use '{%+' to manually disable lstrip_blocks behavior433+ no_lstrip_re = e('+')434+ # detect overlap between block and variable or comment strings435+ block_diff = c(r'^%s(.*)' % e(environment.block_start_string))436+ # make sure we don't mistake a block for a variable or a comment437+ m = block_diff.match(environment.comment_start_string)438+ no_lstrip_re += m and r'|%s' % e(m.group(1)) or ''439+ m = block_diff.match(environment.variable_start_string)440+ no_lstrip_re += m and r'|%s' % e(m.group(1)) or ''441+442+ # detect overlap between comment and variable strings443+ comment_diff = c(r'^%s(.*)' % e(environment.comment_start_string))444+ m = comment_diff.match(environment.variable_start_string)445+ no_variable_re = m and r'(?!%s)' % e(m.group(1)) or ''446+447 lstrip_re = r'^[ \t]*'448 block_prefix_re = r'%s%s(?!%s)|%s\+?' % (449 lstrip_re,450 e(environment.block_start_string),451 no_lstrip_re,452 e(environment.block_start_string),453 )454+ comment_prefix_re = r'%s%s%s|%s\+?' % (455+ lstrip_re,456+ e(environment.comment_start_string),457+ no_variable_re,458+ e(environment.comment_start_string),459+ )460 prefix_re['block'] = block_prefix_re461+ prefix_re['comment'] = comment_prefix_re462 else:463 block_prefix_re = '%s' % e(environment.block_start_string)464 465 self.newline_sequence = environment.newline_sequence253 unmodified lines